grpcutil

package
v3.0.0-pre1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package grpcutil implements various utilities around managing gRPC services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandlerFunc

func HandlerFunc(grpcServer *grpc.Server, otherwise http.Handler) http.Handler

HandlerFunc returns an http.Handler that delegates to grpc.Server on incoming gRPC connections otherwise serves with the provided handler.

func IsGRPCRequest

func IsGRPCRequest(r *http.Request) bool

IsGRPCRequest returns true if the provided request came from a gRPC client.

Its logic is a partial recreation of gRPC's internal checks, see: https://github.com/grpc/grpc-go/blob/01de3de/transport/handler_server.go#L61:L69

func NewGateway

func NewGateway(addr string, tlsConfig *tls.Config, funcs []RegisterServiceHandlerFunc) (http.Handler, *grpc.ClientConn, error)

NewGateway creates a new http.Handler and grpc.ClientConn with the provided gRPC Services registered.

func NewServer

func NewServer(tlsConfig *tls.Config, fn RegisterServicesFunc) *grpc.Server

NewServer allocates a new grpc.Server and handles some some boilerplate configuration.

Types

type MuxedGRPCServer

type MuxedGRPCServer struct {
	Addr                string
	TLSConfig           *tls.Config
	ServicesFunc        RegisterServicesFunc
	ServiceHandlerFuncs []RegisterServiceHandlerFunc
}

MuxedGRPCServer defines the parameters for running a gRPC Server alongside a Gateway server on the same port.

func (*MuxedGRPCServer) ListenAndServe

func (srv *MuxedGRPCServer) ListenAndServe(mw httputil.Middleware) error

ListenAndServe listens on the TCP network address srv.Addr and handles both gRPC and JSON requests over HTTP. An optional HTTP middleware can be provided to wrap the output of each request.

Internally, it muxes the Listener based on whether the request is gRPC or HTTP and runs multiple servers.

func (*MuxedGRPCServer) ListenAndServeTLS

func (srv *MuxedGRPCServer) ListenAndServeTLS(certFile, keyFile, caPath string, mw httputil.Middleware) error

ListenAndServeTLS listens on the TCP network address srv.Addr and handles both gRPC and JSON requests over HTTP over TLS. An optional HTTP middleware can be provided to wrap the output of each request.

Internally, the same net.Listener is used because the http.Handler will pivot based on whether the request is gRPC or HTTP.

type RegisterServiceHandlerFunc

type RegisterServiceHandlerFunc func(context.Context, *runtime.ServeMux, *grpc.ClientConn) error

RegisterServiceHandlerFunc is a function that registers ServiceHandlers with a ServeMux.

type RegisterServicesFunc

type RegisterServicesFunc func(*grpc.Server)

RegisterServicesFunc is a function that registers gRPC services with a given server.

Jump to

Keyboard shortcuts

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