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, ...) kit.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 []byte, serverKey []byte) (ServerOption, error)
- 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 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 ¶
func AuthInterceptors(unary grpc.UnaryServerInterceptor, stream grpc.StreamServerInterceptor) ServerOption
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
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.