grpcutils

package
v1.11.4 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: BSD-3-Clause Imports: 15 Imported by: 22

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultDialOptions = []grpc.DialOption{
	grpc.WithDefaultCallOptions(
		grpc.MaxCallRecvMsgSize(math.MaxInt),
		grpc.MaxCallSendMsgSize(math.MaxInt),
		grpc.WaitForReady(defaultWaitForReady),
	),
	grpc.WithKeepaliveParams(keepalive.ClientParameters{
		Time:                defaultClientKeepAliveTime,
		Timeout:             defaultClientKeepAliveTimeOut,
		PermitWithoutStream: defaultPermitWithoutStream,
	}),
	grpc.WithTransportCredentials(insecure.NewCredentials()),
}
View Source
var DefaultServerOptions = []grpc.ServerOption{
	grpc.MaxRecvMsgSize(math.MaxInt),
	grpc.MaxSendMsgSize(math.MaxInt),
	grpc.MaxConcurrentStreams(math.MaxUint32),
	grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
		MinTime:             defaultServerKeepAliveMinTime,
		PermitWithoutStream: defaultPermitWithoutStream,
	}),
	grpc.KeepaliveParams(keepalive.ServerParameters{
		Time:    defaultServerKeepAliveInterval,
		Timeout: defaultServerKeepAliveTimeout,
	}),
}

Functions

func Dial added in v1.7.10

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

gRPC clients created from this ClientConn will wait forever for the Server to become Ready. If you desire a dial timeout ensure context is properly plumbed to the client and use context.WithTimeout.

Dial returns a gRPC ClientConn with the dial options as defined by DefaultDialOptions. DialOption can also optionally be passed.

func EnsureValidResponseCode added in v1.7.11

func EnsureValidResponseCode(code int) int

EnsureValidResponseCode ensures that the response code is valid otherwise it returns 500.

func Errorf added in v1.7.7

func Errorf(code int, tmpl string, args ...interface{}) error

func GetGRPCErrorFromHTTPResponse added in v1.7.7

func GetGRPCErrorFromHTTPResponse(resp *httppb.HandleSimpleHTTPResponse) error

GetGRPCErrorFromHTTPRespone takes an HandleSimpleHTTPResponse as input and returns a gRPC error.

func GetHTTPHeader added in v1.7.7

func GetHTTPHeader(hs http.Header) []*httppb.Element

GetHTTPHeader takes an http.Header as input and returns a slice of Header.

func GetHTTPResponseFromError added in v1.7.7

func GetHTTPResponseFromError(err error) (*httppb.HandleSimpleHTTPResponse, bool)

GetHTTPResponseFromError takes an gRPC error as input and returns a gRPC HandleSimpleHTTPResponse.

func MergeHTTPHeader added in v1.7.7

func MergeHTTPHeader(hs []*httppb.Element, header http.Header)

MergeHTTPHeader takes a slice of Header and merges with http.Header map.

func NewListener added in v1.7.10

func NewListener() (net.Listener, error)

NewListener returns a TCP listener listening against the next available port on the system bound to localhost.

func NewServer added in v1.9.9

func NewServer(opts ...ServerOption) *grpc.Server

NewServer will return a gRPC server with server options as defined by DefaultServerOptions. ServerOption can also optionally be passed.

func Serve added in v1.7.10

func Serve(listener net.Listener, grpcServer *grpc.Server)

Serve will start a gRPC server and block until it errors or is shutdown.

func TimestampAsTime added in v1.7.11

func TimestampAsTime(ts *tspb.Timestamp) (time.Time, error)

TimestampAsTime validates timestamppb timestamp and returns time.Time.

func TimestampFromTime added in v1.7.11

func TimestampFromTime(time time.Time) *tspb.Timestamp

TimestampFromTime converts time.Time to a timestamppb timestamp.

Types

type DialOption added in v1.9.9

type DialOption func(*DialOptions)

func WithChainStreamInterceptor added in v1.9.9

func WithChainStreamInterceptor(interceptors ...grpc.StreamClientInterceptor) DialOption

WithChainStreamInterceptor takes a list of stream client interceptors which are added to the dial options.

func WithChainUnaryInterceptor added in v1.9.9

func WithChainUnaryInterceptor(interceptors ...grpc.UnaryClientInterceptor) DialOption

WithChainUnaryInterceptor takes a list of unary client interceptors which are added to the dial options.

type DialOptions added in v1.9.9

type DialOptions struct {
	// contains filtered or unexported fields
}

DialOptions are options which can be applied to a gRPC client in addition to the defaults set by DefaultDialOptions.

type ServerCloser

type ServerCloser struct {
	// contains filtered or unexported fields
}

func (*ServerCloser) Add

func (s *ServerCloser) Add(server *grpc.Server)

func (*ServerCloser) GracefulStop added in v1.1.4

func (s *ServerCloser) GracefulStop()

func (*ServerCloser) Stop

func (s *ServerCloser) Stop()

type ServerOption added in v1.9.9

type ServerOption func(*ServerOptions)

ServerOption are options which can be applied to a gRPC server in addition to the defaults set by DefaultServerOPtions.

func WithStreamInterceptor added in v1.9.9

func WithStreamInterceptor(streamInterceptor grpc.StreamServerInterceptor) ServerOption

WithStreamInterceptor adds a single stream interceptor to the gRPC server options.

func WithUnaryInterceptor added in v1.9.9

func WithUnaryInterceptor(unaryInterceptor grpc.UnaryServerInterceptor) ServerOption

WithUnaryInterceptor adds a single unary interceptor to the gRPC server options.

type ServerOptions added in v1.9.9

type ServerOptions struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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