grpcutils

package
v1.9.5-rc.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: BSD-3-Clause Imports: 16 Imported by: 3

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(true),
		),
		grpc.WithKeepaliveParams(keepalive.ClientParameters{
			Time:                defaultClientKeepAliveTime,
			Timeout:             defaultClientKeepAliveTimeOut,
			PermitWithoutStream: defaultPermitWithoutStream,
		}),
	}

	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 ...grpc.DialOption) (*grpc.ClientConn, error)

func DialOptsWithMetrics added in v1.8.4

func DialOptsWithMetrics(clientMetrics *grpc_prometheus.ClientMetrics) []grpc.DialOption

DialOptsWithMetrics registers gRPC client metrics via chain interceptors.

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 NewDefaultServer

func NewDefaultServer(opts []grpc.ServerOption) *grpc.Server

NewDefaultServer ensures the plugin service is served with proper defaults. This should always be passed to GRPCServer field of plugin.ServeConfig.

func NewListener

func NewListener() (net.Listener, error)

func Serve

func Serve(listener net.Listener, grpcServerFunc func([]grpc.ServerOption) *grpc.Server)

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 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()

Jump to

Keyboard shortcuts

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