Example of using grpc-gateway annotations for a simple health check:
service TaskManagementService {
rpc Health(HealthRequest) returns (HealthResponse) {
option (google.api.http) = {
post: "/v1/example/echo"
body: "*"
};
}
}
Run the following go commands to build and run the example:
go mod tidy
cd cmd/service
go run service.go
# Output
2023/05/25 14:10:55 Starting service
2023/05/25 14:10:55 Listening http on: 127.0.0.1:8080
2023/05/25 14:10:55 Listening grpc on: 127.0.0.1:9090
curl -XPOST "localhost:8080/v1/example/echo" -H "content-type: application/json" -d "{}"
# Output
{"status":"healthy"}
The generate protobuf code is already checked into the repo, but if you want to regenerate use the following commands at the base of the repo:
rm -rf gen
buf generate proto --include-imports