Commit b5ec77ee authored by Vishal Lal's avatar Vishal Lal Committed by GitHub
Browse files

Merge pull request #48 from microservices-demo/update-go-1.7

Changed necessary to work with go 1.7
parents 5e88df65 1b64efd2
......@@ -5,12 +5,13 @@ package api
// transport.
import (
"context"
"github.com/go-kit/kit/endpoint"
"github.com/go-kit/kit/tracing/opentracing"
"github.com/microservices-demo/user/db"
"github.com/microservices-demo/user/users"
stdopentracing "github.com/opentracing/opentracing-go"
"golang.org/x/net/context"
)
// Endpoints collects the endpoints that comprise the Service.
......
......@@ -4,6 +4,7 @@ package api
// In our case we just use a REST-y HTTP transport.
import (
"context"
"encoding/json"
"errors"
"net/http"
......@@ -16,7 +17,6 @@ import (
"github.com/microservices-demo/user/users"
stdopentracing "github.com/opentracing/opentracing-go"
"github.com/prometheus/client_golang/prometheus/promhttp"
"golang.org/x/net/context"
)
var (
......@@ -24,7 +24,7 @@ var (
)
// MakeHTTPHandler mounts the endpoints into a REST-y HTTP handler.
func MakeHTTPHandler(ctx context.Context, e Endpoints, logger log.Logger, tracer stdopentracing.Tracer) *mux.Router {
func MakeHTTPHandler(e Endpoints, logger log.Logger, tracer stdopentracing.Tracer) *mux.Router {
r := mux.NewRouter().StrictSlash(false)
options := []httptransport.ServerOption{
httptransport.ServerErrorLogger(logger),
......@@ -36,70 +36,60 @@ func MakeHTTPHandler(ctx context.Context, e Endpoints, logger log.Logger, tracer
// GET /health Health Check
r.Methods("GET").Path("/login").Handler(httptransport.NewServer(
ctx,
e.LoginEndpoint,
decodeLoginRequest,
encodeResponse,
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GET /login", logger)))...,
))
r.Methods("POST").Path("/register").Handler(httptransport.NewServer(
ctx,
e.RegisterEndpoint,
decodeRegisterRequest,
encodeResponse,
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "POST /register", logger)))...,
))
r.Methods("GET").PathPrefix("/customers").Handler(httptransport.NewServer(
ctx,
e.UserGetEndpoint,
decodeGetRequest,
encodeResponse,
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GET /customers", logger)))...,
))
r.Methods("GET").PathPrefix("/cards").Handler(httptransport.NewServer(
ctx,
e.CardGetEndpoint,
decodeGetRequest,
encodeResponse,
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GET /cards", logger)))...,
))
r.Methods("GET").PathPrefix("/addresses").Handler(httptransport.NewServer(
ctx,
e.AddressGetEndpoint,
decodeGetRequest,
encodeResponse,
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GET /addresses", logger)))...,
))
r.Methods("POST").Path("/customers").Handler(httptransport.NewServer(
ctx,
e.UserPostEndpoint,
decodeUserRequest,
encodeResponse,
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "POST /customers", logger)))...,
))
r.Methods("POST").Path("/addresses").Handler(httptransport.NewServer(
ctx,
e.AddressPostEndpoint,
decodeAddressRequest,
encodeResponse,
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "POST /addresses", logger)))...,
))
r.Methods("POST").Path("/cards").Handler(httptransport.NewServer(
ctx,
e.CardPostEndpoint,
decodeCardRequest,
encodeResponse,
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "POST /cards", logger)))...,
))
r.Methods("DELETE").PathPrefix("/").Handler(httptransport.NewServer(
ctx,
e.DeleteEndpoint,
decodeDeleteRequest,
encodeResponse,
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "DELETE /", logger)))...,
))
r.Methods("GET").PathPrefix("/health").Handler(httptransport.NewServer(
ctx,
e.HealthEndpoint,
decodeHealthRequest,
encodeHealthResponse,
......
......@@ -16,7 +16,7 @@ services:
- MONGO_HOST=user-db:27017
- reschedule=on-node-failure
ports:
- "8080:8084"
- "8080:80"
user-db:
build:
context: ./docker/user-db/
......
hash: 77eab7ed7829910ee3d4f0266da67abc35fc1c8635bf11e577842222cf0e4791
updated: 2017-03-21T15:35:06.768490243Z
hash: ab1322ca6d24e40907af3a701959880ad721afa2e1b67eaf0c945bb74c9a5c30
updated: 2017-04-28T12:53:43.461401871+02:00
imports:
- name: github.com/afex/hystrix-go
version: 39520ddd07a9d9a071d615f7476798659f5a3b89
......@@ -28,7 +28,7 @@ imports:
- name: github.com/felixge/httpsnoop
version: 287b56e9e314227d3113c7c6b434d31aec68089d
- name: github.com/go-kit/kit
version: 988c05d06d8ee3a9c13782f0e49b2c6e4726388d
version: fadad6fffe0466b19df9efd9acde5c9a52df5fa4
subpackages:
- circuitbreaker
- endpoint
......
package: github.com/microservices-demo/user
import:
- package: github.com/go-kit/kit
version: v0.4.0
subpackages:
- endpoint
- log
......@@ -16,9 +17,6 @@ import:
subpackages:
- prometheus
- prometheus/promhttp
- package: golang.org/x/net
subpackages:
- context
- package: gopkg.in/mgo.v2
subpackages:
- bson
......
......@@ -19,7 +19,6 @@ import (
zipkin "github.com/openzipkin/zipkin-go-opentracing"
stdprometheus "github.com/prometheus/client_golang/prometheus"
commonMiddleware "github.com/weaveworks/common/middleware"
"golang.org/x/net/context"
)
var (
......@@ -51,14 +50,13 @@ func main() {
flag.Parse()
// Mechanical stuff.
errc := make(chan error)
ctx := context.Background()
// Log domain.
var logger log.Logger
{
logger = log.NewLogfmtLogger(os.Stderr)
logger = log.NewContext(logger).With("ts", log.DefaultTimestampUTC)
logger = log.NewContext(logger).With("caller", log.DefaultCaller)
logger = log.With(logger, "ts", log.DefaultTimestampUTC)
logger = log.With(logger, "caller", log.DefaultCaller)
}
var tracer stdopentracing.Tracer
......@@ -66,7 +64,7 @@ func main() {
if zip == "" {
tracer = stdopentracing.NoopTracer{}
} else {
logger := log.NewContext(logger).With("tracer", "Zipkin")
logger := log.With(logger, "tracer", "Zipkin")
logger.Log("addr", zip)
collector, err := zipkin.NewHTTPCollector(
zip,
......@@ -128,7 +126,7 @@ func main() {
endpoints := api.MakeEndpoints(service, tracer)
// HTTP router
router := api.MakeHTTPHandler(ctx, endpoints, logger, tracer)
router := api.MakeHTTPHandler(endpoints, logger, tracer)
httpMiddleware := []commonMiddleware.Interface{
commonMiddleware.Instrument{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment