grpcutil

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetaTagAuthority   = "authority"
	MetaTagContentType = "content-type"
	MetaTagUserAgent   = "user-agent"
)

MetaTags These are common tags found in the metadata for rpc calls, both unary and streaming.

Variables

This section is empty.

Functions

func DialAddress

func DialAddress(addr string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

DialAddress dials an address with a given set of dial options. It resolves how to dial unix sockets if the address is prefixed with `unix://`.

func GetClientCommonName

func GetClientCommonName(ctx context.Context) (clientCommonName string)

GetClientCommonName fetches the client common name from the context.

func GetMethod

func GetMethod(ctx context.Context) string

GetMethod returns the rpc method from the context.

func Listener

func Listener(bindAddr string) (net.Listener, error)

Listener creates a net listener for a given bind address. It handles detecting if we should create a unix socket address.

func LoggedStreaming

func LoggedStreaming(log logger.Triggerable) grpc.StreamServerInterceptor

LoggedStreaming returns a streaming server interceptor.

func LoggedUnary

LoggedUnary returns a unary server interceptor.

func MetaValue

func MetaValue(md metadata.MD, key string) string

MetaValue returns a value from a metadata set.

func RecoverStream

func RecoverStream(opts ...RecoveryOption) grpc.StreamServerInterceptor

RecoverStream returns a new streaming server interceptor for panic recovery.

func RecoverUnary

func RecoverUnary(opts ...RecoveryOption) grpc.UnaryServerInterceptor

RecoverUnary returns a new unary server interceptor for panic recovery.

func TracedUnary

func TracedUnary(tracer opentracing.Tracer) grpc.UnaryServerInterceptor

TracedUnary returns a unary server interceptor.

func UnaryChain

func UnaryChain(interceptors ...grpc.UnaryServerInterceptor) grpc.UnaryServerInterceptor

UnaryChain reads the middleware variadic args and organizes the calls recursively in the order they appear.

func WithClientCommonName

func WithClientCommonName(ctx context.Context, commonName string) context.Context

WithClientCommonName adds a client common name to a context as a value. This value will supercede parsing the value.

func WithMethod

func WithMethod(ctx context.Context, fullMethod string) context.Context

WithMethod adds a method to a context as a value.

Types

type Graceful

type Graceful struct {
	Log      logger.FullReceiver
	Latch    async.Latch
	Listener net.Listener
	Server   *grpc.Server
}

Graceful is a shim for graceful hosting grpc servers.

func NewGraceful

func NewGraceful(listener net.Listener, server *grpc.Server) *Graceful

NewGraceful returns a new graceful host for a grpc server.

func (*Graceful) IsRunning

func (gz *Graceful) IsRunning() bool

IsRunning returns if the server is running.

func (*Graceful) NotifyStarted

func (gz *Graceful) NotifyStarted() <-chan struct{}

NotifyStarted returns the notify started signal.

func (*Graceful) NotifyStopped

func (gz *Graceful) NotifyStopped() <-chan struct{}

NotifyStopped returns the notify stopped signal.

func (*Graceful) Start

func (gz *Graceful) Start() error

Start starts the server.

func (*Graceful) Stop

func (gz *Graceful) Stop() error

Stop shuts the server down.

func (*Graceful) WithLogger

func (gz *Graceful) WithLogger(log logger.FullReceiver) *Graceful

WithLogger sets the logger.

type RecoveryHandlerFunc

type RecoveryHandlerFunc func(p interface{}) (err error)

RecoveryHandlerFunc is a function that recovers from the panic `p` by returning an `error`.

type RecoveryOption

type RecoveryOption func(*recoveryOptions)

RecoveryOption is a type that provides a recovery option.

func WithRecoveryHandler

func WithRecoveryHandler(f RecoveryHandlerFunc) RecoveryOption

WithRecoveryHandler customizes the function for recovering from a panic.

Directories

Path Synopsis
examples
full command
Package main implements a server for the Status service and implements a number of extra features like logging and recovery.
Package main implements a server for the Status service and implements a number of extra features like logging and recovery.
full/client command

Jump to

Keyboard shortcuts

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