Documentation ¶
Overview ¶
Package grpcutil implements various utilities around managing gRPC services.
Index ¶
- func HandlerFunc(grpcServer *grpc.Server, otherwise http.Handler) http.Handler
- func IsGRPCRequest(r *http.Request) bool
- func NewGateway(addr string, tlsConfig *tls.Config, funcs []RegisterServiceHandlerFunc) (http.Handler, *grpc.ClientConn, error)
- func NewServer(tlsConfig *tls.Config, fn RegisterServicesFunc) *grpc.Server
- type MuxedGRPCServer
- type RegisterServiceHandlerFunc
- type RegisterServicesFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandlerFunc ¶
HandlerFunc returns an http.Handler that delegates to grpc.Server on incoming gRPC connections otherwise serves with the provided handler.
func IsGRPCRequest ¶
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.
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 ¶
RegisterServiceHandlerFunc is a function that registers ServiceHandlers with a ServeMux.
type RegisterServicesFunc ¶
RegisterServicesFunc is a function that registers gRPC services with a given server.