grpcserver

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Addr is the network address to listen on.
	Addr string
	// CMuxReadTimeout bounds the amount of time spent muxing connections between
	// gRPC and HTTP. A zero-value specifies unbounded muxing.
	CMuxReadTimeout time.Duration
	// LameDuckDuration specifies the length of the lame duck period during
	// graceful shutdown. If non-zero, the Server will mark itself unhealthy to
	// stop new incoming connections while continuing to serve existing
	// connections.
	LameDuckDuration time.Duration
	// AllowReflection specifies whether to register the gRPC server for
	// reflection. This is required to use with tools like grpc_cli.
	AllowReflection bool
	// EnableTracing specifies whether to install opentracing interceptors on
	// the gRPC server.
	EnableTracing bool
	// EnableChannelz specifies whether to register the channelz service on the
	// gRPC server.
	EnableChannelz bool

	// MetricsEndpoint is the route to serve promhttp metrics on, including
	// those collected be grpc_prometheus interceptors.
	//
	// It is the user's responsibility to ensure this does not conflict with
	// other endpoints.
	//
	// Omit to not export metrics.
	MetricsEndpoint string

	StreamInterceptors []grpc.StreamServerInterceptor
	UnaryInterceptors  []grpc.UnaryServerInterceptor
}

Options defines the set of configurations for a gRPC server.

type Server

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

Server provides a multiplexed gRPC/HTTP server.

func New

func New(name string, opts Options) *Server

New returns a new server. See Options for documentation on configuration options.

The underlying gRPC server always has the following interceptors:

  • prometheus
  • recovery: this handles recovering from panics.

The full list of interceptors is as follows: - (optional) interceptors defined on the Options struct - prometheus - (optional) opentracing, if opts.EnableTracing is set - recovery

func (*Server) GRPCServer

func (s *Server) GRPCServer() *grpc.Server

GRPCServer returns the gRPC Server.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe sets up a listener, multiplexes it into gRPC and non-gRPC requests, and binds the gRPC server and mux.Router to them, respectively. It then installs a signal handler on SIGTERM and SIGQUIT, and runs until either a signal or an unrecoverable error occurs.

On shutdown, it may begin a lame duck period (see Options) before beginning a graceful shutdown of the gRPC server and closing listeners.

func (*Server) MustListenAndServe

func (s *Server) MustListenAndServe()

MustListenAndServe calls ListenAndServe and panics if an error occurs.

func (*Server) Router

func (s *Server) Router() *mux.Router

Router returns the mux.Router powering the HTTP side of the server.

Jump to

Keyboard shortcuts

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