package runtime
Import Path
github.com/grpc-ecosystem/grpc-gateway/v2/runtime (on go.dev)
Dependency Relation
imports 36 packages, and imported by one package
Involved Source Files
context.go
convert.go
Package runtime contains runtime helper functions used by
servers which protoc-gen-grpc-gateway generates.
errors.go
fieldmask.go
handler.go
marshal_httpbodyproto.go
marshal_json.go
marshal_jsonpb.go
marshal_proto.go
marshaler.go
marshaler_registry.go
mux.go
pattern.go
proto2_convert.go
query.go
Package-Level Type Names (total 30)
func WithHTTPPathPattern(pattern string) AnnotateContextOption
func AnnotateContext(ctx context.Context, mux *ServeMux, req *http.Request, rpcMethodName string, options ...AnnotateContextOption) (context.Context, error)
func AnnotateIncomingContext(ctx context.Context, mux *ServeMux, req *http.Request, rpcMethodName string, options ...AnnotateContextOption) (context.Context, error)
Decoder decodes a byte sequence
( Decoder) Decode(v interface{}) error
DecoderFunc
DecoderWrapper
*github.com/francoispqt/gojay.Decoder
github.com/francoispqt/gojay.StreamDecoder
*github.com/go-viper/mapstructure/v2.Decoder
*github.com/goccy/go-json.Decoder
*github.com/hamba/avro/v2.Decoder
*github.com/hamba/avro/v2/ocf.Decoder
*github.com/json-iterator/go.Decoder
*github.com/parquet-go/parquet-go/encoding/thrift.Decoder
*github.com/vmihailenco/msgpack/v5.Decoder
*encoding/gob.Decoder
*encoding/json.Decoder
*encoding/xml.Decoder
*gopkg.in/yaml.v3.Decoder
*gopkg.in/yaml.v3.Node
func (*JSONBuiltin).NewDecoder(r io.Reader) Decoder
func (*JSONPb).NewDecoder(r io.Reader) Decoder
func Marshaler.NewDecoder(r io.Reader) Decoder
func (*ProtoMarshaller).NewDecoder(reader io.Reader) Decoder
DecoderFunc adapts an decoder function into Decoder.
Decode delegates invocations to the underlying function itself.
DecoderFunc : Decoder
DecoderWrapper is a wrapper around a *json.Decoder that adds
support for protos to the Decode method.
Decoder *json.Decoder
UnmarshalOptions protojson.UnmarshalOptions
If AllowPartial is set, input for messages that will result in missing
required fields will not return an error.
If DiscardUnknown is set, unknown fields and enum name values are ignored.
UnmarshalOptions.NoUnkeyedLiterals pragma.NoUnkeyedLiterals
RecursionLimit limits how deeply messages may be nested.
If zero, a default limit is applied.
Resolver is used for looking up types when unmarshaling
google.protobuf.Any messages or extension fields.
If nil, this defaults to using protoregistry.GlobalTypes.
Buffered returns a reader of the data remaining in the Decoder's
buffer. The reader is valid until the next call to [Decoder.Decode].
Decode wraps the embedded decoder's Decode method to support
protos using a jsonpb.Unmarshaler.
DisallowUnknownFields causes the Decoder to return an error when the destination
is a struct and the input contains object keys which do not match any
non-ignored, exported fields in the destination.
InputOffset returns the input stream byte offset of the current decoder position.
The offset gives the location of the end of the most recently returned token
and the beginning of the next token.
More reports whether there is another element in the
current array or object being parsed.
Token returns the next JSON token in the input stream.
At the end of the input stream, Token returns nil, [io.EOF].
Token guarantees that the delimiters [ ] { } it returns are
properly nested and matched: if Token encounters an unexpected
delimiter in the input, it will return an error.
The input stream consists of basic JSON values—bool, string,
number, and null—along with delimiters [ ] { } of type [Delim]
to mark the start and end of arrays and objects.
Commas and colons are elided.
Unmarshal reads the given []byte and populates the given [proto.Message]
using options in the UnmarshalOptions object.
It will clear the message first before setting the fields.
If it returns an error, the given message may be partially set.
The provided message must be mutable (e.g., a non-nil pointer to a message).
UseNumber causes the Decoder to unmarshal a number into an
interface value as a [Number] instead of as a float64.
DecoderWrapper : Decoder
DefaultQueryParser is a QueryParameterParser which implements the default
query parameters parsing behavior.
See https://github.com/grpc-ecosystem/grpc-gateway/issues/2632 for more context.
Parse populates "values" into "msg".
A value is ignored if its key starts with one of the elements in "filter".
*DefaultQueryParser : QueryParameterParser
Delimited defines the streaming delimiter.
Delimiter returns the record separator for the stream.
*JSONBuiltin
*JSONPb
Encoder encodes gRPC payloads / fields into byte sequence.
Encode encodes and writes to the underlying data stream.
EncoderFunc
*github.com/francoispqt/gojay.Encoder
github.com/francoispqt/gojay.StreamEncoder
*github.com/goccy/go-json.Encoder
*github.com/hamba/avro/v2.Encoder
*github.com/hamba/avro/v2/ocf.Encoder
*github.com/json-iterator/go.Encoder
*github.com/parquet-go/parquet-go/encoding/thrift.Encoder
*github.com/vmihailenco/msgpack/v5.Encoder
*encoding/gob.Encoder
*encoding/json.Encoder
*encoding/xml.Encoder
go.uber.org/zap/zapcore.ReflectedEncoder (interface)
*gopkg.in/yaml.v3.Encoder
*gopkg.in/yaml.v3.Node
Encoder : go.uber.org/zap/zapcore.ReflectedEncoder
func (*JSONBuiltin).NewEncoder(w io.Writer) Encoder
func (*JSONPb).NewEncoder(w io.Writer) Encoder
func Marshaler.NewEncoder(w io.Writer) Encoder
func (*ProtoMarshaller).NewEncoder(writer io.Writer) Encoder
EncoderFunc adapts an encoder function into Encoder
Encode delegates invocations to the underlying function itself.
EncoderFunc : Encoder
EncoderFunc : go.uber.org/zap/zapcore.ReflectedEncoder
ErrorHandlerFunc is the signature used to configure error handling.
func WithErrorHandler(fn ErrorHandlerFunc) ServeMuxOption
ForwardResponseRewriter is the signature of a function that is capable of rewriting messages
before they are forwarded in a unary, stream, or error response.
func WithForwardResponseRewriter(fwdResponseRewriter ForwardResponseRewriter) ServeMuxOption
A HandlerFunc handles a specific pair of path pattern and HTTP method.
func (*ServeMux).Handle(meth string, pat Pattern, h HandlerFunc)
func (*ServeMux).HandlePath(meth string, pathPattern string, h HandlerFunc) error
HeaderMatcherFunc checks whether a header key should be forwarded to/from gRPC context.
func WithIncomingHeaderMatcher(fn HeaderMatcherFunc) ServeMuxOption
func WithOutgoingHeaderMatcher(fn HeaderMatcherFunc) ServeMuxOption
func WithOutgoingTrailerMatcher(fn HeaderMatcherFunc) ServeMuxOption
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.
Marshaler Marshaler
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.
Marshal marshals "v" by returning the body bytes if v is a
google.api.HttpBody message, otherwise it falls back to the default Marshaler.
NewDecoder returns a Decoder which reads byte sequence from "r".
NewEncoder returns an Encoder which writes bytes sequence into "w".
Unmarshal unmarshals "data" into "v".
"v" must be a pointer value.
*HTTPBodyMarshaler : Marshaler
HTTPStatusError is the error to use when needing to provide a different HTTP status code for an error
passed to the DefaultRoutingErrorHandler.
Err error
HTTPStatus int
(*HTTPStatusError) Error() string
*HTTPStatusError : error
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.
ContentType always Returns "application/json".
Delimiter for newline encoded JSON streams.
Marshal marshals "v" into JSON
MarshalIndent is like Marshal but applies Indent to format the output
NewDecoder returns a Decoder which reads JSON stream from "r".
NewEncoder returns an Encoder which writes JSON stream into "w".
Unmarshal unmarshals JSON data into "v".
*JSONBuiltin : Delimited
*JSONBuiltin : Marshaler
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.
MarshalOptions protojson.MarshalOptions
EmitDefaultValues specifies whether to emit default-valued primitive fields,
empty lists, and empty maps. The fields affected are as follows:
╔═══════╤════════════════════════════════════════╗
║ JSON │ Protobuf field ║
╠═══════╪════════════════════════════════════════╣
║ false │ non-optional scalar boolean fields ║
║ 0 │ non-optional scalar numeric fields ║
║ "" │ non-optional scalar string/byte fields ║
║ [] │ empty repeated fields ║
║ {} │ empty map fields ║
╚═══════╧════════════════════════════════════════╝
Behaves similarly to EmitUnpopulated, but does not emit "null"-value fields,
i.e. presence-sensing fields that are omitted will remain omitted to preserve
presence-sensing.
EmitUnpopulated takes precedence over EmitDefaultValues since the former generates
a strict superset of the latter.
EmitUnpopulated specifies whether to emit unpopulated fields. It does not
emit unpopulated oneof fields or unpopulated extension fields.
The JSON value emitted for unpopulated fields are as follows:
╔═══════╤════════════════════════════╗
║ JSON │ Protobuf field ║
╠═══════╪════════════════════════════╣
║ false │ proto3 boolean fields ║
║ 0 │ proto3 numeric fields ║
║ "" │ proto3 string/bytes fields ║
║ null │ proto2 scalar fields ║
║ null │ message fields ║
║ [] │ list fields ║
║ {} │ map fields ║
╚═══════╧════════════════════════════╝
Indent specifies the set of indentation characters to use in a multiline
formatted output such that every entry is preceded by Indent and
terminated by a newline. If non-empty, then Multiline is treated as true.
Indent can only be composed of space or tab characters.
Multiline specifies whether the marshaler should format the output in
indented-form with every textual element on a new line.
If Indent is an empty string, then an arbitrary indent is chosen.
UseEnumNumbers emits enum values as numbers.
UseProtoNames uses proto field name instead of lowerCamelCase name in JSON
field names.
UnmarshalOptions protojson.UnmarshalOptions
If DiscardUnknown is set, unknown fields and enum name values are ignored.
RecursionLimit limits how deeply messages may be nested.
If zero, a default limit is applied.
ContentType always returns "application/json".
Delimiter for newline encoded JSON streams.
Format formats the message as a string.
This method is only intended for human consumption and ignores errors.
Do not depend on the output being stable. Its output will change across
different builds of your program, even when using the same version of the
protobuf module.
Marshal marshals "v" into JSON.
MarshalAppend appends the JSON format encoding of m to b,
returning the result.
NewDecoder returns a Decoder which reads JSON stream from "r".
NewEncoder returns an Encoder which writes JSON stream into "w".
Unmarshal unmarshals JSON "data" into "v"
*JSONPb : Delimited
*JSONPb : Marshaler
Marshaler defines a conversion between byte sequence and gRPC payloads / fields.
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.
Marshal marshals "v" into byte sequence.
NewDecoder returns a Decoder which reads byte sequence from "r".
NewEncoder returns an Encoder which writes bytes sequence into "w".
Unmarshal unmarshals "data" into "v".
"v" must be a pointer value.
*HTTPBodyMarshaler
*JSONBuiltin
*JSONPb
*ProtoMarshaller
func MarshalerForRequest(mux *ServeMux, r *http.Request) (inbound Marshaler, outbound Marshaler)
func MarshalerForRequest(mux *ServeMux, r *http.Request) (inbound Marshaler, outbound Marshaler)
func DefaultHTTPErrorHandler(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, r *http.Request, err error)
func DefaultRoutingErrorHandler(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, r *http.Request, httpStatus int)
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)
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)
func HTTPError(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, r *http.Request, err error)
func HTTPStreamError(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, r *http.Request, err error)
func WithMarshalerOption(mime string, marshaler Marshaler) ServeMuxOption
A Middleware handler wraps another HandlerFunc to do some pre- and/or post-processing of the request. This is used as an alternative to gRPC interceptors when using the direct-to-implementation
registration methods. It is generally recommended to use gRPC client or server interceptors instead
where possible.
func WithMiddlewares(middlewares ...Middleware) ServeMuxOption
Pattern is a template pattern of http request paths defined in
https://github.com/googleapis/googleapis/blob/master/google/api/http.proto
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.
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.
( Pattern) String() string
Verb returns the verb part of the Pattern.
Pattern : expvar.Var
Pattern : fmt.Stringer
func HTTPPattern(ctx context.Context) (Pattern, bool)
func MustPattern(p Pattern, err error) Pattern
func NewPattern(version int, ops []int, pool []string, verb string) (Pattern, error)
func MustPattern(p Pattern, err error) Pattern
func (*ServeMux).Handle(meth string, pat Pattern, h HandlerFunc)
ProtoMarshaller is a Marshaller which marshals/unmarshals into/from serialize proto bytes
ContentType always returns "application/octet-stream".
Marshal marshals "value" into Proto
NewDecoder returns a Decoder which reads proto stream from "reader".
NewEncoder returns an Encoder which writes proto stream into "writer".
Unmarshal unmarshals proto "data" into "value"
*ProtoMarshaller : Marshaler
QueryParameterParser defines interface for all query parameter parsers
( QueryParameterParser) Parse(msg proto.Message, values url.Values, filter *utilities.DoubleArray) error
*DefaultQueryParser
func SetQueryParameterParser(queryParameterParser QueryParameterParser) ServeMuxOption
RoutingErrorHandlerFunc is the signature used to configure error handling for routing errors.
func WithRoutingErrorHandler(fn RoutingErrorHandlerFunc) ServeMuxOption
ServeMux is a request multiplexer for grpc-gateway.
It matches http requests to patterns and invokes the corresponding handler.
GetForwardResponseOptions returns the ForwardResponseOptions associated with this ServeMux.
Handle associates "h" to the pair of HTTP method and path pattern.
HandlePath allows users to configure custom path handlers.
refer: https://grpc-ecosystem.github.io/grpc-gateway/docs/operations/inject_router/
ServeHTTP dispatches the request to the first handler whose pattern matches to r.Method and r.URL.Path.
*ServeMux : net/http.Handler
func NewServeMux(opts ...ServeMuxOption) *ServeMux
func AnnotateContext(ctx context.Context, mux *ServeMux, req *http.Request, rpcMethodName string, options ...AnnotateContextOption) (context.Context, error)
func AnnotateIncomingContext(ctx context.Context, mux *ServeMux, req *http.Request, rpcMethodName string, options ...AnnotateContextOption) (context.Context, error)
func DefaultHTTPErrorHandler(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, r *http.Request, err error)
func DefaultRoutingErrorHandler(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, r *http.Request, httpStatus int)
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)
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)
func HTTPError(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, r *http.Request, err error)
func HTTPStreamError(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, r *http.Request, err error)
func MarshalerForRequest(mux *ServeMux, r *http.Request) (inbound Marshaler, outbound Marshaler)
func go.opentelemetry.io/proto/otlp/collector/trace/v1.RegisterTraceServiceHandler(ctx context.Context, mux *ServeMux, conn *grpc.ClientConn) error
func go.opentelemetry.io/proto/otlp/collector/trace/v1.RegisterTraceServiceHandlerClient(ctx context.Context, mux *ServeMux, client v1.TraceServiceClient) error
func go.opentelemetry.io/proto/otlp/collector/trace/v1.RegisterTraceServiceHandlerFromEndpoint(ctx context.Context, mux *ServeMux, endpoint string, opts []grpc.DialOption) (err error)
func go.opentelemetry.io/proto/otlp/collector/trace/v1.RegisterTraceServiceHandlerServer(ctx context.Context, mux *ServeMux, server v1.TraceServiceServer) error
ServeMuxOption is an option that can be given to a ServeMux on construction.
func SetQueryParameterParser(queryParameterParser QueryParameterParser) ServeMuxOption
func WithDisablePathLengthFallback() ServeMuxOption
func WithErrorHandler(fn ErrorHandlerFunc) ServeMuxOption
func WithForwardResponseOption(forwardResponseOption func(context.Context, http.ResponseWriter, proto.Message) error) ServeMuxOption
func WithForwardResponseRewriter(fwdResponseRewriter ForwardResponseRewriter) 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 WithMiddlewares(middlewares ...Middleware) ServeMuxOption
func WithOutgoingHeaderMatcher(fn HeaderMatcherFunc) ServeMuxOption
func WithOutgoingTrailerMatcher(fn HeaderMatcherFunc) ServeMuxOption
func WithRoutingErrorHandler(fn RoutingErrorHandlerFunc) ServeMuxOption
func WithStreamErrorHandler(fn StreamErrorHandlerFunc) ServeMuxOption
func WithUnescapingMode(mode UnescapingMode) ServeMuxOption
func WithWriteContentLength() ServeMuxOption
func NewServeMux(opts ...ServeMuxOption) *ServeMux
ServerMetadata consists of metadata sent from gRPC server.
HeaderMD metadata.MD
TrailerMD metadata.MD
func ServerMetadataFromContext(ctx context.Context) (md ServerMetadata, ok bool)
func NewServerMetadataContext(ctx context.Context, md ServerMetadata) context.Context
ServerTransportStream implements grpc.ServerTransportStream.
It should only be used by the generated files to support grpc.SendHeader
outside of gRPC server use.
Header returns the header metadata of the stream.
Method returns the method for the stream.
SendHeader sets the header metadata.
SetHeader sets the header metadata.
SetTrailer sets the trailer metadata.
Trailer returns the cached trailer metadata.
*ServerTransportStream : google.golang.org/grpc.ServerTransportStream
StreamContentType defines the streaming content type.
StreamContentType returns the content type for a stream. This shares the
same behaviour as for `Marshaler.ContentType`, but is called, if present,
in the case of a streamed response.
StreamErrorHandlerFunc is the signature used to configure stream error handling.
func WithStreamErrorHandler(fn StreamErrorHandlerFunc) ServeMuxOption
UnescapingMode defines the behavior of ServeMux when unescaping path parameters.
func WithUnescapingMode(mode UnescapingMode) ServeMuxOption
func Pattern.MatchAndEscape(components []string, verb string, unescapingMode UnescapingMode) (map[string]string, error)
const UnescapingModeAllCharacters
const UnescapingModeAllExceptReserved
const UnescapingModeAllExceptSlash
const UnescapingModeDefault
const UnescapingModeLegacy
Package-Level Functions (total 80)
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.
AnnotateIncomingContext adds context information such as metadata from the request.
Attach metadata as incoming context.
Bool converts the given string representation of a boolean value into bool.
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.
BoolSlice converts 'val' where individual booleans are separated by
'sep' into a bool slice.
BoolValue well-known type support as wrapper around bool type
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
BytesSlice converts 'val' where individual bytes sequences, encoded in URL-safe
base64 without padding, are separated by 'sep' into a slice of byte slices.
BytesValue well-known type support as wrapper around bytes[] type
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.
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.
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
DoubleValue well-known type support as wrapper around float64 type
Duration converts the given string into a timestamp.Duration.
Enum converts the given string into an int32 that should be type casted into the
correct enum proto type.
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.
FieldMaskFromRequestBody creates a FieldMask printing all complete paths from the JSON body.
Float32 converts the given string representation of a floating point number into float32.
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.
Float32Slice converts 'val' where individual floating point numbers are separated by
'sep' into a float32 slice.
Float64 converts the given string representation into representation of a floating point number into float64.
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.
Float64Slice converts 'val' where individual floating point numbers are separated by
'sep' into a float64 slice.
FloatValue well-known type support as wrapper around float32 type
ForwardResponseMessage forwards the message "resp" from gRPC server to REST client.
ForwardResponseStream forwards the stream from gRPC server to REST client.
HTTPError uses the mux-configured error handler.
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.
HTTPPattern returns the HTTP path pattern struct relating to the HTTP handler, if one exists.
HTTPStatusFromCode converts a gRPC error code into the corresponding HTTP response status.
See: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
HTTPStreamError uses the mux-configured stream error handler to notify error to the client without closing the connection.
Int32 converts the given string representation of an integer into int32.
Int32P parses the given string representation of an integer
and returns a pointer to an int32 whose value is same as the parsed integer.
Int32Slice converts 'val' where individual integers are separated by
'sep' into an int32 slice.
Int32Value well-known type support as wrapper around int32 type
Int64 converts the given string representation of an integer into int64.
Int64P parses the given string representation of an integer
and returns a pointer to an int64 whose value is same as the parsed integer.
Int64Slice converts 'val' where individual integers are separated by
'sep' into an int64 slice.
Int64Value well-known type support as wrapper around int64 type
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.
MustPattern is a helper function which makes it easier to call NewPattern in variable initialization.
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.
NewServeMux returns a new ServeMux whose internal mapping is empty.
NewServerMetadataContext creates a new context with ServerMetadata
PopulateFieldFromPath sets a value in a nested Protobuf structure.
PopulateQueryParameters parses query parameters
into "msg" using current query parser
RPCMethod returns the method string for the server context. The returned
string is in the format of "/package.service/method".
ServerMetadataFromContext returns the ServerMetadata in ctx
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.
String just returns the given string.
It is just for compatibility to other types.
StringP returns a pointer to a string whose pointee is same as the given string value.
StringSlice converts 'val' where individual strings are separated by
'sep' into a string slice.
StringValue well-known type support as wrapper around string type
Timestamp converts the given RFC3339 formatted string into a timestamp.Timestamp.
Uint32 converts the given string representation of an integer into uint32.
Uint32P parses the given string representation of an integer
and returns a pointer to a uint32 whose value is same as the parsed integer.
Uint32Slice converts 'val' where individual integers are separated by
'sep' into a uint32 slice.
UInt32Value well-known type support as wrapper around uint32 type
Uint64 converts the given string representation of an integer into uint64.
Uint64P parses the given string representation of an integer
and returns a pointer to a uint64 whose value is same as the parsed integer.
Uint64Slice converts 'val' where individual integers are separated by
'sep' into a uint64 slice.
UInt64Value well-known type support as wrapper around uint64 type
WithDisablePathLengthFallback returns a ServeMuxOption for disable path length fallback.
WithErrorHandler returns a ServeMuxOption for configuring a custom error handler.
This can be used to configure a custom error response.
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.
WithForwardResponseRewriter returns a ServeMuxOption that allows for implementers to insert logic
that can rewrite the final response before it is forwarded.
The response rewriter function is called during unary message forwarding, stream message
forwarding and when errors are being forwarded.
NOTE: Using this option will likely make what is generated by `protoc-gen-openapiv2` incorrect.
Since this option involves making runtime changes to the response shape or type.
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.
WithHealthzEndpoint returns a ServeMuxOption that will add a /healthz endpoint to the created ServeMux.
See WithHealthEndpointAt for the general implementation.
func WithHTTPPathPattern(pattern string) AnnotateContextOption
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 the modified header.
WithMarshalerOption returns a ServeMuxOption which associates inbound and outbound
Marshalers to a MIME type in mux.
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.
WithMiddlewares sets server middleware for all handlers. This is useful as an alternative to gRPC
interceptors when using the direct-to-implementation registration methods and cannot rely
on gRPC interceptors. It's recommended to use gRPC interceptors instead if possible.
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 the modified header.
WithOutgoingTrailerMatcher returns a ServeMuxOption representing a headerMatcher for outgoing response from gateway.
This matcher will be called with each header in response trailer 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 the modified header.
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
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.
WithUnescapingMode sets the escaping type. See the definitions of UnescapingMode
for more information.
WithWriteContentLength returns a ServeMuxOption to enable writing content length on non-streaming responses
Package-Level Variables (total 3)
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.
ErrInvalidPattern indicates that the given definition of Pattern is not valid.
ErrNotMatch indicates that the given HTTP request path does not match to the pattern.
Package-Level Constants (total 9)
MetadataHeaderPrefix is the http prefix that represents custom metadata
parameters to or from a gRPC call.
MetadataPrefix is prepended to permanent HTTP header keys (as specified
by the IANA) when added to the gRPC context.
MetadataTrailerPrefix is prepended to gRPC metadata as it is converted to
HTTP headers in a response handled by grpc-gateway
MIMEWildcard is the fallback MIME type used for requests which do not match
a registered MIME type.
UnescapingModeAllCharacters unescapes all URL path parameters.
UnescapingModeAllExceptReserved unescapes all path parameters except RFC 6570
reserved characters.
UnescapingModeAllExceptSlash unescapes URL path parameters except path
separators, which will be left as "%2F".
UnescapingModeDefault is the default escaping type.
TODO(v3): default this to UnescapingModeAllExceptReserved per grpc-httpjson-transcoding's
reference implementation
UnescapingModeLegacy is the default V2 behavior, which escapes the entire
path string before doing any routing.
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |