Start server using go run main.go
. To print available arguments, run go run main.go -h
. If using gateway mode or gateway-hybrid mode, you can play with APIs at http://localhost:8080/swagger.
- Go
- Protocol buffer compiler, version 3
- Go plugins for the protocol buffer compiler
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
- gRPC gateway and OpenAPI plugin for the protocol buffer compiler
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest
Run the example command in the "grpc_example_proto" repository to generate server library.
OUTPUT_DIR=./go_gens
TARGET_DIR=../grpc_example_server
make OUTPUT_DIR=${OUTPUT_DIR} \
EXTRA_FLAGS="--grpc-gateway_opt=logtostderr=true,generate_unbound_methods=true --grpc-gateway_out=${OUTPUT_DIR} --openapiv2_opt=logtostderr=true,generate_unbound_methods=true,allow_merge=true --openapiv2_out=${OUTPUT_DIR}" \
&& cp -r go_gens/grpc_example/proto ${TARGET_DIR} \
&& cp go_gens/apidocs.swagger.json ${TARGET_DIR}/third_party/swagger_ui
- Build server binary for the Linux AMD64 platform
env GOOS=linux GOARCH=amd64 go build -o build/server main.go
- Build Docker image
docker build -t grpc_example_server .
- Run all tests
go test github.com/zmzhang8/grpc_example/...
- Run tests in a package
go test github.com/zmzhang8/grpc_example/path/to/package