rpc

package
v0.2.71 Latest Latest
Warning

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

Go to latest
Published: May 28, 2024 License: Apache-2.0 Imports: 22 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientConn

func ClientConn(cfg ClientCfg) (conn *grpc.ClientConn, err error)

ClientConn opens client connection with given configuration.

func PrepareServe

func PrepareServe(cfg *ServerCfg) (s *grpc.Server, lis net.Listener, err error)

PrepareServe builds gRPC server that allows graceful shutdown. You must start it by yourself with Serve() that blocks which typically means that you need a goroutine for that.

func Serve

func Serve(cfg *ServerCfg)

Serve builds up the gRPC server and starts to serve. Note that the function blocks. In most cases you should start it as goroutine. To be able to gracefully stop the gRPC server you should call PrepareServe which builds everything ready but leaves calling the grpcServer.Serve for you.

func Server

func Server(cfg *ServerCfg) (s *grpc.Server, err error)

Server creates a gRPC server with TLS and JWT token authorization.

Types

type CertFiles

type CertFiles struct {
	CertFile string
	KeyFile  string
}

CertFiles is helper struct to keep both needed certification files together.

type ClientCfg

type ClientCfg struct {
	*PKI
	JWT  string
	Addr string
	Opts []grpc.DialOption
	// Client should set the insecure flag if token should be sent
	// over insecure connection - intended for internal, secure networks only
	Insecure bool
}

ClientCfg is gRPC client initialization and configuration struct.

func (ClientCfg) GetRequestMetadata added in v0.1.41

func (c ClientCfg) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error)

func (ClientCfg) RequireTransportSecurity added in v0.1.41

func (c ClientCfg) RequireTransportSecurity() bool

type PKI

type PKI struct {
	ServerName string
	Server     CertFiles
	Client     CertFiles
}

PKI is helper struct to keep need certification files for both S/C.

func LoadPKI

func LoadPKI(tlsPath string) *PKI

func LoadPKIWithServerName added in v0.1.7

func LoadPKIWithServerName(tlsPath, serverName string) *PKI

type ServerCfg

type ServerCfg struct {
	*PKI
	Port      int
	TestLis   *bufconn.Listener
	Register  func(s *grpc.Server) error
	JWTSecret string

	NoAuthorization bool
}

ServerCfg is gRPC server configuration struct for service init

Jump to

Keyboard shortcuts

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