grpcutils

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2024 License: BSD-3-Clause Imports: 15 Imported by: 0

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

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

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

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

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

TimestampAsTime validates timestamppb timestamp and returns time.Time.

func TimestampFromTime

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

TimestampFromTime converts time.Time to a timestamppb timestamp.

Types

type DialOption

type DialOption func(*DialOptions)

func WithChainStreamInterceptor

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

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

func WithChainUnaryInterceptor

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

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

type DialOptions

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

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

func WithStreamInterceptor(streamInterceptor grpc.StreamServerInterceptor) ServerOption

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

func WithUnaryInterceptor

func WithUnaryInterceptor(unaryInterceptor grpc.UnaryServerInterceptor) ServerOption

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

type ServerOptions

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