grpcutil

package
v5.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: May 17, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

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.

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