grpcutils

package
v1.9.1-rc.7 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2022 License: BSD-3-Clause Imports: 16 Imported by: 29

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 added in v1.7.10

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

func DialOptsWithMetrics added in v1.7.15

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

DialOptsWithMetrics registers gRPC client metrics via chain interceptors.

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 NewDefaultServer added in v1.7.10

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 added in v1.7.10

func NewListener() (net.Listener, error)

func Serve added in v1.7.10

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

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

Jump to

Keyboard shortcuts

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