Documentation ¶
Overview ¶
Package grpcutil implements some common functionality for gRPC that we use across all servers.
Index ¶
- Constants
- func Dial(address string, tls bool, caFile, tokenFile string) (*grpc.ClientConn, error)
- func DialOptions(tokenFile string) []grpc.DialOption
- func LogStreamRequests(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, ...) error
- func LogUnaryRequests(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (interface{}, error)
- func NewServer(opts Opts) (net.Listener, *grpc.Server)
- func OptionalTLS(keyFile, certFile string, opts ...grpc.ServerOption) []grpc.ServerOption
- func ServeForever(lis net.Listener, s *grpc.Server)
- func ShouldCompress(ctx context.Context) bool
- func SkipCompression(ctx context.Context) context.Context
- type Opts
Constants ¶
const GCKey = "purity-gc"
GCKey is a metadata key that we use to identify GC requests which don't extend the lifetime of an action result.
Variables ¶
This section is empty.
Functions ¶
func Dial ¶
Dial is a convenience function wrapping up some common gRPC functionality. If the URL is prefixed by a protocol (grpc:// or grpcs://) that overrides the TLS flag.
func DialOptions ¶
func DialOptions(tokenFile string) []grpc.DialOption
DialOptions returns some common dial options.
func LogStreamRequests ¶
func LogStreamRequests(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error
LogStreamRequests is a gRPC interceptor that logs outcomes of stream requests.
func LogUnaryRequests ¶
func LogUnaryRequests(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
LogUnaryRequests is a gRPC interceptor that logs outcomes of unary requests.
func NewServer ¶
NewServer creates a new gRPC server with a standard set of interceptors. It opens the relevant port and returns a listener for it, but does not begin serving.
func OptionalTLS ¶
func OptionalTLS(keyFile, certFile string, opts ...grpc.ServerOption) []grpc.ServerOption
OptionalTLS loads TLS certificates from the given files and attaches them as a gRPC ServerOption. If both filenames are empty then no credentials will be attached.
func ServeForever ¶
ServeForever runs the given server until termination via signal.
func ShouldCompress ¶
ShouldCompress returns true if an incoming context does not indicate that we shouldn't compress the stream (i.e. the default is to compress it)
Types ¶
type Opts ¶
type Opts struct { Host string `long:"host" description:"Host to listen on"` Port int `short:"p" long:"port" default:"7777" description:"Port to serve on"` KeyFile string `short:"k" long:"key_file" description:"Key file to load TLS credentials from"` CertFile string `short:"c" long:"cert_file" description:"Cert file to load TLS credentials from"` TokenFile string `long:"token_file" description:"File containing a pre-shared token that clients must provide as authentication."` AuthAll bool `long:"auth_all" description:"Require authentication on all RPCs (by default only on RPCs that mutate state)"` }
Opts is the set of common options for gRPC servers.