grpc

package
v0.0.0-...-f8a288c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2023 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Overview

grpc wraps setup of a grpc server with shared defaults for all packet services

Index

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

func LoadX509KeyPair(certFile, keyFile string) Option

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 Port

func Port(port int) Option

Port will set the port the server will bind to, Port must be > 0

func Register

func Register(r func(*grpc.Server)) Option

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

func X509KeyPair(certPEMBlock, keyPEMBlock string) Option

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

func NewServer(l log.Logger, reg ServiceRegister, options ...Option) (*Server, error)

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.

func (*Server) Port

func (s *Server) Port() int

Port returns the port the server is listening on

func (*Server) Serve

func (s *Server) Serve() error

Serve starts the grpc server

func (*Server) Server

func (s *Server) Server() *grpc.Server

Server returns the grpc server

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.

Directories

Path Synopsis
authz module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL