Go-kit Examples
stringsvc
go run 01.stringsvc1/main.go
curl -XPOST -d'{"s":"hello, world"}' localhost:8080/uppercase
curl -XPOST -d'{"s":"hello, world"}' localhost:8080/count
go run 02.stringsvc2/*.go
curl -XPOST -d'{"s":"hello, world"}' localhost:8080/uppercase
curl -XPOST -d'{"s":"hello, world"}' localhost:8080/count
go get github.com/streadway/handy/breaker
go get github.com/afex/hystrix-go/hystrix
go get golang.org/x/time/rate
go run 03.stringsvc3/*.go -listen=:8001 &
go run 03.stringsvc3/*.go -listen=:8002 &
go run 03.stringsvc3/*.go -listen=:8003 &
go run 03.stringsvc3/*.go -listen=:8080 -proxy=localhost:8001,localhost:8002,localhost:8003
for s in foo bar baz ; do curl -d"{\"s\":\"$s\"}" localhost:8080/uppercase ; done
for s in foo bar baz ; do curl -d"{\"s\":\"$s\"}" localhost:8080/count ; done
curl localhost:8080/metrics
apt-get -y install flex bison
wget https://github.com/apache/thrift/archive/v0.13.0.tar.gz
tar -zxvf v0.13.0.tar.gz
cd thrift-0.13.0/
./bootstrap.sh
./configure --without-qt4 --without-qt5 --without-c_glib --without-csharp --without-java --without-erlang --without-nodejs --without-lua --without-python --without-perl --without-php --without-php_extension --without-dart --without-ruby --without-haskell --without-rs --without-cl --without-haxe --without-dotnetcore --without-d
make; make install
make pb thrift
make
./server.bin
./client.bin -http-addr=localhost:8081 -method=sum 1 2
./client.bin -http-addr=localhost:8081 -method=concat 1 2
./client.bin -grpc-addr=localhost:8082 -method=sum 1 2
./client.bin -grpc-addr=localhost:8082 -method=concat 1 2
./client.bin -thrift-addr=localhost:8083 -method=sum 1 2
./client.bin -thrift-addr=localhost:8083 -method=concat 1 2
./client.bin -jsonrpc-addr=localhost:8084 -method=sum 1 2
./client.bin -jsonrpc-addr=localhost:8084 -method=concat 1 2
go run ./cmd/profilesvc/main.go
curl -d '{"id":"1234","Name":"Go Kit"}' -H "Content-Type: application/json" -X POST http://localhost:8080/profiles/
curl localhost:8080/profiles/1234
curl -d '{"id": "1", "location": "location1"}' -H "Content-Type: application/json" -X POST http://localhost:8080/profiles/1234/addresses/
curl -X GET localhost:8080/profiles/1234/addresses/
curl -X DELETE localhost:8080/profiles/1234/addresses/1
-
reference : GoDDD
-
test booking
- Check out the sample cargos
curl -X GET http://localhost:8080/booking/v1/cargos
curl -X POST -d '{"origin": "SESTO", "destination": "FIHEL", "arrival_deadline": "2016-03-21T19:50:24Z"}' -H "Content-Type: application/json" http://localhost:8080/booking/v1/cargos
curl -X POST -d '{"origin": "SESTO", "destination": "CNHKG", "arrival_deadline": "2021-01-19T09:28:00Z"}' -H "Content-Type: application/json" http://localhost:8080/booking/v1/cargos
curl -X GET http://localhost:8080/booking/v1/cargos/ABC123
- Request possible routes for sample cargo ABC123
curl -X GET http://localhost:8080/booking/v1/cargos/ABC123/request_routes
curl -d '{}' -X POST http://localhost:8080/booking/v1/cargos/ABC123/change_destination
curl -X GET http://localhost:8080/booking/v1/locations
curl -d '{"completion_time":"2016-03-21T19:50:24Z", "tracking_id":"ABC123", "voyage":"V100", "location":"SESTO", "event_type":"Receive"}' -X POST http://localhost:8080/handling/v1/incidents
curl -X GET http://localhost:8080/tracking/v1/cargos/ABC123
go get github.com/hashicorp/consul/api
- run addsvc
cd ${GOPATH}/src/08.go-kit/04.addsvc;
make pb thrift;
cd ${GOPATH}/src/08.go-kit/04.addsvc/cmd/addsvc;
go run addsvc.go -debug.addr :7080 -http-addr :7081 -grpc-addr :7082 -thrift-addr :7083 -jsonrpc-addr :7084
curl -XPOST -d'{"a":"7","b":"4"}' http://localhost:7081/concat
curl -XPOST -d'{"a":7,"b":4}' http://localhost:7081/sum
- run stringsvc
cd ${GOPATH}/src/08.go-kit/03.stringsvc3;
go run . -listen :8081
curl -XPOST -d'{"s":"mytest"}' http://localhost:8081/count
curl -XPOST -d'{"s":"mytest"}' http://localhost:8081/uppercase
- run consul
cd $HOME; wget https://releases.hashicorp.com/consul/1.6.2/consul_1.6.2_linux_amd64.zip;
unzip consul_1.6.2_linux_amd64.zip; cp consul /usr/local/bin/;
cd ${GOPATH}/src/08.go-kit/07.apigateway;
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 ${GOPATH}/src/08.go-kit/07.apigateway;
go run main.go -consul.addr :8500
curl -XPOST -d'{"a":"7","b":"4"}' http://localhost:8000/addsvc/concat
curl -XPOST -d'{"a":7,"b":4}' http://localhost:8000/addsvc/sum
curl -XPOST -d'{"s":"mytest"}' http://localhost:8000/stringsvc/count
curl -XPOST -d'{"s":"mytest"}' http://localhost:8000/stringsvc/uppercase
cd ${GOPATH}/src/08.go-kit/08.napodate/cmd;
go run main.go
curl http://localhost:8080/get
curl http://localhost:8080/status
curl -XPOST -d '{"date":"32/12/2020"}' http://localhost:8080/validate
curl -XPOST -d '{"date":"12/12/2021"}' http://localhost:8080/validate
cd ${GOPATH}/src/github.com/go-kit/kit/cmd/kitgen
go get .
go install
kitgen -h
- autogenerate endpoints, http, service with kitgen
cd ${GOPATH}/src/08.go-kit/09.kitloc;
mkdir hello; cd hello
kitgen ../service.go
docker run -d -p 9411:9411 openzipkin/zipkin
go get go.opencensus.io
go get contrib.go.opencensus.io/exporter/zipkin
cd ${GOPATH}/src/08.go-kit/09.kitloc;
go run cmd/hello/main.go
export PORT=40775
curl -X POST -d '{}' http://localhost:${PORT}/hello
curl -X POST -d '{"FirstName":"John"}' http://localhost:${PORT}/hello
curl -X POST -d '{"LastName":"Doe"}' http://localhost:${PORT}/hello
curl -X POST -d '{"FirstName":"John","LastName":"Doe"}' http://localhost:${PORT}/hello
- Endpoint URL Format : /lorem/{type}/{min}/{max}
- prepare
go get github.com/go-kit/kit
go get github.com/drhodes/golorem
go get github.com/gorilla/mux
cd ${GOPATH}/src/08.go-kit/10.lorem
go run lorem.d/main.go
curl -X POST http://localhost:8080/lorem/word/1/50
curl -X POST http://localhost:8080/lorem/sentence/1/50
curl -X POST http://localhost:8080/lorem/paragraph/1/50
curl -X POST http://localhost:8080/lorem/nomention/1/50