Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #45 from microservices-demo/refactor/weave-common
Browse files Browse the repository at this point in the history
Reuse middleware from weaveworks/common.
  • Loading branch information
Phil Winder authored Mar 21, 2017
2 parents e147999 + c06f85b commit 1714eca
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: go
go: 1.6
go: 1.7
sudo: required
env:
- GROUP=weaveworksdemos COMMIT=$TRAVIS_COMMIT TAG=$TRAVIS_TAG
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.6-alpine
FROM golang:1.7-alpine
ENV sourcesdir /go/src/github.com/microservices-demo/user/
ENV MONGO_HOST mytestdb:27017
ENV HATEAOS user
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-test
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH

RUN apt-get update && apt-get install -yq git curl

RUN curl -sSL https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz -o go.tar.gz && \
RUN curl -sSL https://storage.googleapis.com/golang/go1.7.linux-amd64.tar.gz -o go.tar.gz && \
tar -C /usr/local -xvf go.tar.gz
RUN go get -v github.com/Masterminds/glide

Expand Down
38 changes: 28 additions & 10 deletions glide.lock

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

3 changes: 3 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ import:
subpackages:
- hystrix
- package: github.com/felixge/httpsnoop
- package: github.com/weaveworks/common
subpackages:
- middleware
23 changes: 14 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,32 @@ import (
"github.com/microservices-demo/user/api"
"github.com/microservices-demo/user/db"
"github.com/microservices-demo/user/db/mongodb"
"github.com/microservices-demo/user/middleware"
stdopentracing "github.com/opentracing/opentracing-go"
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 (
dev bool
port string
acc string
zip string
)

var (
HTTPLatency = stdprometheus.NewHistogramVec(stdprometheus.HistogramOpts{
Name: "request_duration_seconds",
Help: "Time (in seconds) spent serving HTTP requests.",
Buckets: stdprometheus.DefBuckets,
}, []string{"method", "route", "status_code", "isWS"})
)

const (
ServiceName = "user"
)

func init() {

stdprometheus.MustRegister(HTTPLatency)
flag.StringVar(&zip, "zipkin", os.Getenv("ZIPKIN"), "Zipkin address")
flag.StringVar(&port, "port", "8084", "Port on which to run")
db.Register("mongodb", &mongodb.Mongo{})
Expand Down Expand Up @@ -124,16 +130,15 @@ func main() {
// HTTP router
router := api.MakeHTTPHandler(ctx, endpoints, logger, tracer)

httpMiddleware := []middleware.Interface{
middleware.Instrument{
Duration: middleware.HTTPLatency,
httpMiddleware := []commonMiddleware.Interface{
commonMiddleware.Instrument{
Duration: HTTPLatency,
RouteMatcher: router,
Service: ServiceName,
},
}

// Handler
handler := middleware.Merge(httpMiddleware...).Wrap(router)
handler := commonMiddleware.Merge(httpMiddleware...).Wrap(router)

// Create and launch the HTTP server.
go func() {
Expand Down
94 changes: 0 additions & 94 deletions middleware/instrument.go

This file was deleted.

33 changes: 0 additions & 33 deletions middleware/middleware.go

This file was deleted.

0 comments on commit 1714eca

Please sign in to comment.