runtime

package
v0.0.0-...-f647940 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2016 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package runtime contains runtime helper functions used by servers which protoc-gen-grpc-gateway generates.

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
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

func AnnotateContext(ctx context.Context, req *http.Request) context.Context

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 Bool

func Bool(val string) (bool, error)

Bool converts the given string representation of a boolean value into bool.

func BoolP

func BoolP(val string) (*bool, error)

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

func Float32(val string) (float32, error)

Float32 converts the given string representation of a floating point number into float32.

func Float32P

func Float32P(val string) (*float32, error)

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

func Float64(val string) (float64, error)

Float64 converts the given string representation into representation of a floating point number into float64.

func Float64P

func Float64P(val string) (*float64, error)

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, 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, 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

func HTTPStatusFromCode(code codes.Code) int

HTTPStatusFromCode converts a gRPC error code into the corresponding HTTP response status.

func Int32

func Int32(val string) (int32, error)

Int32 converts the given string representation of an integer into int32.

func Int32P

func Int32P(val string) (*int32, error)

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 Int64

func Int64(val string) (int64, error)

Int64 converts the given string representation of an integer into int64.

func Int64P

func Int64P(val string) (*int64, error)

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

func PopulateFieldFromPath(msg proto.Message, fieldPathString string, value string) error

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 String

func String(val string) (string, error)

String just returns the given string. It is just for compatibility to other types.

func StringP

func StringP(val string) (*string, error)

StringP returns a pointer to a string whose pointee is same as the given string value.

func Uint32

func Uint32(val string) (uint32, error)

Uint32 converts the given string representation of an integer into uint32.

func Uint32P

func Uint32P(val string) (*uint32, error)

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 Uint64

func Uint64(val string) (uint64, error)

Uint64 converts the given string representation of an integer into uint64.

func Uint64P

func Uint64P(val string) (*uint64, error)

Uint64P parses the given string representation of an integer and returns a pointer to a uint64 whose value is same as the parsed integer.

Types

type HandlerFunc

type HandlerFunc func(w http.ResponseWriter, r *http.Request, pathParams map[string]string)

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

func MustPattern(p Pattern, err error) Pattern

MustPattern is a helper function which makes it easier to call NewPattern in variable initialization.

func NewPattern

func NewPattern(version int, ops []int, pool []string, verb string) (Pattern, error)

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

func (p Pattern) Match(components []string, verb string) (map[string]string, error)

Match examines components if it matches to the Pattern. If it matches, the function returns a mapping from field paths to their captured values. If otherwise, the function returns an error.

func (Pattern) String

func (p Pattern) String() string

func (Pattern) Verb

func (p Pattern) Verb() string

Verb returns the verb part of the Pattern.

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 MuxHandler 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) ServeHTTP

func (s *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP dispatches the request to the first handler whose pattern matches to r.Method and r.Path.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL