grpc

package
v0.0.0-...-fc4206c Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Overview

Package grpc provides the backbone for a gRPC server with some opinionated defaults.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is an option for the gRPC server.

func WithContextExtender

func WithContextExtender(contextExtender ...func(context.Context) context.Context) Option

WithContextExtender adds functions that extend request contexts.

func WithForwardIncomingHeaders

func WithForwardIncomingHeaders(headers ...string) Option

WithForwardIncomingHeaders makes the gRPC gateway forward the given request headers.

func WithForwardOutgoingHeaders

func WithForwardOutgoingHeaders(headers ...string) Option

WithForwardOutgoingHeaders makes the gRPC gateway forward the given response headers.

func WithGRPCServerOption

func WithGRPCServerOption(serverOptions ...grpc.ServerOption) Option

WithGRPCServerOption adds serverOptions. The options UnaryInterceptor, StreamInterceptor and StatsHandler should not be used.

func WithGRPCWebOption

func WithGRPCWebOption(grpcWebOptions ...grpcweb.Option) Option

WithGRPCWebOption adds grpcWebOptions.

func WithRuntimeServeMuxOption

func WithRuntimeServeMuxOption(serveMuxOptions ...runtime.ServeMuxOption) Option

WithRuntimeServeMuxOption adds serveMuxOptions.

func WithStatsHandler

func WithStatsHandler(handler ...stats.Handler) Option

WithStatsHandler adds stats handlers.

func WithStreamInterceptor

func WithStreamInterceptor(interceptor ...grpc.StreamServerInterceptor) Option

WithStreamInterceptor adds stream interceptors.

func WithUnaryInterceptor

func WithUnaryInterceptor(interceptor ...grpc.UnaryServerInterceptor) Option

WithUnaryInterceptor adds unary interceptors.

type Server

type Server struct {
	Server  *grpc.Server
	Web     *grpcweb.WrappedGrpcServer
	Gateway *runtime.ServeMux
	Health  *health.Server
	// contains filtered or unexported fields
}

Server wraps the gRPC server, gRPC-gateway and a loopback connection.

func NewServer

func NewServer(opts ...Option) *Server

NewServer instantiates a new gRPC server with the given options.

func (*Server) AddContextExtender

func (s *Server) AddContextExtender(contextExtender ...func(context.Context) context.Context)

AddContextExtender adds functions that extend request contexts.

func (*Server) AddStatsHandler

func (s *Server) AddStatsHandler(handler ...stats.Handler)

AddStatsHandler adds stats handlers.

func (*Server) AddStreamInterceptor

func (s *Server) AddStreamInterceptor(interceptor ...grpc.StreamServerInterceptor)

AddStreamInterceptor adds stream interceptors.

func (*Server) AddUnaryInterceptor

func (s *Server) AddUnaryInterceptor(interceptor ...grpc.UnaryServerInterceptor)

AddUnaryInterceptor adds unary interceptors.

func (*Server) GracefulStop

func (s *Server) GracefulStop() error

GracefulStop stops the gRPC server gracefully.

func (*Server) LoopbackConn

func (s *Server) LoopbackConn() *grpc.ClientConn

LoopbackConn returns an in-process gRPC connection to the server.

func (*Server) Serve

func (s *Server) Serve(lis net.Listener) error

Serve serves the gRPC server (but not the gRPC-gateway) on lis.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) ServeLoopback

func (s *Server) ServeLoopback() error

ServeLoopback serves the gRPC server for the in-process gRPC connection.

Jump to

Keyboard shortcuts

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