server

package
v0.0.0-...-013b7c2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LogGRPCRequest

func LogGRPCRequest(
	ctx context.Context,
	req any,
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (resp any, err error)

LogGRPCRequest is a grpc.UnaryServerInterceptor which logs all gRPC requests at the debug level. If the request returned an error, it is also logged in a separate log message. If the error is an internal or unexpected error, it is logged at the error level, otherwise it is logged at the debug level.

Types

type ApplicationServer

type ApplicationServer struct {
	// Mux is the gRPC-Gateway multiplexer. It is exported so that it can be
	//passed to the AWS Lambda adapter (see the top level lambda/main.go).
	Mux *runtime.ServeMux
	// contains filtered or unexported fields
}

ApplicationServer is the container struct representing the actual application. It stores the state of all runtime dependencies, such as protocol listeners, gRPC service implementations, etc. Once constructed, the server should be initialized with the Init method, and then run with one of Serve methods (Serve, ServeGrpc, ServeHttp).

func NewApplicationServer

func NewApplicationServer(cfg config.Config) *ApplicationServer

NewApplicationServer creates a new ApplicationServer instance with the given configuration.

func (*ApplicationServer) Init

func (app *ApplicationServer) Init(ctx context.Context) error

Init calls various initializer methods necessary for proper startup. Note that the order of the init method calls are here because there are no nil-checks in the initializers. Init works primarily via side effects. The global application state is largely stored in the ApplicationServer struct. This method serves to populate the runtime dependencies (fields) of the ApplicationServer instance. It should be called immediately before Run.

func (*ApplicationServer) Serve

func (app *ApplicationServer) Serve(ctx context.Context, grpcListener, httpListener net.Listener) error

Serve brings up a gRPC and HTTP API server and continues until there's either a failure or the server is otherwise terminated or killed. Requires a prior call to Init.

func (*ApplicationServer) ServeGrpc

func (app *ApplicationServer) ServeGrpc(ctx context.Context, lis net.Listener) error

ServeGrpc starts the gRPC server and blocks until it stops. This method is intended to be called in a separate goroutine if necessary. It is a wrapper around grpc.Server.Serve, but it also handles graceful shutdown. Requires a prior call to Init.

func (*ApplicationServer) ServeHttp

func (app *ApplicationServer) ServeHttp(ctx context.Context, lis net.Listener) error

ServeHttp starts the HTTP server and blocks until it stops. This method is intended to be called in a separate goroutine if necessary. It is a wrapper around http.Server.Serve, but it also handles graceful shutdown. Requires a prior call to Init.

Jump to

Keyboard shortcuts

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