grpcutils

package
v1.10.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: BSD-3-Clause Imports: 15 Imported by: 10

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,
		MaxConnectionAge:      defaultServerMaxConnectionAge,
		MaxConnectionAgeGrace: defaultServerMaxConnectionAgeGrace,
	}),
}

Functions

func Dial

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.8.4

func EnsureValidResponseCode(code int) int

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

func Errorf

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

func GetGRPCErrorFromHTTPResponse

func GetGRPCErrorFromHTTPResponse(resp *httppb.HandleSimpleHTTPResponse) error

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

func GetHTTPHeader

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

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

func GetHTTPResponseFromError

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

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

func MergeHTTPHeader

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

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

func NewListener

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

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.8.4

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

TimestampAsTime validates timestamppb timestamp and returns time.Time.

func TimestampFromTime added in v1.8.4

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

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