Go example for Twitch's Twirp RPC framework
Twirp is a framework for service-to-service communication emphasizing simplicity and minimalism. It generates routing and serialization from API definition files and lets you focus on your application's logic instead of thinking about folderol like HTTP methods and paths and JSON.
See Twirp official repository.
All executables are located at the cmd
directory.
There are 5 examples:
- Clients
grpc-client
: Can connect togrpc-server
andhybrid-server
twirp-client
: Can connect totwirp-server
andhybrid-server
- Servers
grpc-server
: Can be connected bygrpc-client
twirp-server
: Can be connected bytwirp-client
andcURL
hybrid-server
: Can be connected bygrpc-client
,twirp-client
andcURL
$ ./build/bin/grpc-server
or
$ ./build/bin/twirp-server
or
$ ./build/bin/hybrid-server
$ ./build/bin/grpc-client
or
$ ./build/bin/twirp-client
HTTP endpoints: http://host
:port
/twirp/am.is.PetstoreService/<method>
$ curl -s -XPOST http://localhost:8000/twirp/am.is.PetstoreService/AddPet --header "Content-Type:application/json" --data '{"pet": {"name": "Test"}}' | jq
Output
{
"name": "Test"
}
Build all executables
$ make all
Generate code from protobuf
$ make gen
Clean all executables
$ make clean
Run go test
$ make test
Run dep ensure
$ make deps
Build docker image
$ make docker
Push docker image
$ make docker-push
Note: Be sure to set
DOCKER_REPOSITORY
inMakefile
for your own before building and pushing the docker image.
The MIT License