Documentation ¶
Overview ¶
Package runtime contains runtime helper functions used by servers which protoc-gen-grpc-gateway generates.
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, w http.ResponseWriter, err error)
- 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, w http.ResponseWriter, req *http.Request, ...)
- func ForwardResponseStream(ctx context.Context, w http.ResponseWriter, req *http.Request, ...)
- 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 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 HandlerFunc
- type Pattern
- type ServeMux
Constants ¶
This section is empty.
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") )
var ( // HTTPError replies to the request with the error. // You can set a custom function to this variable to customize error format. HTTPError = DefaultHTTPError )
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, w http.ResponseWriter, 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, w http.ResponseWriter, req *http.Request, resp proto.Message)
ForwardResponseMessage forwards the message "resp" from gRPC server to REST client.
func ForwardResponseStream ¶
func ForwardResponseStream(ctx context.Context, w http.ResponseWriter, req *http.Request, recv func() (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 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 "filters".
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 HandlerFunc ¶
A HandlerFunc handles a specific pair of path pattern and HTTP method.
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() *ServeMux
NewServeMux returns a new MuxHandler whose internal mapping is empty.