grpcutil

package
v7.0.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2020 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package grpcutil implements some common functionality for gRPC that we use across all servers.

Index

Constants

View Source
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

func Dial(address string, tls bool, caFile, tokenFile string) (*grpc.ClientConn, error)

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

func NewServer(opts Opts) (net.Listener, *grpc.Server)

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

func ServeForever(lis net.Listener, s *grpc.Server)

ServeForever runs the given server until termination via signal.

func ShouldCompress

func ShouldCompress(ctx context.Context) bool

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)

func SkipCompression

func SkipCompression(ctx context.Context) context.Context

SkipCompression returns a context that indicates that we should not compress this request.

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.

Jump to

Keyboard shortcuts

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