grpcserver

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: BSD-3-Clause Imports: 32 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorToCode

func ErrorToCode(err error) codes.Code

ErrorToCode determines the gRPC error code for an error, accounting for context errors and errors wrapped with pkg/errors.

ErrorToCode implements grpc_logging.ErrorToCode.

func New

func New(opts ...ServerOption) *grpc.Server

New configures a gRPC Server with default options and a health server.

func NewStandardH2C

func NewStandardH2C(http11 http.Handler, opts ...ServerOption) (*grpc.Server, *http.Server)

NewStandardH2C create a set of servers suitable for serving gRPC services using H2C (aka client upgrades). This is suitable for serving gRPC services via both hermes and dogwood-router. HTTP 1.x traffic will be passed to the provided handler. This will return a *grpc.Server configured with our standard set of services, and a HTTP server that should be what is served on a listener.

func NewStandardServer

func NewStandardServer(logger log.FieldLogger, port int, serverCACerts [][]byte, serverCert tls.Certificate, server Starter, opts ...ServerOption) cmdutil.Server

NewStandardServer configures a GRPC server with a standard setup including metrics (if provider passed), panic handling, a health check service, TLS termination with client authentication, and proxy-protocol wrapping.

func RunStandardServer deprecated

func RunStandardServer(logger log.FieldLogger, port int, serverCACerts [][]byte, serverCert, serverKey []byte, server Starter, opts ...ServerOption) error

RunStandardServer runs a GRPC server with a standard setup including metrics (if provider passed), panic handling, a health check service, TLS termination with client authentication, and proxy-protocol wrapping.

Deprecated: Use NewStandardServer instead.

func UnaryPayloadLoggingTagger

func UnaryPayloadLoggingTagger(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (_ interface{}, err error)

UnaryPayloadLoggingTagger annotates ctx with grpc_ctxtags tags for request and response payloads.

A loggable request or response implements this interface

type loggable interface {
	LoggingTags() map[string]interface{}
}

Any request or response implementing this interface will add tags to the context for logging in success and error cases.

Types

type LocalServer

type LocalServer struct {
	// contains filtered or unexported fields
}

An LocalServer serves a gRPC server from memory.

func Local

func Local(s *grpc.Server) *LocalServer

Local returns an in-process server for the provided gRPC server.

Example
srv := New()
localsrv := Local(srv)

go func() {
	if err := localsrv.Run(); err != nil {
		panic(err)
	}
}()
defer localsrv.Stop(nil)

c := healthpb.NewHealthClient(localsrv.Conn())

resp, err := c.Check(context.Background(), &healthpb.HealthCheckRequest{}, grpc.WaitForReady(false))
if err != nil {
	fmt.Printf("Error = %v", err)
	return
}

fmt.Printf("Status = %v", resp.Status)
Output:

Status = SERVING

func (*LocalServer) Conn

func (s *LocalServer) Conn(opts ...grpc.DialOption) *grpc.ClientConn

Conn returns a client connection to the in-process server.

func (*LocalServer) Run

func (s *LocalServer) Run() error

Run starts the in-process server.

It implements oklog group's runFn.

func (*LocalServer) Stop

func (s *LocalServer) Stop(error)

Stop gracefully stops the gRPC server.

It implements oklog group's interruptFn.

type ServerOption

type ServerOption func(*options)

ServerOption sets optional fields on the standard gRPC server

func AuthInterceptors

AuthInterceptors sets interceptors that are intended for authentication/authorization in the correct locations in the chain

func GRPCOption

func GRPCOption(opt grpc.ServerOption) ServerOption

GRPCOption adds a grpc ServerOption to the server.

func HighCardInterceptors added in v0.0.49

func HighCardInterceptors(unary grpc.UnaryServerInterceptor, stream grpc.StreamServerInterceptor) ServerOption

HighCardInterceptors sets interceptors that use Attributes/Labels on the instrumentation.

func LogEntry

func LogEntry(entry *logrus.Entry) ServerOption

LogEntry provided will be added to the context

func MetricsProvider

func MetricsProvider(provider metrics.Provider) ServerOption

MetricsProvider will have metrics reported to it

func TLS

func TLS(caCerts [][]byte, serverCert tls.Certificate) (ServerOption, error)

TLS returns a ServerOption which adds mutual-TLS to the gRPC server.

func ValidateInterceptor added in v0.0.5

func ValidateInterceptor() ServerOption

ValidateInterceptor sets interceptors that will validate every message that has a receiver of the form `Validate() error`

See github.com/mwitkow/go-proto-validators for details.

func WithOCGRPCServerHandler added in v0.0.14

func WithOCGRPCServerHandler(h *ocgrpc.ServerHandler) ServerOption

WithOCGRPCServerHandler sets the grpc server up with provided ServerHandler as its StatsHandler

func WithPeerValidator added in v0.0.6

func WithPeerValidator(f func(*x509.Certificate) bool) ServerOption

WithPeerValidator configures the gRPC server to reject calls from peers which do not provide a certificate or for which the provided function returns false.

func WithReadHeaderTimeout added in v0.1.0

func WithReadHeaderTimeout(d time.Duration) ServerOption

type Starter

type Starter interface {
	Start(srv *grpc.Server) error
}

A Starter registers and starts itself on the provided grpc.Server.

It's expected Start will call the relevant RegisterXXXServer method using srv.

type TCPServer

type TCPServer struct {
	// contains filtered or unexported fields
}

A TCPServer serves a gRPC server over TCP with proxy-protocol support.

func TCP

func TCP(l logrus.FieldLogger, s *grpc.Server, addr string) *TCPServer

TCP returns a TCP server for the provided gRPC server.

The server transparently handles proxy protocol.

func (*TCPServer) Run

func (s *TCPServer) Run() error

Run binds to the configured address and serves the gRPC server.

It implements oklog group's runFn.

func (*TCPServer) Stop

func (s *TCPServer) Stop(error)

Stop gracefully stops the gRPC server.

It implements oklog group's interruptFn.

Jump to

Keyboard shortcuts

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