Go-Kit Api Gateway

You will need to have a working Go environment setup to follow along. You can get that going by starting here.

Getting the source code

$ go get github.com/go-kit/kit

Starting Addsvc

$ cd $HOME/go/src/github.com/go-kit/kit/examples/addsvc
$ go get
$ go run addsvc.go -debug.addr :7080 -http-addr :7081 -grpc-addr :7082 -thrift-addr :7083 -jsonrpc-addr :7084

The only port that we will actually use is: -grpc-addr :7082, this is the port we will register with Consul.

$ curl -XPOST -d'{"a":"7","b":"4"}' http://localhost:7081/concat
{"v":"74"}
$ curl -XPOST -d'{"a":7,"b":4}' http://localhost:7081/sum
{"v":11}

Starting Stringsvc

$ cd $HOME/go/src/github.com/go-kit/kit/examples/stringsvc3
$ go get
$ go run *.go -listen :8081
$ curl -XPOST -d'{"s":"mytest"}' http://localhost:8081/count
{"v":6}
$ curl -XPOST -d'{"s":"mytest"}' http://localhost:8081/uppercase
{"v":"MYTEST"}

Starting Consul

$ mkdir ./consul.d$ echo '{"service": {"name": "addsvc", "tags": [], "port": 7082}}' > ./consul.d/addsvc.json$ echo '{"service": {"name": "stringsvc", "tags": [], "port": 8081}}' > ./consul.d/stringsvc.json
$ ./consul agent -dev -config-dir=./consul.d

Starting Api Gateway

$ cd $HOME/go/src/github.com/go-kit/kit/examples/apigateway
$ go run main.go -consul.addr :8500
$ curl -XPOST -d'{"a":"7","b":"4"}' http://localhost:8000/addsvc/concat
{"v":"74"}
$ curl -XPOST -d'{"a":7,"b":4}' http://localhost:8000/addsvc/sum
{"v":11}
$ curl -XPOST -d'{"s":"mytest"}' http://localhost:8000/stringsvc/count
{"v":6}
$ curl -XPOST -d'{"s":"mytest"}' http://localhost:8000/stringsvc/uppercase
{"v":"MYTEST"}

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store