Skip to content
This repository has been archived by the owner on Jun 3, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/0.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
rumyantseva committed Jul 21, 2017
2 parents 36e8ace + 1cf607b commit 5d3c859
Show file tree
Hide file tree
Showing 82 changed files with 1,265 additions and 0 deletions.
1 change: 1 addition & 0 deletions .version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1
1 change: 1 addition & 0 deletions practice/01-prepare-codebase/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
app
6 changes: 6 additions & 0 deletions practice/01-prepare-codebase/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- repo: git://github.com/dnephin/pre-commit-golang
sha: 471a7c123ea7a3b776ff018edf00066947873a94
hooks:
- id: go-fmt
- id: go-vet
- id: go-lint
2 changes: 2 additions & 0 deletions practice/02-simpliest-service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
app

6 changes: 6 additions & 0 deletions practice/02-simpliest-service/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- repo: git://github.com/dnephin/pre-commit-golang
sha: 471a7c123ea7a3b776ff018edf00066947873a94
hooks:
- id: go-fmt
- id: go-vet
- id: go-lint
11 changes: 11 additions & 0 deletions practice/02-simpliest-service/handlers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
"fmt"
"net/http"
)

// home returns the path of current request
func home(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Processing URL %s...\n", r.URL.Path)
}
12 changes: 12 additions & 0 deletions practice/02-simpliest-service/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

import (
"net/http"
)

// Run server: go build -o app && ./app
// Try requests: curl http://127.0.0.1:8000/any
func main() {
http.HandleFunc("/", home)
http.ListenAndServe(":8000", nil)
}
2 changes: 2 additions & 0 deletions practice/03-router/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
app

6 changes: 6 additions & 0 deletions practice/03-router/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- repo: git://github.com/dnephin/pre-commit-golang
sha: 471a7c123ea7a3b776ff018edf00066947873a94
hooks:
- id: go-fmt
- id: go-vet
- id: go-lint
13 changes: 13 additions & 0 deletions practice/03-router/handlers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"fmt"
"net/http"

"github.com/julienschmidt/httprouter"
)

// home returns the path of current request
func home(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
fmt.Fprintf(w, "Processing URL %s...\n", r.URL.Path)
}
16 changes: 16 additions & 0 deletions practice/03-router/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import (
"net/http"

"github.com/julienschmidt/httprouter"
)

// Run server: go build -o app && ./app
// Try requests: curl http://127.0.0.1:8000/
func main() {
router := httprouter.New()
router.GET("/", home)

http.ListenAndServe(":8000", router)
}
2 changes: 2 additions & 0 deletions practice/04-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
app

6 changes: 6 additions & 0 deletions practice/04-tests/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- repo: git://github.com/dnephin/pre-commit-golang
sha: 471a7c123ea7a3b776ff018edf00066947873a94
hooks:
- id: go-fmt
- id: go-vet
- id: go-lint
13 changes: 13 additions & 0 deletions practice/04-tests/handlers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"fmt"
"net/http"

"github.com/julienschmidt/httprouter"
)

// home returns the path of current request
func home(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
fmt.Fprintf(w, "Processing URL %s...\n", r.URL.Path)
}
42 changes: 42 additions & 0 deletions practice/04-tests/handlers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"io/ioutil"
"net/http"
"net/http/httptest"
"strings"
"testing"

"github.com/julienschmidt/httprouter"
)

// TestHandler is the simplest test: check home (/) URL
// go test
func TestHandler(t *testing.T) {
router := httprouter.New()
router.GET("/", home)

ts := httptest.NewServer(router)
defer ts.Close()

res, err := http.Get(ts.URL + "/")
if err != nil {
t.Fatal(err)
}

greeting, err := ioutil.ReadAll(res.Body)
res.Body.Close()

if err != nil {
t.Fatal(err)
}

expectedGreeting := "Processing URL /..."
testingGreeting := strings.Trim(string(greeting), " \n")
if testingGreeting != expectedGreeting {
t.Fatalf(
"Wrong greeting '%s', expected '%s'",
testingGreeting, expectedGreeting,
)
}
}
16 changes: 16 additions & 0 deletions practice/04-tests/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import (
"net/http"

"github.com/julienschmidt/httprouter"
)

// Run server: go build -o app && ./app
// Try requests: curl http://127.0.0.1:8000/
func main() {
router := httprouter.New()
router.GET("/", home)

http.ListenAndServe(":8000", router)
}
2 changes: 2 additions & 0 deletions practice/05-logger/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
app

6 changes: 6 additions & 0 deletions practice/05-logger/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- repo: git://github.com/dnephin/pre-commit-golang
sha: 471a7c123ea7a3b776ff018edf00066947873a94
hooks:
- id: go-fmt
- id: go-vet
- id: go-lint
14 changes: 14 additions & 0 deletions practice/05-logger/handlers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"fmt"
"net/http"

"github.com/julienschmidt/httprouter"
)

// home returns the path of current request
func home(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
log.Info("Request received.")
fmt.Fprintf(w, "Processing URL %s...\n", r.URL.Path)
}
42 changes: 42 additions & 0 deletions practice/05-logger/handlers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"io/ioutil"
"net/http"
"net/http/httptest"
"strings"
"testing"

"github.com/julienschmidt/httprouter"
)

// TestHandler is the simplest test: check home (/) URL
// go test
func TestHandler(t *testing.T) {
router := httprouter.New()
router.GET("/", home)

ts := httptest.NewServer(router)
defer ts.Close()

res, err := http.Get(ts.URL + "/")
if err != nil {
t.Fatal(err)
}

greeting, err := ioutil.ReadAll(res.Body)
res.Body.Close()

if err != nil {
t.Fatal(err)
}

expectedGreeting := "Processing URL /..."
testingGreeting := strings.Trim(string(greeting), " \n")
if testingGreeting != expectedGreeting {
t.Fatalf(
"Wrong greeting '%s', expected '%s'",
testingGreeting, expectedGreeting,
)
}
}
22 changes: 22 additions & 0 deletions practice/05-logger/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"net/http"

"github.com/Sirupsen/logrus"
"github.com/julienschmidt/httprouter"
)

var log = logrus.New()

// Run server: go build -o app && ./app
// Try requests: curl http://127.0.0.1:8000/
func main() {
log.Info("Initialize service...")

router := httprouter.New()
router.GET("/", home)

log.Info("Service is ready to listen and serve.")
http.ListenAndServe(":8000", router)
}
2 changes: 2 additions & 0 deletions practice/06-dependencies/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
app

6 changes: 6 additions & 0 deletions practice/06-dependencies/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- repo: git://github.com/dnephin/pre-commit-golang
sha: 471a7c123ea7a3b776ff018edf00066947873a94
hooks:
- id: go-fmt
- id: go-vet
- id: go-lint
14 changes: 14 additions & 0 deletions practice/06-dependencies/handlers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"fmt"
"net/http"

"github.com/julienschmidt/httprouter"
)

// home returns the path of current request
func home(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
log.Info("Request received.")
fmt.Fprintf(w, "Processing URL %s...\n", r.URL.Path)
}
42 changes: 42 additions & 0 deletions practice/06-dependencies/handlers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"io/ioutil"
"net/http"
"net/http/httptest"
"strings"
"testing"

"github.com/julienschmidt/httprouter"
)

// TestHandler is the simplest test: check home (/) URL
// go test
func TestHandler(t *testing.T) {
router := httprouter.New()
router.GET("/", home)

ts := httptest.NewServer(router)
defer ts.Close()

res, err := http.Get(ts.URL + "/")
if err != nil {
t.Fatal(err)
}

greeting, err := ioutil.ReadAll(res.Body)
res.Body.Close()

if err != nil {
t.Fatal(err)
}

expectedGreeting := "Processing URL /..."
testingGreeting := strings.Trim(string(greeting), " \n")
if testingGreeting != expectedGreeting {
t.Fatalf(
"Wrong greeting '%s', expected '%s'",
testingGreeting, expectedGreeting,
)
}
}
24 changes: 24 additions & 0 deletions practice/06-dependencies/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"net/http"

"github.com/Sirupsen/logrus"
"github.com/julienschmidt/httprouter"
)

var log = logrus.New()

// Prepare vendoring config: glide init; glide install

// Run server: go build -o app && ./app
// Try requests: curl http://127.0.0.1:8000/
func main() {
log.Info("Initialize service...")

router := httprouter.New()
router.GET("/", home)

log.Info("Service is ready to listen and serve.")
http.ListenAndServe(":8000", router)
}
2 changes: 2 additions & 0 deletions practice/07-config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
app
vendor
6 changes: 6 additions & 0 deletions practice/07-config/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- repo: git://github.com/dnephin/pre-commit-golang
sha: 471a7c123ea7a3b776ff018edf00066947873a94
hooks:
- id: go-fmt
- id: go-vet
- id: go-lint
12 changes: 12 additions & 0 deletions practice/07-config/glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions practice/07-config/glide.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package: github.com/rumyantseva/production-ready-microservices/practice/07-config
import:
- package: github.com/Sirupsen/logrus
version: ^1.0.2
- package: github.com/julienschmidt/httprouter
version: ^1.1.0
14 changes: 14 additions & 0 deletions practice/07-config/handlers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"fmt"
"net/http"

"github.com/julienschmidt/httprouter"
)

// home returns the path of current request
func home(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
log.Info("Request received.")
fmt.Fprintf(w, "Processing URL %s...\n", r.URL.Path)
}
Loading

0 comments on commit 5d3c859

Please sign in to comment.