Documentation ¶
Overview ¶
Package runtime contains runtime helper functions used by servers which protoc-gen-grpc-gateway generates.
Package runtime is a generated protocol buffer package.
It is generated from these files:
runtime/stream_chunk.proto
It has these top-level messages:
StreamError
Index ¶
- Variables
- func AnnotateContext(ctx context.Context, req *http.Request) context.Context
- func Bool(val string) (bool, error)
- func BoolP(val string) (*bool, error)
- func DefaultHTTPError(ctx context.Context, marshaler Marshaler, w http.ResponseWriter, ...)
- func DefaultOtherErrorHandler(w http.ResponseWriter, _ *http.Request, error string, code int)
- func Float32(val string) (float32, error)
- func Float32P(val string) (*float32, error)
- func Float64(val string) (float64, error)
- func Float64P(val string) (*float64, error)
- func ForwardResponseMessage(ctx context.Context, marshaler Marshaler, w http.ResponseWriter, ...)
- func ForwardResponseStream(ctx context.Context, marshaler Marshaler, w http.ResponseWriter, ...)
- func HTTPStatusFromCode(code codes.Code) int
- func Int32(val string) (int32, error)
- func Int32P(val string) (*int32, error)
- func Int64(val string) (int64, error)
- func Int64P(val string) (*int64, 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 String(val string) (string, error)
- func StringP(val string) (*string, error)
- func Uint32(val string) (uint32, error)
- func Uint32P(val string) (*uint32, error)
- func Uint64(val string) (uint64, error)
- func Uint64P(val string) (*uint64, error)
- type Decoder
- type DecoderFunc
- type Encoder
- type EncoderFunc
- type HandlerFunc
- type JSONBuiltin
- type JSONPb
- type Marshaler
- type Pattern
- type ServeMux
- type ServeMuxOption
- type ServerMetadata
- type StreamError
Constants ¶
This section is empty.
Variables ¶
var ( // HTTPError replies to the request with the error. // You can set a custom function to this variable to customize error format. HTTPError = DefaultHTTPError // This handles the following error used by the gateway: StatusMethodNotAllowed StatusNotFound and StatusBadRequest OtherErrorHandler = DefaultOtherErrorHandler )
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") )
Functions ¶
func AnnotateContext ¶
AnnotateContext adds context information such as metadata from the request.
If there are no metadata headers in the request, then the context returned will be the same 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 DefaultHTTPError ¶
func DefaultHTTPError(ctx context.Context, marshaler Marshaler, w http.ResponseWriter, _ *http.Request, err error)
DefaultHTTPError is the default implementation of HTTPError. If "err" is an error from gRPC system, the function replies with the status code mapped by HTTPStatusFromCode. If otherwise, it replies with http.StatusInternalServerError.
The response body returned by this function is a JSON object, which contains a member whose key is "error" and whose value is err.Error().
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 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 ForwardResponseMessage ¶
func ForwardResponseMessage(ctx context.Context, 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, 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 HTTPStatusFromCode ¶
HTTPStatusFromCode converts a gRPC error code into the corresponding HTTP response status.
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 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 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. It instantiates missing protobuf fields as it goes.
func PopulateQueryParameters ¶
func PopulateQueryParameters(msg proto.Message, values url.Values, filter *utilities.DoubleArray) error
PopulateQueryParameters populates "values" into "msg". A value is ignored if its key starts with one of the elements in "filter".
func StringP ¶
StringP returns a pointer to a string whose pointee is same as the given string value.
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.
Types ¶
type Decoder ¶
type Decoder interface {
Decode(v interface{}) error
}
Decoder decodes a byte sequence
type DecoderFunc ¶
type DecoderFunc func(v interface{}) error
DecoderFunc adapts an decoder function into Decoder.
func (DecoderFunc) Decode ¶
func (f DecoderFunc) Decode(v interface{}) error
Decode delegates invocations to the underlying function itself.
type Encoder ¶
type Encoder interface {
Encode(v interface{}) error
}
Encoder encodes gRPC payloads / fields into byte sequence.
type EncoderFunc ¶
type EncoderFunc func(v interface{}) error
EncoderFunc adapts an encoder function into Encoder
func (EncoderFunc) Encode ¶
func (f EncoderFunc) Encode(v interface{}) error
Encode delegates invocations to the underlying function itself.
type HandlerFunc ¶
A HandlerFunc handles a specific pair of path pattern and HTTP method.
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, ....
func (*JSONBuiltin) ContentType ¶
func (*JSONBuiltin) ContentType() string
ContentType always Returns "application/json".
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 { // Whether to render enum values as integers, as opposed to string values. EnumsAsInts bool // Whether to render fields with zero values. EmitDefaults bool // A string to indent each level by. The presence of this field will // also cause a space to appear between the field separator and // value, and for newlines to be appear between fields and array // elements. Indent string // Whether to use the original (.proto) name for fields. OrigName bool }
JSONPb is a Marshaler which marshals/unmarshals into/from JSON with the "github.com/golang/protobuf/jsonpb". It supports fully functionality of protobuf unlike JSONBuiltin.
func (*JSONPb) ContentType ¶
ContentType always returns "application/json".
func (*JSONPb) Marshal ¶
Marshal marshals "v" into JSON Currently it can marshal only proto.Message. TODO(yugui) Support fields of primitive types in a message.
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 Marshaler ¶
type Marshaler interface { // Marshal marshals "v" into byte sequence. Marshal(v interface{}) ([]byte, error) // Unmarshal unmarshals "data" into "v". // "v" must be a pointer value. Unmarshal(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. ContentType() 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 third_party/googleapis/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.
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.
type ServeMuxOption ¶
type ServeMuxOption func(*ServeMux)
ServeMuxOption is an option that can be given to a ServeMux on construction.
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 WithInboundMarshalerOption ¶
func WithInboundMarshalerOption(mime string, in Marshaler) ServeMuxOption
WithInboundMarshalerOption returns a ServeMuxOption which associates an inbound Marshaler to a MIME type in mux.
func WithMarshalerOption ¶
func WithMarshalerOption(mime string, in, out Marshaler) ServeMuxOption
WithMarshalerOption returns a ServeMuxOption which associates inbound and outbound Marshalers to a MIME type in mux.
func WithOutboundMarshalerOption ¶
func WithOutboundMarshalerOption(mime string, out Marshaler) ServeMuxOption
WithOutboundMarshalerOption returns a ServeMuxOption which associates an outbound Marshaler to a MIME type in mux.
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 StreamError ¶
type StreamError struct { GrpcCode int32 `protobuf:"varint,1,opt,name=grpc_code,json=grpcCode" json:"grpc_code,omitempty"` HttpCode int32 `protobuf:"varint,2,opt,name=http_code,json=httpCode" json:"http_code,omitempty"` Message string `protobuf:"bytes,3,opt,name=message" json:"message,omitempty"` HttpStatus string `protobuf:"bytes,4,opt,name=http_status,json=httpStatus" json:"http_status,omitempty"` }
func (*StreamError) Descriptor ¶
func (*StreamError) Descriptor() ([]byte, []int)
func (*StreamError) ProtoMessage ¶
func (*StreamError) ProtoMessage()
func (*StreamError) Reset ¶
func (m *StreamError) Reset()
func (*StreamError) String ¶
func (m *StreamError) String() string