Documentation ¶
Index ¶
- func ErrorToCode(err error) codes.Code
- func New(opts ...ServerOption) *grpc.Server
- func NewStandardH2C(http11 http.Handler, opts ...ServerOption) (*grpc.Server, *http.Server)
- func NewStandardServer(logger log.FieldLogger, port int, serverCACerts [][]byte, ...) cmdutil.Server
- func RunStandardServer(logger log.FieldLogger, port int, serverCACerts [][]byte, ...) errordeprecated
- func UnaryPayloadLoggingTagger(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, ...) (_ interface{}, err error)
- type LocalServer
- type ServerOption
- func AuthInterceptors(unary grpc.UnaryServerInterceptor, stream grpc.StreamServerInterceptor) ServerOption
- func GRPCOption(opt grpc.ServerOption) ServerOption
- func LogEntry(entry *logrus.Entry) ServerOption
- func MetricsProvider(provider metrics.Provider) ServerOption
- func TLS(caCerts [][]byte, serverCert tls.Certificate) (ServerOption, error)
- func ValidateInterceptor() ServerOption
- func WithOCGRPCServerHandler(h *ocgrpc.ServerHandler) ServerOption
- func WithPeerValidator(f func(*x509.Certificate) bool) ServerOption
- type Starter
- type TCPServer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorToCode ¶
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 ¶
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()) //TODO: SA1019: grpc.FailFast is deprecated: use WaitForReady. (staticcheck) resp, err := c.Check(context.Background(), &healthpb.HealthCheckRequest{}, grpc.FailFast(true)) //nolint:staticcheck 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 ¶
func AuthInterceptors(unary grpc.UnaryServerInterceptor, stream grpc.StreamServerInterceptor) ServerOption
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 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.
type Starter ¶
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 ¶
TCP returns a TCP server for the provided gRPC server.
The server transparently handles proxy protocol.