Documentation ¶
Overview ¶
Package runtime contains runtime helper functions used by servers which protoc-gen-grpc-gateway generates.
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 Bool(val string) (bool, error)
- func BoolP(val string) (*bool, error)
- func BoolSlice(val, sep string) ([]bool, error)
- func BoolValue(val string) (*wrapperspb.BoolValue, error)
- func Bytes(val string) ([]byte, error)
- func BytesSlice(val, sep string) ([][]byte, error)
- func BytesValue(val string) (*wrapperspb.BytesValue, 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, err error) *status.Status
- func DoubleValue(val string) (*wrapperspb.DoubleValue, error)
- func Duration(val string) (*durationpb.Duration, error)
- func Enum(val string, enumValMap map[string]int32) (int32, error)
- func EnumSlice(val, sep string, enumValMap map[string]int32) ([]int32, error)
- func FieldMaskFromRequestBody(r io.Reader, msg proto.Message) (*field_mask.FieldMask, error)
- func Float32(val string) (float32, error)
- func Float32P(val string) (*float32, error)
- func Float32Slice(val, sep string) ([]float32, error)
- func Float64(val string) (float64, error)
- func Float64P(val string) (*float64, error)
- func Float64Slice(val, sep string) ([]float64, error)
- func FloatValue(val string) (*wrapperspb.FloatValue, error)
- func ForwardResponseMessage(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, ...)
- func ForwardResponseStream(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, ...)
- func HTTPError(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, ...)
- func HTTPPathPattern(ctx context.Context) (string, bool)
- func HTTPStatusFromCode(code codes.Code) int
- func Int32(val string) (int32, error)
- func Int32P(val string) (*int32, error)
- func Int32Slice(val, sep string) ([]int32, error)
- func Int32Value(val string) (*wrapperspb.Int32Value, error)
- func Int64(val string) (int64, error)
- func Int64P(val string) (*int64, error)
- func Int64Slice(val, sep string) ([]int64, error)
- func Int64Value(val string) (*wrapperspb.Int64Value, error)
- func MarshalerForRequest(mux *ServeMux, r *http.Request) (inbound Marshaler, outbound Marshaler)
- func NewServerMetadataContext(ctx context.Context, md ServerMetadata) context.Context
- func PopulateFieldFromPath(msg proto.Message, fieldPathString string, value string) error
- func PopulateQueryParameters(msg proto.Message, values url.Values, filter *utilities.DoubleArray) error
- func RPCMethod(ctx context.Context) (string, bool)
- func String(val string) (string, error)
- func StringP(val string) (*string, error)
- func StringSlice(val, sep string) ([]string, error)
- func StringValue(val string) (*wrapperspb.StringValue, error)
- func Timestamp(val string) (*timestamppb.Timestamp, error)
- func UInt32Value(val string) (*wrapperspb.UInt32Value, error)
- func UInt64Value(val string) (*wrapperspb.UInt64Value, error)
- func Uint32(val string) (uint32, error)
- func Uint32P(val string) (*uint32, error)
- func Uint32Slice(val, sep string) ([]uint32, error)
- func Uint64(val string) (uint64, error)
- func Uint64P(val string) (*uint64, error)
- func Uint64Slice(val, sep string) ([]uint64, error)
- type AnnotateContextOption
- type Decoder
- type DecoderFunc
- type DecoderWrapper
- type DefaultQueryParser
- type Delimited
- type Encoder
- type EncoderFunc
- type ErrorHandlerFunc
- type HTTPBodyMarshaler
- type HTTPStatusError
- type HandlerFunc
- type HeaderMatcherFunc
- type JSONBuiltin
- func (*JSONBuiltin) ContentType(_ interface{}) string
- func (j *JSONBuiltin) Delimiter() []byte
- func (j *JSONBuiltin) Marshal(v interface{}) ([]byte, error)
- func (j *JSONBuiltin) NewDecoder(r io.Reader) Decoder
- func (j *JSONBuiltin) NewEncoder(w io.Writer) Encoder
- func (j *JSONBuiltin) Unmarshal(data []byte, v interface{}) error
- type JSONPb
- func (*JSONPb) ContentType(_ interface{}) string
- func (j *JSONPb) Delimiter() []byte
- func (j *JSONPb) Marshal(ctx context.Context, v interface{}) ([]byte, error)
- func (j *JSONPb) NewDecoder(r io.Reader) Decoder
- func (j *JSONPb) NewEncoder(w io.Writer) Encoder
- func (j *JSONPb) Unmarshal(ctx context.Context, data []byte, v interface{}) error
- type MalformedSequenceError
- type Marshaler
- type Pattern
- type ProtoMarshaller
- func (*ProtoMarshaller) ContentType(_ interface{}) string
- func (*ProtoMarshaller) Marshal(_ context.Context, value interface{}) ([]byte, error)
- func (marshaller *ProtoMarshaller) NewDecoder(reader io.Reader) Decoder
- func (marshaller *ProtoMarshaller) NewEncoder(writer io.Writer) Encoder
- func (*ProtoMarshaller) Unmarshal(_ context.Context, data []byte, value interface{}) error
- type QueryParameterParser
- type RoutingErrorHandlerFunc
- type ServeMux
- func (s *ServeMux) GetForwardResponseOptions() []func(context.Context, http.ResponseWriter, proto.Message) error
- func (s *ServeMux) Handle(meth string, pat Pattern, h HandlerFunc)
- func (s *ServeMux) HandlePath(meth string, pathPattern string, h HandlerFunc) error
- func (s *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type ServeMuxOption
- func SetQueryParameterParser(queryParameterParser QueryParameterParser) ServeMuxOption
- func WithDisablePathLengthFallback() ServeMuxOption
- func WithErrorHandler(fn ErrorHandlerFunc) ServeMuxOption
- func WithForwardResponseOption(...) 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 WithMarshalerOption(mime string, marshaler Marshaler) ServeMuxOption
- func WithMetadata(annotator func(context.Context, *http.Request) metadata.MD) ServeMuxOption
- func WithOutgoingHeaderMatcher(fn HeaderMatcherFunc) ServeMuxOption
- func WithRoutingErrorHandler(fn RoutingErrorHandlerFunc) ServeMuxOption
- func WithStreamErrorHandler(fn StreamErrorHandlerFunc) ServeMuxOption
- func WithUnescapingMode(mode UnescapingMode) 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 UnescapingMode
Constants ¶
const MIMEWildcard = "*"
MIMEWildcard is the fallback MIME type used for requests which do not match a registered MIME type.
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 ( // ErrNotMatch indicates that the given HTTP request path does not match to the pattern. ErrNotMatch = errors.New("not match to the path pattern") // ErrInvalidPattern indicates that the given definition of Pattern is not valid. ErrInvalidPattern = errors.New("invalid pattern") // ErrMalformedSequence indicates that an escape sequence was malformed. ErrMalformedSequence = errors.New("malformed escape sequence") )
var ( // 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. DefaultContextTimeout = 0 * time.Second )
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 BoolP ¶
BoolP parses the given string representation of a boolean value, and returns a pointer to a bool whose value is same as the parsed value.
func BoolSlice ¶
BoolSlice converts 'val' where individual booleans are separated by 'sep' into a bool slice.
func BoolValue ¶
func BoolValue(val string) (*wrapperspb.BoolValue, error)
BoolValue well-known type support as wrapper around bool type
func Bytes ¶
Bytes converts the given string representation of a byte sequence into a slice of bytes A bytes sequence is encoded in URL-safe base64 without padding
func BytesSlice ¶
BytesSlice converts 'val' where individual bytes sequences, encoded in URL-safe base64 without padding, are separated by 'sep' into a slice of bytes slices slice.
func BytesValue ¶
func BytesValue(val string) (*wrapperspb.BytesValue, error)
BytesValue well-known type support as wrapper around bytes[] type
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) to gRPC context with grpcgateway- prefix. HTTP headers that start with 'Grpc-Metadata-' are mapped to gRPC metadata after removing prefix 'Grpc-Metadata-'.
func DefaultRoutingErrorHandler ¶
func DefaultRoutingErrorHandler(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, r *http.Request, httpStatus int)
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 DoubleValue ¶
func DoubleValue(val string) (*wrapperspb.DoubleValue, error)
DoubleValue well-known type support as wrapper around float64 type
func Duration ¶
func Duration(val string) (*durationpb.Duration, error)
Duration converts the given string into a timestamp.Duration.
func Enum ¶
Enum converts the given string into an int32 that should be type casted into the correct enum proto type.
func EnumSlice ¶
EnumSlice converts 'val' where individual enums are separated by 'sep' into a int32 slice. Each individual int32 should be type casted into the correct enum proto type.
func FieldMaskFromRequestBody ¶
FieldMaskFromRequestBody creates a FieldMask printing all complete paths from the JSON body.
func Float32 ¶
Float32 converts the given string representation of a floating point number into float32.
func Float32P ¶
Float32P parses the given string representation of a floating point number, and returns a pointer to a float32 whose value is same as the parsed number.
func Float32Slice ¶
Float32Slice converts 'val' where individual floating point numbers are separated by 'sep' into a float32 slice.
func Float64 ¶
Float64 converts the given string representation into representation of a floating point number into float64.
func Float64P ¶
Float64P parses the given string representation of a floating point number, and returns a pointer to a float64 whose value is same as the parsed number.
func Float64Slice ¶
Float64Slice converts 'val' where individual floating point numbers are separated by 'sep' into a float64 slice.
func FloatValue ¶
func FloatValue(val string) (*wrapperspb.FloatValue, error)
FloatValue well-known type support as wrapper around float32 type
func ForwardResponseMessage ¶
func ForwardResponseMessage(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, req *http.Request, resp proto.Message, opts ...func(context.Context, http.ResponseWriter, proto.Message) error)
ForwardResponseMessage forwards the message "resp" from gRPC server to REST client.
func ForwardResponseStream ¶
func ForwardResponseStream(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, req *http.Request, recv func() (proto.Message, error), opts ...func(context.Context, http.ResponseWriter, proto.Message) error)
ForwardResponseStream forwards the stream from gRPC server to REST client.
func HTTPError ¶
func HTTPError(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, r *http.Request, err error)
HTTPError uses the mux-configured error handler.
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 Int32P ¶
Int32P parses the given string representation of an integer and returns a pointer to a int32 whose value is same as the parsed integer.
func Int32Slice ¶
Int32Slice converts 'val' where individual integers are separated by 'sep' into a int32 slice.
func Int32Value ¶
func Int32Value(val string) (*wrapperspb.Int32Value, error)
Int32Value well-known type support as wrapper around int32 type
func Int64P ¶
Int64P parses the given string representation of an integer and returns a pointer to a int64 whose value is same as the parsed integer.
func Int64Slice ¶
Int64Slice converts 'val' where individual integers are separated by 'sep' into a int64 slice.
func Int64Value ¶
func Int64Value(val string) (*wrapperspb.Int64Value, error)
Int64Value well-known type support as wrapper around int64 type
func 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 NewServerMetadataContext ¶
func NewServerMetadataContext(ctx context.Context, md ServerMetadata) context.Context
NewServerMetadataContext creates a new context with ServerMetadata
func PopulateFieldFromPath ¶
PopulateFieldFromPath sets a value in a nested Protobuf structure.
func PopulateQueryParameters ¶
func PopulateQueryParameters(msg proto.Message, values url.Values, filter *utilities.DoubleArray) error
PopulateQueryParameters parses query parameters into "msg" using current query parser
func RPCMethod ¶
RPCMethod returns the method string for the server context. The returned string is in the format of "/package.service/method".
func StringP ¶
StringP returns a pointer to a string whose pointee is same as the given string value.
func StringSlice ¶
StringSlice converts 'val' where individual strings are separated by 'sep' into a string slice.
func StringValue ¶
func StringValue(val string) (*wrapperspb.StringValue, error)
StringValue well-known type support as wrapper around string type
func Timestamp ¶
func Timestamp(val string) (*timestamppb.Timestamp, error)
Timestamp converts the given RFC3339 formatted string into a timestamp.Timestamp.
func UInt32Value ¶
func UInt32Value(val string) (*wrapperspb.UInt32Value, error)
UInt32Value well-known type support as wrapper around uint32 type
func UInt64Value ¶
func UInt64Value(val string) (*wrapperspb.UInt64Value, error)
UInt64Value well-known type support as wrapper around uint64 type
func Uint32P ¶
Uint32P parses the given string representation of an integer and returns a pointer to a uint32 whose value is same as the parsed integer.
func Uint32Slice ¶
Uint32Slice converts 'val' where individual integers are separated by 'sep' into a uint32 slice.
func Uint64P ¶
Uint64P parses the given string representation of an integer and returns a pointer to a uint64 whose value is same as the parsed integer.
func Uint64Slice ¶
Uint64Slice converts 'val' where individual integers are separated by 'sep' into a uint64 slice.
Types ¶
type AnnotateContextOption ¶
func WithHTTPPathPattern ¶
func WithHTTPPathPattern(pattern string) AnnotateContextOption
type DecoderFunc ¶
DecoderFunc adapts an decoder function into Decoder.
type DecoderWrapper ¶
type DecoderWrapper struct { *json.Decoder protojson.UnmarshalOptions }
DecoderWrapper is a wrapper around a *json.Decoder that adds support for protos to the Decode method.
type DefaultQueryParser ¶
type DefaultQueryParser struct{}
DefaultQueryParser is a QueryParameterParser which implements the default query parameters parsing behavior.
See https://github.com/monime-lab/grpc-gateway/issues/2632 for more context.
func (*DefaultQueryParser) Parse ¶
func (*DefaultQueryParser) Parse(msg proto.Message, values url.Values, filter *utilities.DoubleArray) error
Parse populates "values" into "msg". A value is ignored if its key starts with one of the elements in "filter".
type Delimited ¶
type Delimited interface { // Delimiter returns the record separator for the stream. Delimiter() []byte }
Delimited defines the streaming delimiter.
type EncoderFunc ¶
EncoderFunc adapts an encoder function into Encoder
type ErrorHandlerFunc ¶
type ErrorHandlerFunc func(context.Context, *ServeMux, Marshaler, http.ResponseWriter, *http.Request, error)
ErrorHandlerFunc is the signature used to configure error handling.
type HTTPBodyMarshaler ¶
type HTTPBodyMarshaler struct {
Marshaler
}
HTTPBodyMarshaler is a Marshaler which supports marshaling of a google.api.HttpBody message as the full response body if it is the actual message used as the response. If not, then this will simply fallback to the Marshaler specified as its default Marshaler.
func (*HTTPBodyMarshaler) ContentType ¶
func (h *HTTPBodyMarshaler) ContentType(v interface{}) string
ContentType returns its specified content type in case v is a google.api.HttpBody message, otherwise it will fall back to the default Marshalers content type.
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 HandlerFunc ¶
A HandlerFunc handles a specific pair of path pattern and HTTP method.
type HeaderMatcherFunc ¶
HeaderMatcherFunc checks whether a header key should be forwarded to/from gRPC context.
type JSONBuiltin ¶
type JSONBuiltin struct{}
JSONBuiltin is a Marshaler which marshals/unmarshals into/from JSON with the standard "encoding/json" package of Golang. Although it is generally faster for simple proto messages than JSONPb, it does not support advanced features of protobuf, e.g. map, oneof, ....
The NewEncoder and NewDecoder types return *json.Encoder and *json.Decoder respectively.
func (*JSONBuiltin) ContentType ¶
func (*JSONBuiltin) ContentType(_ interface{}) string
ContentType always Returns "application/json".
func (*JSONBuiltin) Delimiter ¶
func (j *JSONBuiltin) Delimiter() []byte
Delimiter for newline encoded JSON streams.
func (*JSONBuiltin) Marshal ¶
func (j *JSONBuiltin) Marshal(v interface{}) ([]byte, error)
Marshal marshals "v" into JSON
func (*JSONBuiltin) NewDecoder ¶
func (j *JSONBuiltin) NewDecoder(r io.Reader) Decoder
NewDecoder returns a Decoder which reads JSON stream from "r".
func (*JSONBuiltin) NewEncoder ¶
func (j *JSONBuiltin) NewEncoder(w io.Writer) Encoder
NewEncoder returns an Encoder which writes JSON stream into "w".
func (*JSONBuiltin) Unmarshal ¶
func (j *JSONBuiltin) Unmarshal(data []byte, v interface{}) error
Unmarshal unmarshals JSON data into "v".
type JSONPb ¶
type JSONPb struct { protojson.MarshalOptions protojson.UnmarshalOptions }
JSONPb is a Marshaler which marshals/unmarshals into/from JSON with the "google.golang.org/protobuf/encoding/protojson" marshaler. It supports the full functionality of protobuf unlike JSONBuiltin.
The NewDecoder method returns a DecoderWrapper, so the underlying *json.Decoder methods can be used.
func (*JSONPb) ContentType ¶
ContentType always returns "application/json".
func (*JSONPb) NewDecoder ¶
NewDecoder returns a Decoder which reads JSON stream from "r".
func (*JSONPb) NewEncoder ¶
NewEncoder returns an Encoder which writes JSON stream into "w".
type MalformedSequenceError ¶
type MalformedSequenceError string
func (MalformedSequenceError) Error ¶
func (e MalformedSequenceError) Error() string
type Marshaler ¶
type Marshaler interface { // Marshal marshals "v" into byte sequence. Marshal(ctx context.Context, v interface{}) ([]byte, error) // Unmarshal unmarshals "data" into "v". // "v" must be a pointer value. Unmarshal(ctx context.Context, data []byte, v interface{}) error // NewDecoder returns a Decoder which reads byte sequence from "r". NewDecoder(r io.Reader) Decoder // NewEncoder returns an Encoder which writes bytes sequence into "w". NewEncoder(w io.Writer) Encoder // ContentType returns the Content-Type which this marshaler is responsible for. // The parameter describes the type which is being marshalled, which can sometimes // affect the content type returned. ContentType(v interface{}) string }
Marshaler defines a conversion between byte sequence and gRPC payloads / fields.
type Pattern ¶
type Pattern struct {
// contains filtered or unexported fields
}
Pattern is a template pattern of http request paths defined in https://github.com/googleapis/googleapis/blob/master/google/api/http.proto
func MustPattern ¶
MustPattern is a helper function which makes it easier to call NewPattern in variable initialization.
func NewPattern ¶
NewPattern returns a new Pattern from the given definition values. "ops" is a sequence of op codes. "pool" is a constant pool. "verb" is the verb part of the pattern. It is empty if the pattern does not have the part. "version" must be 1 for now. It returns an error if the given definition is invalid.
func (Pattern) Match
deprecated
MatchAndEscape examines components to determine if they match to a Pattern. It will never perform per-component unescaping (see: UnescapingModeLegacy). MatchAndEscape will return an error if no Patterns matched. If successful, the function returns a mapping from field paths to their captured values.
Deprecated: Use MatchAndEscape.
func (Pattern) MatchAndEscape ¶
func (p Pattern) MatchAndEscape(components []string, verb string, unescapingMode UnescapingMode) (map[string]string, error)
MatchAndEscape examines components to determine if they match to a Pattern. MatchAndEscape will return an error if no Patterns matched or if a pattern matched but contained malformed escape sequences. If successful, the function returns a mapping from field paths to their captured values.
type ProtoMarshaller ¶
type ProtoMarshaller struct{}
ProtoMarshaller is a Marshaller which marshals/unmarshals into/from serialize proto bytes
func (*ProtoMarshaller) ContentType ¶
func (*ProtoMarshaller) ContentType(_ interface{}) string
ContentType always returns "application/octet-stream".
func (*ProtoMarshaller) Marshal ¶
func (*ProtoMarshaller) Marshal(_ context.Context, value interface{}) ([]byte, error)
Marshal marshals "value" into Proto
func (*ProtoMarshaller) NewDecoder ¶
func (marshaller *ProtoMarshaller) NewDecoder(reader io.Reader) Decoder
NewDecoder returns a Decoder which reads proto stream from "reader".
func (*ProtoMarshaller) NewEncoder ¶
func (marshaller *ProtoMarshaller) NewEncoder(writer io.Writer) Encoder
NewEncoder returns an Encoder which writes proto stream into "writer".
type QueryParameterParser ¶
type QueryParameterParser interface {
Parse(msg proto.Message, values url.Values, filter *utilities.DoubleArray) error
}
QueryParameterParser defines interface for all query parameter parsers
type RoutingErrorHandlerFunc ¶
type RoutingErrorHandlerFunc func(context.Context, *ServeMux, Marshaler, http.ResponseWriter, *http.Request, int)
RoutingErrorHandlerFunc is the signature used to configure error handling for routing errors.
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) GetForwardResponseOptions ¶
func (s *ServeMux) GetForwardResponseOptions() []func(context.Context, http.ResponseWriter, proto.Message) error
GetForwardResponseOptions returns the ForwardResponseOptions associated with this ServeMux.
func (*ServeMux) Handle ¶
func (s *ServeMux) Handle(meth string, pat Pattern, h HandlerFunc)
Handle associates "h" to the pair of HTTP method and path pattern.
func (*ServeMux) HandlePath ¶
func (s *ServeMux) HandlePath(meth string, pathPattern string, h HandlerFunc) error
HandlePath allows users to configure custom path handlers. refer: https://grpc-ecosystem.github.io/grpc-gateway/docs/operations/inject_router/
type ServeMuxOption ¶
type ServeMuxOption func(*ServeMux)
ServeMuxOption is an option that can be given to a ServeMux on construction.
func SetQueryParameterParser ¶
func SetQueryParameterParser(queryParameterParser QueryParameterParser) ServeMuxOption
SetQueryParameterParser 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 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 func(context.Context, http.ResponseWriter, proto.Message) error) 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 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).
See here https://grpc-ecosystem.github.io/grpc-gateway/docs/operations/health_check/ for more information on how to setup the protocol in the grpc server.
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 WithMarshalerOption ¶
func WithMarshalerOption(mime string, marshaler Marshaler) ServeMuxOption
WithMarshalerOption returns a ServeMuxOption which associates inbound and outbound Marshalers to a MIME type in mux.
func WithMetadata ¶
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 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 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 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 WithUnescapingMode ¶
func WithUnescapingMode(mode UnescapingMode) ServeMuxOption
WithEscapingType sets the escaping type. See the definitions of UnescapingMode for more information.
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.
type UnescapingMode ¶
type UnescapingMode int
UnescapingMode defines the behavior of ServeMux when unescaping path parameters.
const ( // UnescapingModeLegacy is the default V2 behavior, which escapes the entire // path string before doing any routing. UnescapingModeLegacy UnescapingMode = iota // UnescapingModeAllExceptReserved unescapes all path parameters except RFC 6570 // reserved characters. UnescapingModeAllExceptReserved // UnescapingModeAllExceptSlash unescapes URL path parameters except path // separators, which will be left as "%2F". UnescapingModeAllExceptSlash // UnescapingModeAllCharacters unescapes all URL path parameters. UnescapingModeAllCharacters // UnescapingModeDefault is the default escaping type. // TODO(v3): default this to UnescapingModeAllExceptReserved per grpc-httpjson-transcoding's // reference implementation UnescapingModeDefault = UnescapingModeLegacy )