Documentation ¶
Overview ¶
grpc wraps setup of a grpc server with shared defaults for all packet services
Index ¶
- type Option
- func LoadX509KeyPair(certFile, keyFile string) Option
- func Port(port int) Option
- func Register(r func(*grpc.Server)) Option
- func ServerOption(opt grpc.ServerOption) Option
- func StreamInterceptor(si grpc.StreamServerInterceptor) Option
- func UnaryInterceptor(ui grpc.UnaryServerInterceptor) Option
- func X509KeyPair(certPEMBlock, keyPEMBlock string) Option
- type Server
- type ServiceRegister
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Server)
The Option type describes functions that operate on Server during NewServer. It is a convenience type to make it easier for callers to build up the slice of options apart from the call to NewServer.
func LoadX509KeyPair ¶
LoadX509KeyPair will setup server as a secure server by reading the cert and key from the provided file locations. This function overrides GRPC_CERT and GRPC_KEY environment variables. NewServer will return an error if both X509KeyPair and LoadX509KeyPair are used.
func Register ¶
Register will call the callback func after the main grpc service has been setup. The Prometheus register is always included in the set
func ServerOption ¶
func ServerOption(opt grpc.ServerOption) Option
ServerOption will add the opt param to the underlying grpc.NewServer() call.
func StreamInterceptor ¶
func StreamInterceptor(si grpc.StreamServerInterceptor) Option
StreamInterceptor adds the argument to the list of interceptors in a grpc_middleware.Chain Logging and Prometheus interceptors are always included in the set. OpenTelemetry is NOT included by default on streams because it's noisy and can't be on by default.
func UnaryInterceptor ¶
func UnaryInterceptor(ui grpc.UnaryServerInterceptor) Option
UnaryInterceptor adds the argument to the list of interceptors in a grpc_middleware.Chain Logging, Prometheus, and OpenTelemetry interceptors are always included in the set
func X509KeyPair ¶
X509KeyPair will setup server as a secure server using the provided cert and key This function overrides GRPC_CERT and GRPC_KEY environment variables. NewServer will return an error if both X509KeyPair and LoadX509KeyPair are used.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is used to hold configured info and ultimately the grpc server
func NewServer ¶
NewServer creates a new grpc server. By default the server will be an insecure server listening on port 8080 with logging and prometheus interceptors setup.
The server's port is configured via the GRPC_PORT env variable, but can be overriden by the Port helper func. A tls server is setup if keys are provided in either the environment variables GRPC_CERT/GRPC_KEY, or using the X509KeyPair or LoadX509KeyPair helper funcs. Logging is always setup using the provided log.Logger. Prometheus is always setup using the default prom interceptors and Register func. OpenTelemetry is setup for unary servers, but NOT streaming servers. Use StreamingInterceptor to add it if you really want/need it.
req is called after the server has been setup. This is where your service is gets registered with grpc, equivalent to pb.RegisterMyServiceServer(s, &myServiceImpl{}).
After your service has been registered any callbacks that were setup with Register will be called to finish up registration.
type ServiceRegister ¶
type ServiceRegister func(*Server)
The ServiceRegister type is used as a callback once the underlying grpc server is setup to register the main service.