grpcutil

package
v0.3.0-nightly.20220823 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// HTTPEndpointHeader is added internally by the GRPC Gateway to signal the
	// GRPC handler the request was actually received by an HTTP endpoint.
	HTTPEndpointHeader = "x-http-endpoint"

	// RequestIDHeader contains a value that uniquely identifies a request.
	RequestIDHeader = "x-request-id"
)

Variables

This section is empty.

Functions

func HeaderMatcher

func HeaderMatcher(key string) (string, bool)

func LoggerUnaryServerInterceptor

func LoggerUnaryServerInterceptor(logger log.CtxLogger) grpc.UnaryServerInterceptor

LoggerUnaryServerInterceptor logs all GRPC requests when they are returned. It logs the duration, grpc method and grpc status code. If the request originated from the GRPC gateway (HTTP request) the HTTP endpoint is logged as well, assuming the GRPC gateway has the WithHTTPEndpointHeader middleware.

func RequestIDUnaryServerInterceptor

func RequestIDUnaryServerInterceptor(logger log.CtxLogger) grpc.UnaryServerInterceptor

RequestIDUnaryServerInterceptor tries to fetch the request ID from metadata and generates a new request ID if not found. It also adds the request ID to the response metadata.

func WithDefaultGatewayMiddleware

func WithDefaultGatewayMiddleware(logger log.CtxLogger, h http.Handler) http.Handler

WithDefaultGatewayMiddleware wraps the handler with the default GRPC Gateway middleware.

func WithErrorHandler

func WithErrorHandler(logger log.CtxLogger) runtime.ServeMuxOption

WithErrorHandler makes sure that we log any requests that errored out and add a request ID to the response.

func WithHTTPEndpointHeader

func WithHTTPEndpointHeader(h http.Handler) http.Handler

func WithPrettyJSONHeader

func WithPrettyJSONHeader(h http.Handler) http.Handler

func WithPrettyJSONMarshaler

func WithPrettyJSONMarshaler() runtime.ServeMuxOption

WithPrettyJSONMarshaler returns a GRPC gateway ServeMuxOption which prints a pretty JSON output when Accept header contains application/json+pretty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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