grpcserver

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2019 License: BSD-3-Clause Imports: 25 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 suitible for serving gRPC services using H2C (aka client upgrades). This is suitible 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, serverKey []byte, server Starter, opts ...ServerOption) kit.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 localsrv.Run()
defer localsrv.Stop(nil)

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

resp, err := c.Check(context.Background(), &healthpb.HealthCheckRequest{}, grpc.FailFast(true))
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(err 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 intented 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 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 []byte, serverKey []byte) (ServerOption, error)

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

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(err 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