Documentation ¶
Index ¶
- Constants
- Variables
- func AnnotateContext(ctx context.Context, mux *ServeMux, req *http.Request, rpcMethodName string, ...) (context.Context, error)
- func AnnotateIncomingContext(ctx context.Context, mux *ServeMux, req *http.Request, rpcMethodName string, ...) (context.Context, error)
- func DefaultHTTPErrorHandler(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, ...)
- func DefaultHeaderMatcher(key string) (string, bool)
- func DefaultRoutingErrorHandler(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, ...)
- func DefaultStreamErrorHandler(_ context.Context, _ *http.Request, err error) (int, any)
- func DefaultWebsocketErrorHandler(ctx context.Context, marshaler Marshaler, _ *http.Request, ...)
- func HTTPPathPattern(ctx context.Context) (string, bool)
- func HTTPStatusFromCode(code codes.Code) int
- func NewServerMetadataContext(ctx context.Context, md ServerMetadata) context.Context
- func RPCMethod(ctx context.Context) (string, bool)
- type AnnotateContextOption
- type Decoder
- type DecoderFunc
- type DefaultQueryParser
- type Delimited
- type Encoder
- type EncoderFunc
- type ErrInvalidQueryParameters
- type ErrMarshal
- type ErrPathParameterInvalidEnum
- type ErrPathParameterMissing
- type ErrPathParameterTypeMismatch
- type ErrRouting
- type ErrStreamingMethodNotAllowed
- type ErrorHandlerFunc
- type ForwardResponseFunc
- type HTTPStatusError
- type HeaderMatcherFunc
- type Marshaler
- type MetadataAnnotatorFunc
- type PanicHandlerFunc
- type Params
- type ProtoMessage
- type QueryParameterParseOptions
- type QueryParameterParser
- type RoutingErrorHandlerFunc
- type SSEConfig
- type SSEErrorHandlerFunc
- type SSEMessage
- type ServeMux
- func (s *ServeMux) ForwardResponseMessage(ctx context.Context, marshaler Marshaler, writer http.ResponseWriter, ...)
- func (s *ServeMux) ForwardResponseStreamChunked(ctx context.Context, marshaler Marshaler, writer http.ResponseWriter, ...)
- func (s *ServeMux) ForwardResponseStreamSSE(ctx context.Context, marshaler Marshaler, writer http.ResponseWriter, ...)
- func (s *ServeMux) ForwardWebsocket(ctx context.Context, req *http.Request, stream grpc.ClientStream, ...)
- func (s *ServeMux) ForwardWebsocketServerStreaming(ctx context.Context, req *http.Request, stream grpc.ClientStream, ...)
- func (s *ServeMux) HTTPError(ctx context.Context, marshaler Marshaler, w http.ResponseWriter, ...)
- func (s *ServeMux) Handle(method, pattern string, handler http.Handler)
- func (s *ServeMux) HandleWithParams(method, pattern string, handler httprouter.Handle)
- func (s *ServeMux) IsSSE(req *http.Request) bool
- func (s *ServeMux) IsWebsocketUpgrade(req *http.Request) bool
- func (s *ServeMux) MarshalerForRequest(req *http.Request) (inbound, outbound Marshaler)
- func (s *ServeMux) PopulateQueryParameters(msg proto.Message, values url.Values, inputs QueryParameterParseOptions) error
- func (s *ServeMux) ServeHTTP(writer http.ResponseWriter, req *http.Request)
- func (s *ServeMux) UpgradeToWebsocket(response http.ResponseWriter, req *http.Request) (websocket.Connection, error)
- func (s *ServeMux) WebsocketError(ctx context.Context, marshaler Marshaler, r *http.Request, ...)
- type ServeMuxOption
- func WithDisablePathLengthFallback() ServeMuxOption
- func WithErrorHandler(fn ErrorHandlerFunc) ServeMuxOption
- func WithForwardResponseOption(forwardResponseOption ForwardResponseFunc) ServeMuxOption
- func WithGlobalOptionsHandler(handler http.Handler) ServeMuxOption
- func WithHealthEndpointAt(healthCheckClient grpc_health_v1.HealthClient, endpointPath string) ServeMuxOption
- func WithHealthzEndpoint(healthCheckClient grpc_health_v1.HealthClient) ServeMuxOption
- func WithIncomingHeaderMatcher(fn HeaderMatcherFunc) ServeMuxOption
- func WithMetadata(annotator MetadataAnnotatorFunc) ServeMuxOption
- func WithMethodNotAllowedHandler(handler http.Handler) ServeMuxOption
- func WithNotFoundHandler(handler http.Handler) ServeMuxOption
- func WithOutgoingHeaderMatcher(fn HeaderMatcherFunc) ServeMuxOption
- func WithPanicHandler(handler PanicHandlerFunc) ServeMuxOption
- func WithQueryParameterParser(queryParameterParser QueryParameterParser) ServeMuxOption
- func WithRoutingErrorHandler(fn RoutingErrorHandlerFunc) ServeMuxOption
- func WithSSEConfig(config SSEConfig) ServeMuxOption
- func WithSSEErrorHandler(handler SSEErrorHandlerFunc) ServeMuxOption
- func WithStreamErrorHandler(fn StreamErrorHandlerFunc) ServeMuxOption
- func WithWebsocketErrorHandler(fn WebsocketErrorHandlerFunc) ServeMuxOption
- func WithWebsocketUpgrader(upgradeFunc WebsocketUpgradeFunc) ServeMuxOption
- func WithoutHandlingOptions() ServeMuxOption
- type ServerMetadata
- type ServerTransportStream
- func (s *ServerTransportStream) Header() metadata.MD
- func (s *ServerTransportStream) Method() string
- func (s *ServerTransportStream) SendHeader(md metadata.MD) error
- func (s *ServerTransportStream) SetHeader(md metadata.MD) error
- func (s *ServerTransportStream) SetTrailer(md metadata.MD) error
- func (s *ServerTransportStream) Trailer() metadata.MD
- type StreamErrorHandlerFunc
- type WebsocketErrorHandlerFunc
- type WebsocketUpgradeFunc
Constants ¶
const MetadataHeaderPrefix = "Grpc-Metadata-"
MetadataHeaderPrefix is the http prefix that represents custom metadata parameters to or from a gRPC call.
const MetadataPrefix = "grpcgateway-"
MetadataPrefix is prepended to permanent HTTP header keys (as specified by the IANA) when added to the gRPC context.
const MetadataTrailerPrefix = "Grpc-Trailer-"
MetadataTrailerPrefix is prepended to gRPC metadata as it is converted to HTTP headers in a response handled by grpc-gateway
Variables ¶
var DefaultContextTimeout = 0 * time.Second
DefaultContextTimeout is used for gRPC call context.WithTimeout whenever a Grpc-Timeout inbound header isn't present. If the value is 0 the sent `context` will not have a timeout.
Functions ¶
func AnnotateContext ¶
func AnnotateContext(ctx context.Context, mux *ServeMux, req *http.Request, rpcMethodName string, options ...AnnotateContextOption) (context.Context, error)
AnnotateContext adds context information such as metadata from the request.
At a minimum, the RemoteAddr is included in the fashion of "X-Forwarded-For", except that the forwarded destination is not another HTTP service but rather a gRPC service.
func AnnotateIncomingContext ¶
func AnnotateIncomingContext(ctx context.Context, mux *ServeMux, req *http.Request, rpcMethodName string, options ...AnnotateContextOption) (context.Context, error)
AnnotateIncomingContext adds context information such as metadata from the request. Attach metadata as incoming context.
func DefaultHTTPErrorHandler ¶
func DefaultHTTPErrorHandler(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, r *http.Request, err error)
DefaultHTTPErrorHandler is the default error handler. If "err" is a gRPC Status, the function replies with the status code mapped by HTTPStatusFromCode. If "err" is a HTTPStatusError, the function replies with the status code provide by that struct. This is intended to allow passing through of specific statuses via the function set via WithRoutingErrorHandler for the ServeMux constructor to handle edge cases which the standard mappings in HTTPStatusFromCode are insufficient for. If otherwise, it replies with http.StatusInternalServerError.
The response body written by this function is a Status message marshaled by the Marshaler.
func DefaultHeaderMatcher ¶
DefaultHeaderMatcher is used to pass http request headers to/from gRPC context. This adds permanent HTTP header keys (as specified by the IANA, e.g: Accept, Cookie, Host) to the gRPC metadata with the grpcgateway- prefix. If you want to know which headers are considered permanent, you can view the isPermanentHTTPHeader function. HTTP headers that start with 'Grpc-Metadata-' are mapped to gRPC metadata after removing the prefix 'Grpc-Metadata-'. Other headers are not added to the gRPC metadata.
func DefaultRoutingErrorHandler ¶
func DefaultRoutingErrorHandler( ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, r *http.Request, err ErrRouting)
DefaultRoutingErrorHandler is our default handler for routing errors. By default http error codes mapped on the following error codes:
NotFound -> grpc.NotFound StatusBadRequest -> grpc.InvalidArgument MethodNotAllowed -> grpc.Unimplemented Other -> grpc.Internal, method is not expecting to be called for anything else
func HTTPPathPattern ¶
HTTPPathPattern returns the HTTP path pattern string relating to the HTTP handler, if one exists. The format of the returned string is defined by the google.api.http path template type.
func HTTPStatusFromCode ¶
HTTPStatusFromCode converts a gRPC error code into the corresponding HTTP response status. See: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
func NewServerMetadataContext ¶
func NewServerMetadataContext(ctx context.Context, md ServerMetadata) context.Context
NewServerMetadataContext creates a new context with ServerMetadata
Types ¶
type AnnotateContextOption ¶
func WithHTTPPathPattern ¶
func WithHTTPPathPattern(pattern string) AnnotateContextOption
type DecoderFunc ¶
type DecoderFunc = protomarshal.DecoderFunc
DecoderFunc adapts an decoder function into Decoder.
type DefaultQueryParser ¶
type DefaultQueryParser struct{}
DefaultQueryParser is a QueryParameterParser which implements the default query parameters parsing behavior.
func (*DefaultQueryParser) Parse ¶
func (*DefaultQueryParser) Parse(msg proto.Message, values url.Values, input QueryParameterParseOptions) error
Parse populates "values" into "msg". A value is ignored if its key starts with one of the elements in "filter".
type Encoder ¶
type Encoder = protomarshal.Encoder
Encoder encodes gRPC payloads / fields into byte sequence.
type EncoderFunc ¶
type EncoderFunc = protomarshal.EncoderFunc
EncoderFunc adapts an encoder function into Encoder
type ErrInvalidQueryParameters ¶
type ErrInvalidQueryParameters struct { // Err is the underlying parsing error. Err error }
ErrInvalidQueryParameters is the error related to parsing query params. If the query parameters are invalid, cannot be parsed or their values cannot be parsed, this error type gets used.
func (ErrInvalidQueryParameters) Error ¶
func (e ErrInvalidQueryParameters) Error() string
func (ErrInvalidQueryParameters) GRPCStatus ¶
func (e ErrInvalidQueryParameters) GRPCStatus() *status.Status
type ErrMarshal ¶
type ErrMarshal struct { // Err is the underlying marshal/unmarshal error. Err error // Inbound indicates whether or not the error is from unmarshaling an inbound request payload. // // If this value is true, it indicates that the request payload could not be unmarshaled // into the expected gRPC request type. // // If this value is false, it indicates the marshaler failed to encode response payload when // forwarding the response back to the HTTP client. Inbound bool }
ErrMarshal is the error returned by the gateway when marshal or unmarshal functions fail.
func (ErrMarshal) Error ¶
func (e ErrMarshal) Error() string
func (ErrMarshal) GRPCStatus ¶
func (e ErrMarshal) GRPCStatus() *status.Status
type ErrPathParameterInvalidEnum ¶
type ErrPathParameterInvalidEnum struct { // Err is the underlying parsing error. Err error // Name is the name of the parameter that happens to be a field path in the proto type. Name string }
ErrPathParameterInvalidEnum is the error generated when parsing values path parameters to an enum type fails.
func (ErrPathParameterInvalidEnum) Error ¶
func (e ErrPathParameterInvalidEnum) Error() string
func (ErrPathParameterInvalidEnum) GRPCStatus ¶
func (e ErrPathParameterInvalidEnum) GRPCStatus() *status.Status
type ErrPathParameterMissing ¶
type ErrPathParameterMissing struct { // Name is the name of the parameter that happens to be a field path in the proto type. Name string }
ErrPathParameterMissing is the error generated by the gateway when HTTP path parameters are missing.
func (ErrPathParameterMissing) Error ¶
func (e ErrPathParameterMissing) Error() string
func (ErrPathParameterMissing) GRPCStatus ¶
func (e ErrPathParameterMissing) GRPCStatus() *status.Status
type ErrPathParameterTypeMismatch ¶
type ErrPathParameterTypeMismatch struct { // Err is the underlying type mismatch. Err error // Name is the name of the parameter that happens to be a field path in the proto type. Name string }
ErrPathParameterTypeMismatch is the error generated by the gateway when path parameter type is unexpected.
func (ErrPathParameterTypeMismatch) Error ¶
func (e ErrPathParameterTypeMismatch) Error() string
func (ErrPathParameterTypeMismatch) GRPCStatus ¶
func (e ErrPathParameterTypeMismatch) GRPCStatus() *status.Status
type ErrRouting ¶
type ErrRouting uint8
ErrRouting is an error type specific to routing errors such as not found and method not allowed.
const ( // ErrRoutingMethodNotAllowed is for routes that exist but with a different HTTP method. ErrRoutingMethodNotAllowed ErrRouting = iota // ErrRoutingNotFound is for routes that are not handled by the serve mux. ErrRoutingNotFound )
func (ErrRouting) Error ¶
func (r ErrRouting) Error() string
func (ErrRouting) GRPCStatus ¶
func (r ErrRouting) GRPCStatus() *status.Status
type ErrStreamingMethodNotAllowed ¶
type ErrStreamingMethodNotAllowed struct { // MethodSupportsWebsocket indicates whether or not the server accepts websocket for this method. MethodSupportsWebsocket bool // MethodSupportsSSE indicates whether or not the server accepts SSE for this method. MethodSupportsSSE bool // MethodSupportsChunkedTransfer indicates whether or not the server accepts chunked transfer streaming. MethodSupportsChunkedTransfer bool }
ErrStreamingMethodNotAllowed is the error related to when a server receives a request that does not use any of the available streaming methods.
func (ErrStreamingMethodNotAllowed) Error ¶
func (e ErrStreamingMethodNotAllowed) Error() string
func (ErrStreamingMethodNotAllowed) GRPCStatus ¶
func (e ErrStreamingMethodNotAllowed) GRPCStatus() *status.Status
type ErrorHandlerFunc ¶
type ErrorHandlerFunc func(context.Context, *ServeMux, Marshaler, http.ResponseWriter, *http.Request, error)
ErrorHandlerFunc is the signature used to configure error handling.
type ForwardResponseFunc ¶
ForwardResponseFunc updates the outgoing gRPC request and the HTTP response.
type HTTPStatusError ¶
HTTPStatusError is the error to use when needing to provide a different HTTP status code for an error passed to the DefaultRoutingErrorHandler.
func (HTTPStatusError) Error ¶
func (e HTTPStatusError) Error() string
type HeaderMatcherFunc ¶
HeaderMatcherFunc checks whether a header key should be forwarded to/from gRPC context.
type Marshaler ¶
type Marshaler = protomarshal.Marshaler
Marshaler defines a conversion between byte sequence and gRPC payloads / fields.
type MetadataAnnotatorFunc ¶
MetadataAnnotatorFunc updates the outgoing gRPC request context based on the incoming HTTP request.
type PanicHandlerFunc ¶
type PanicHandlerFunc func(http.ResponseWriter, *http.Request, interface{})
PanicHandlerFunc is a function that gets called when a panic is encountered.
type Params ¶
type Params = httprouter.Params
type ProtoMessage ¶
type QueryParameterParseOptions ¶
type QueryParameterParseOptions struct { // Filter holds a trie that can block already bound or otherwise ignored query paramters. Filter *trie.Node // Aliases is a table of arbitrary names mapped to field keys. Aliases map[string]string // LimitToAliases limits the query parameters to aliases only. Used when auto discovery is disabled. LimitToAliases bool }
QueryParameterParseOptions hold all inputs for parsing query parameters.
type QueryParameterParser ¶
type QueryParameterParser interface {
Parse(msg proto.Message, values url.Values, inputs QueryParameterParseOptions) error
}
QueryParameterParser defines interface for all query parameter parsers.
type RoutingErrorHandlerFunc ¶
type RoutingErrorHandlerFunc func(context.Context, *ServeMux, Marshaler, http.ResponseWriter, *http.Request, ErrRouting)
RoutingErrorHandlerFunc is the signature used to configure error handling for routing errors.
type SSEConfig ¶
type SSEConfig struct { // EndOfStreamMessage is the last message send when the gRPC client streaming finishes. EndOfStreamMessage *SSEMessage }
SSEConfig configures the behavior of the Server-Sent Events (SSE).
type SSEErrorHandlerFunc ¶
SSEErrorHandlerFunc is the signature used to configure SSE error handling.
This function should return desired SSE message for the error response. If the returned message is nil, no response is sent.
type SSEMessage ¶
type SSEMessage struct { // ID is the event ID (optional). ID string // Event is the event portion of the SSE message (optional). Event string // Data is the event data. // Must be UTF-8 encoded. Data []byte }
SSEMessage describes a single Server-Sent Events (SSE) message.
func DefaultSSEErrorHandler ¶
type ServeMux ¶
type ServeMux struct {
// contains filtered or unexported fields
}
ServeMux is a request multiplexer for grpc-gateway. It matches http requests to patterns and invokes the corresponding handler.
func NewServeMux ¶
func NewServeMux(opts ...ServeMuxOption) *ServeMux
NewServeMux returns a new ServeMux whose internal mapping is empty.
func (*ServeMux) ForwardResponseMessage ¶
func (*ServeMux) ForwardResponseStreamChunked ¶
func (s *ServeMux) ForwardResponseStreamChunked( ctx context.Context, marshaler Marshaler, writer http.ResponseWriter, req *http.Request, recv func() (proto.Message, error))
ForwardResponseStreamChunked forwards the stream from gRPC server to REST client using Transfer-Encoding chunked.
func (*ServeMux) ForwardResponseStreamSSE ¶
func (s *ServeMux) ForwardResponseStreamSSE( ctx context.Context, marshaler Marshaler, writer http.ResponseWriter, req *http.Request, recv func() (proto.Message, error))
ForwardResponseStreamSSE forwards the stream from gRPC server to REST client using Server-Sent Events (SSE).
func (*ServeMux) ForwardWebsocket ¶
func (s *ServeMux) ForwardWebsocket( ctx context.Context, req *http.Request, stream grpc.ClientStream, ws websocket.Connection, inboundMarshaler, outboundMarshaler Marshaler, protoReq, protoRes ProtoMessage)
func (*ServeMux) ForwardWebsocketServerStreaming ¶
func (s *ServeMux) ForwardWebsocketServerStreaming( ctx context.Context, req *http.Request, stream grpc.ClientStream, ws websocket.Connection, outboundMarshaler Marshaler, protoRes ProtoMessage)
func (*ServeMux) HTTPError ¶
func (s *ServeMux) HTTPError( ctx context.Context, marshaler Marshaler, w http.ResponseWriter, r *http.Request, err error)
HTTPError uses the mux-configured error handler.
func (*ServeMux) HandleWithParams ¶
func (s *ServeMux) HandleWithParams(method, pattern string, handler httprouter.Handle)
HandleWithParams registers a new handler for the method and pattern specified.
NOTE: this method takes an httprouter.Handle function, helpful when path parameters are needed. if using http.Handler is desired, use Handle instead.
func (*ServeMux) IsWebsocketUpgrade ¶
IsWebsocketUpgrade returns whether or not the client is requesting for connection upgrade to websocket and server is capable of upgrading. If websocket upgrade function is not setup, this method returns false.
func (*ServeMux) MarshalerForRequest ¶
MarshalerForRequest returns the inbound/outbound marshalers for this request. It checks the registry on the ServeMux for the MIME type set by the Content-Type header. If it isn't set (or the request Content-Type is empty), checks for "*". If there are multiple Content-Type headers set, choose the first one that it can exactly match in the registry. Otherwise, it follows the above logic for "*"/InboundMarshaler/OutboundMarshaler.
func (*ServeMux) PopulateQueryParameters ¶
func (s *ServeMux) PopulateQueryParameters(msg proto.Message, values url.Values, inputs QueryParameterParseOptions) error
PopulateQueryParameters parses query parameters into "msg" using current query parser.
func (*ServeMux) ServeHTTP ¶
func (s *ServeMux) ServeHTTP(writer http.ResponseWriter, req *http.Request)
ServeHTTP dispatches the request to the first handler whose pattern matches to r.Method and r.URL.Path.
func (*ServeMux) UpgradeToWebsocket ¶
func (s *ServeMux) UpgradeToWebsocket(response http.ResponseWriter, req *http.Request) (websocket.Connection, error)
UpgradeToWebsocket upgrades an HTTP request to a websocket connection.
type ServeMuxOption ¶
type ServeMuxOption interface {
// contains filtered or unexported methods
}
ServeMuxOption is an option that can be given to a ServeMux on construction.
func WithDisablePathLengthFallback ¶
func WithDisablePathLengthFallback() ServeMuxOption
WithDisablePathLengthFallback returns a ServeMuxOption for disable path length fallback.
func WithErrorHandler ¶
func WithErrorHandler(fn ErrorHandlerFunc) ServeMuxOption
WithErrorHandler returns a ServeMuxOption for configuring a custom error handler.
This can be used to configure a custom error response.
func WithForwardResponseOption ¶
func WithForwardResponseOption(forwardResponseOption ForwardResponseFunc) ServeMuxOption
WithForwardResponseOption returns a ServeMuxOption representing the forwardResponseOption.
forwardResponseOption is an option that will be called on the relevant context.Context, http.ResponseWriter, and proto.Message before every forwarded response.
The message may be nil in the case where just a header is being sent.
func WithGlobalOptionsHandler ¶
func WithGlobalOptionsHandler(handler http.Handler) ServeMuxOption
WithGlobalOptionsHandler sets an optional handler that is called on automatic OPTIONS requests. The handler is only called if handling OPTIONS is enabled and no OPTIONS handler for the specific path is set. The "Allowed" header is set before calling the handler.
func WithHealthEndpointAt ¶
func WithHealthEndpointAt(healthCheckClient grpc_health_v1.HealthClient, endpointPath string) ServeMuxOption
WithHealthEndpointAt returns a ServeMuxOption that will add an endpoint to the created ServeMux at the path specified by endpointPath. When called the handler will forward the request to the upstream grpc service health check (defined in the gRPC Health Checking Protocol).
If you define a service as query parameter, this will also be forwarded as service in the HealthCheckRequest.
func WithHealthzEndpoint ¶
func WithHealthzEndpoint(healthCheckClient grpc_health_v1.HealthClient) ServeMuxOption
WithHealthzEndpoint returns a ServeMuxOption that will add a /healthz endpoint to the created ServeMux.
See WithHealthEndpointAt for the general implementation.
func WithIncomingHeaderMatcher ¶
func WithIncomingHeaderMatcher(fn HeaderMatcherFunc) ServeMuxOption
WithIncomingHeaderMatcher returns a ServeMuxOption representing a headerMatcher for incoming request to gateway.
This matcher will be called with each header in http.Request. If matcher returns true, that header will be passed to gRPC context. To transform the header before passing to gRPC context, matcher should return modified header.
func WithMetadata ¶
func WithMetadata(annotator MetadataAnnotatorFunc) ServeMuxOption
WithMetadata returns a ServeMuxOption for passing metadata to a gRPC context.
This can be used by services that need to read from http.Request and modify gRPC context. A common use case is reading token from cookie and adding it in gRPC context.
func WithMethodNotAllowedHandler ¶
func WithMethodNotAllowedHandler(handler http.Handler) ServeMuxOption
WithMethodNotAllowedHandler sets a configurable http.Handler which is called when a request cannot be routed and HandleMethodNotAllowed is true. If it is not set, http.Error with http.StatusMethodNotAllowed is used. The "Allow" header with allowed request methods is set before the handler is called.
func WithNotFoundHandler ¶
func WithNotFoundHandler(handler http.Handler) ServeMuxOption
WithNotFoundHandler sets a configurable http.Handler which is called when no matching route is found. If it is not set, http.NotFound is used.
func WithOutgoingHeaderMatcher ¶
func WithOutgoingHeaderMatcher(fn HeaderMatcherFunc) ServeMuxOption
WithOutgoingHeaderMatcher returns a ServeMuxOption representing a headerMatcher for outgoing response from gateway.
This matcher will be called with each header in response header metadata. If matcher returns true, that header will be passed to http response returned from gateway. To transform the header before passing to response, matcher should return modified header.
func WithPanicHandler ¶
func WithPanicHandler(handler PanicHandlerFunc) ServeMuxOption
WithPanicHandler sets the function to handle panics recovered from http handlers. It should be used to generate a error page and return the http error code 500 (Internal Server Error). The handler can be used to keep your server from crashing because of unrecovered panics.
func WithQueryParameterParser ¶
func WithQueryParameterParser(queryParameterParser QueryParameterParser) ServeMuxOption
WithQueryParameterParser sets the query parameter parser, used to populate message from query parameters. Configuring this will mean the generated OpenAPI output is no longer correct, and it should be done with careful consideration.
func WithRoutingErrorHandler ¶
func WithRoutingErrorHandler(fn RoutingErrorHandlerFunc) ServeMuxOption
WithRoutingErrorHandler returns a ServeMuxOption for configuring a custom error handler to handle http routing errors.
Method called for errors which can happen before gRPC route selected or executed. The following error codes: StatusMethodNotAllowed StatusNotFound StatusBadRequest
func WithSSEConfig ¶
func WithSSEConfig(config SSEConfig) ServeMuxOption
WithSSEConfig sets Server-Sent Events (SSE) configuration.
func WithSSEErrorHandler ¶
func WithSSEErrorHandler(handler SSEErrorHandlerFunc) ServeMuxOption
WithSSEErrorHandler returns a ServeMuxOption for configuring an SSE error handler.
This can be used to configure a custom error response.
func WithStreamErrorHandler ¶
func WithStreamErrorHandler(fn StreamErrorHandlerFunc) ServeMuxOption
WithStreamErrorHandler returns a ServeMuxOption that will use the given custom stream error handler, which allows for customizing the error trailer for server-streaming calls.
For stream errors that occur before any response has been written, the mux's ErrorHandler will be invoked. However, once data has been written, the errors must be handled differently: they must be included in the response body. The response body's final message will include the error details returned by the stream error handler.
func WithWebsocketErrorHandler ¶
func WithWebsocketErrorHandler(fn WebsocketErrorHandlerFunc) ServeMuxOption
WithWebsocketErrorHandler returns a ServeMuxOption for configuring a websocket error handler.
This can be used to configure a custom error response.
func WithWebsocketUpgrader ¶
func WithWebsocketUpgrader(upgradeFunc WebsocketUpgradeFunc) ServeMuxOption
WithWebsocketUpgrader enables websocket upgrades for the serve mux.
func WithoutHandlingOptions ¶
func WithoutHandlingOptions() ServeMuxOption
WithoutHandlingOptions disabled automatically handling OPTIONS for available endpoints, which is by default enabled.
type ServerMetadata ¶
ServerMetadata consists of metadata sent from gRPC server.
func ServerMetadataFromContext ¶
func ServerMetadataFromContext(ctx context.Context) (md ServerMetadata, ok bool)
ServerMetadataFromContext returns the ServerMetadata in ctx
type ServerTransportStream ¶
type ServerTransportStream struct {
// contains filtered or unexported fields
}
ServerTransportStream implements grpc.ServerTransportStream. It should only be used by the generated files to support grpc.SendHeader outside of gRPC server use.
func (*ServerTransportStream) Header ¶
func (s *ServerTransportStream) Header() metadata.MD
Header returns the header metadata of the stream.
func (*ServerTransportStream) Method ¶
func (s *ServerTransportStream) Method() string
Method returns the method for the stream.
func (*ServerTransportStream) SendHeader ¶
func (s *ServerTransportStream) SendHeader(md metadata.MD) error
SendHeader sets the header metadata.
func (*ServerTransportStream) SetHeader ¶
func (s *ServerTransportStream) SetHeader(md metadata.MD) error
SetHeader sets the header metadata.
func (*ServerTransportStream) SetTrailer ¶
func (s *ServerTransportStream) SetTrailer(md metadata.MD) error
SetTrailer sets the trailer metadata.
func (*ServerTransportStream) Trailer ¶
func (s *ServerTransportStream) Trailer() metadata.MD
Trailer returns the cached trailer metadata.
type StreamErrorHandlerFunc ¶
StreamErrorHandlerFunc is the signature used to configure stream error handling.
This function should return desired HTTP status code for the response and any object. The status would be used only if status has not already been written. The data is flexible format and will be unmarshaled using the marshaler for the request. If the returning data is nil, no data will be written.
This is used for chunked transfer only.
type WebsocketErrorHandlerFunc ¶
type WebsocketErrorHandlerFunc func(context.Context, Marshaler, *http.Request, websocket.Connection, error)
WebsocketErrorHandlerFunc is the signature used to configure websocket error handling.
This function should return desired error message that will get marshaled and sent back to the client before closing the connection.
If the returned data is nil, no message is sent back before closing the connection.
type WebsocketUpgradeFunc ¶
type WebsocketUpgradeFunc func(http.ResponseWriter, *http.Request) (websocket.Connection, error)
WebsocketUpgradeFunc handles a protocol upgrade and creates a websocket connection.