https://github.com/chainguard-dev/go-grpc-kit
Utility methods for gRPC.
https://github.com/chainguard-dev/go-grpc-kit
Last synced: about 2 months ago
JSON representation
Utility methods for gRPC.
- Host: GitHub
- URL: https://github.com/chainguard-dev/go-grpc-kit
- Owner: chainguard-dev
- License: apache-2.0
- Created: 2022-02-03T19:49:44.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-21T20:07:20.000Z (7 months ago)
- Last Synced: 2024-10-22T05:56:08.782Z (7 months ago)
- Language: Go
- Size: 360 KB
- Stars: 8
- Watchers: 1
- Forks: 11
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gRPC Kit
This repository contains helpers working with gRPC.
## gRPC Duplex
For cases where you would like to serve both the gRPC endpoint and a
[gRPC Gateway](https://grpc-ecosystem.github.io/grpc-gateway/), the
chainguard.dev/grpc/pkg/duplex package is a helpful wrapper.First, define the REST endpoints in the `.proto` file. Then change to use the
duplex object to start and build up the gRPC server. Example:```go
d := duplex.New(8080)pb.RegisterServer(d.Server, impl.NewServer())
if err := d.RegisterHandler(ctx, impl.RegisterServiceHandlerFromEndpoint); err != nil {
log.Panicf("Failed to register gateway endpoint: %v", err)
}...
if err := d.ListenAndServe(ctx); err != nil {
log.Panicf("ListenAndServe() = %v", err)
}
```Run this and you should see a message like:
```text
Duplex gRPC/HTTP server starting at ::8080
```### Options
You can pass `grpc.ServerOption` and `runtime.NewServeMux` into `duplex.New`.
For example, if you wanted to make a duplex server with a
[unary interceptor](https://pkg.go.dev/google.golang.org/grpc#UnaryInterceptor):```go
d := duplex.New(port, grpc.UnaryInterceptor(myInterceptorFn))
```