grpcutil

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2021 License: Apache-2.0 Imports: 7 Imported by: 2

Documentation

Overview

Package grpcutil contains utility functions to create gRPC clients and servers

Package grpcutil contains nice-to-have gRPC client and server types to reduce the boilerplate a bit.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDialOpts

func GetDialOpts(config GRPCClientParam) ([]grpc.DialOption, error)

GetDialOpts returns a populated grpc.DialOption array from the client parameters.

func GetServerOpts added in v1.0.10

func GetServerOpts(config GRPCServerParam) ([]grpc.ServerOption, error)

GetServerOpts returns the server options. Note that the options might include an unary interceptor if the metrics flag is set (there can be only one per server) so if you use additional unary interceptors you have to chain them yourself.

func NewGRPCClientConnection

func NewGRPCClientConnection(config GRPCClientParam, opts ...grpc.DialOption) (*grpc.ClientConn, error)

NewGRPCClientConnection is a factory method to create gRPC client connections

Types

type GRPCClientParam

type GRPCClientParam struct {
	ServerEndpoint     string `kong:"help='Server endpoint',default='localhost:10000'"` // Host:port address of the server
	TLS                bool   `kong:"help='Enable TLS',default='false'"`                // TLS enabled
	CAFile             string `kong:"help='CA certificate file',type='existingfile'"`   // CA cert file
	ServerHostOverride string `kong:"help='Host name override for certificate'"`        // Server name returned from the TLS handshake (for debugging)

}

GRPCClientParam contains gRPC client parameters. These paramters are the same for every gRPC client across the system.

type GRPCServer

type GRPCServer interface {
	// Start launches the server in the foreground
	Start(registerFunc func(s *grpc.Server)) error

	// StartWithOpts launches a new server with additional server options. Use
	// GetServerOpts to get the default set of options.
	StartWithOpts(registerFunc func(s *grpc.Server), opts []grpc.ServerOption) error

	// Launch launches the server in the background
	Launch(registerFunc func(s *grpc.Server), timeout time.Duration) error

	// LaunchWithOpts launches the server in the background with addtional server options
	LaunchWithOpts(registerFunc func(s *grpc.Server), timeout time.Duration, opts []grpc.ServerOption) error

	// Endpoint returns the server's endpoint
	ListenAddress() net.Addr

	// Stop shuts down the server
	Stop()
}

GRPCServer is the common interface for GRPC servers

func NewGRPCServer

func NewGRPCServer(params GRPCServerParam) (GRPCServer, error)

NewGRPCServer configures a new GRPC server. A port will be allocated for the server

type GRPCServerParam

type GRPCServerParam struct {
	Endpoint string `kong:"help='Service endpoint',default='localhost:0'"`
	TLS      bool   `kong:"help='Enable TLS',default='false'"`
	CertFile string `kong:"help='Certificate file',type='existingfile'"`
	KeyFile  string `kong:"help='Certificate key file',type='existingfile'"`
	Metrics  bool   `kong:"help='Add Prometheus interceptors for server',default='true'"`
}

GRPCServerParam holds parameters for a GRPC server

Jump to

Keyboard shortcuts

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