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 #36 from microservices-demo/refactor/middleware
Browse files Browse the repository at this point in the history
Refactor to use middleware from weaveworks/common.
  • Loading branch information
Phil Winder committed Mar 22, 2017
2 parents 4d04796 + 8bb588a commit c32e534
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sudo: required
services:
- docker
go:
- 1.6
- 1.7
before_install:
- go get -u github.com/FiloSottile/gvt
- gvt restore
Expand Down
18 changes: 15 additions & 3 deletions cmd/cataloguesvc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,27 @@ import (
_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
"github.com/microservices-demo/catalogue"
"github.com/microservices-demo/catalogue/middleware"
"github.com/prometheus/client_golang/prometheus"
"github.com/weaveworks/common/middleware"
"golang.org/x/net/context"
)

const (
ServiceName = "catalogue"
)

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

func init() {
prometheus.MustRegister(HTTPLatency)
}

func main() {
var (
port = flag.String("port", "8081", "Port to bind HTTP listener") // TODO(pb): should be -addr, default ":8081"
Expand Down Expand Up @@ -110,9 +123,8 @@ func main() {

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

Expand Down
2 changes: 1 addition & 1 deletion docker/catalogue/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.6
FROM golang:1.7

RUN mkdir /app
COPY . /go/src/github.com/microservices-demo/catalogue/
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.

1 change: 0 additions & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ echo $CODE_DIR

cp -r $CODE_DIR/images/ $CODE_DIR/docker/catalogue/images/
cp -r $CODE_DIR/cmd/ $CODE_DIR/docker/catalogue/cmd/
cp -r $CODE_DIR/middleware/ $CODE_DIR/docker/catalogue/middleware/
cp $CODE_DIR/*.go $CODE_DIR/docker/catalogue/
mkdir -p $CODE_DIR/docker/catalogue/vendor && cp $CODE_DIR/vendor/manifest $CODE_DIR/docker/catalogue/vendor/

Expand Down
2 changes: 1 addition & 1 deletion test/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_go(self):
code_dir = script_dir + "/.."
home = expanduser("~")
goPath = os.environ['GOPATH']
command = ['docker', 'run', '--rm', '-v', goPath + ':/go/src/', '-v', code_dir + ':/go/src/github.com/microservices-demo/catalogue', '-w', '/go/src/github.com/microservices-demo/catalogue', '-e', 'GOPATH=/go/', 'golang:1.6', 'go', 'test', '-v', '-covermode=count', '-coverprofile=coverage.out']
command = ['docker', 'run', '--rm', '-v', goPath + ':/go/src/', '-v', code_dir + ':/go/src/github.com/microservices-demo/catalogue', '-w', '/go/src/github.com/microservices-demo/catalogue', '-e', 'GOPATH=/go/', 'golang:1.7', 'go', 'test', '-v', '-covermode=count', '-coverprofile=coverage.out']

print(Docker().execute(command))

Expand Down

0 comments on commit c32e534

Please sign in to comment.