grpc

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientConfig added in v0.21.0

type ClientConfig struct {
	Address              string                         // Address on which the server is accessible
	UnaryInterceptors    []grpc.UnaryClientInterceptor  // Client unary interceptors to apply
	StreamInterceptors   []grpc.StreamClientInterceptor // Client stream interceptors to apply
	Options              []grpc.DialOption              // Additional server options
	Port                 uint16                         // Port on which the server is accessible
	PropagateAuthHeaders bool                           // If true propagate any authorization header to the server
	RetryServerErrors    bool                           // If true, the client will automatically retry on server errors
}

ClientConfig contains the configuration necessary for connecting to a gRPC Server.

func NewDefaultClientConfig added in v0.21.0

func NewDefaultClientConfig(ctx context.Context) ClientConfig

NewDefaultClientConfig returns the default SpotHero gRPC plaintext Client Configuration

func NewDefaultTLSClientConfig added in v0.51.0

func NewDefaultTLSClientConfig(ctx context.Context) ClientConfig

NewDefaultTLSClientConfig returns the default SpotHero gRPC TLS Client Configuration

func (ClientConfig) GetConn added in v0.21.0

func (cc ClientConfig) GetConn() (*grpc.ClientConn, error)

GetConn dials and returns a gRPC connection. It is the responsibility of the caller to make sure they call `conn.Close()` through a defer statement or otherwise.

func (*ClientConfig) RegisterFlags added in v0.21.0

func (cc *ClientConfig) RegisterFlags(flags *pflag.FlagSet, serverName string)

RegisterFlags registers gRPC client configuration flags with pflags. Callers must specify a server name when calling this function. For example, if your service interacts with grpc service "foo" and "bar", you might register flags for both of these servers in your application. As such you must provide the names "foo" and "bar" and call this function twice. If you do, you will end up with a set of flags for each server in the format `--foo-grpc-server-address` and `--bar-grpc-server-address`.

Failure to provide a server name will result in a panic.

type Config

type Config struct {
	ServerRegistration func(*grpc.Server)             // Callback for registering GRPC API Servers
	Name               string                         // Name of the GRPC Server
	Address            string                         // Address on which the server will be accessible
	TLSCrtPath         string                         // Location of TLS Certificate
	TLSKeyPath         string                         // Location of TLS Key
	StreamInterceptors []grpc.StreamServerInterceptor // A list of global GRPC stream interceptor functions to be called. Order is honored left to right.
	UnaryInterceptors  []grpc.UnaryServerInterceptor  // A list of global GRPC unary interceptor functions to be called. Order is honored left to right.
	CancelSignals      []os.Signal                    // OS Signals to be used to cancel running servers. Defaults to SIGINT/`os.Interrupt`.
	Port               uint16                         // Port on which the server will be accessible
	TLSEnabled         bool                           // Whether or not traffic should be served via HTTPS
}

Config contains the configuration necessary for running a GRPC Server.

func NewDefaultConfig

func NewDefaultConfig(name string, serverRegistration func(*grpc.Server)) Config

NewDefaultConfig returns a default GRPC server config object. The caller must still supply the name of the server and a serverRegistration callback. The serverRegistration callback is a function that registers GRPC API servers with the provided GRPC server.

func (Config) NewServer

func (c Config) NewServer() Server

NewServer creates and returns a configured Server object given a GRPC configuration object.

func (*Config) RegisterFlags

func (c *Config) RegisterFlags(flags *pflag.FlagSet)

RegisterFlags registers GRPC flags with pflags

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server contains the configured GRPC server and related components

func (Server) Run

func (s Server) Run() (chan bool, error)

Run starts the GRPC server. The function returns an error if the GRPC server cannot bind to its listen address. This function is non-blocking and will return immediately. If no error is returned the server is running. The returned channel will be closed after the server shuts down.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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