Documentation ¶
Index ¶
- Constants
- Variables
- func Accept(next http.Handler) http.Handler
- func ContentType(next http.Handler) http.Handler
- func Match(body io.Reader) bool
- func Metadata(next http.Handler) http.Handler
- func PrepareMediaType(name string, r *http.Request)
- func SetMediaType(name string, r *http.Request)
- type ErrorHandlerFunc
- type FormDecoder
- type FormMarshaler
- func (m *FormMarshaler) ContentType(_ interface{}) string
- func (m *FormMarshaler) Marshal(v interface{}) ([]byte, error)
- func (m *FormMarshaler) NewDecoder(r io.Reader) runtime.Decoder
- func (m *FormMarshaler) NewEncoder(w io.Writer) runtime.Encoder
- func (m *FormMarshaler) Unmarshal(data []byte, v interface{}) error
- type HeaderMatcherFunc
- type Proxy
- func (proxy *Proxy) OnError(fn runtime.ErrorHandlerFunc)
- func (proxy *Proxy) Router() chi.Router
- func (proxy *Proxy) Serve(mux cmux.CMux) error
- func (proxy *Proxy) Shutdown(ctx context.Context) error
- func (proxy *Proxy) Use(fn ProxyHandlerFunc)
- func (proxy *Proxy) UseDialOption(opt grpc.DialOption)
- func (proxy *Proxy) WithErrorHandler() runtime.ServeMuxOption
- type ProxyHandlerFunc
- type ServeMuxOption
Constants ¶
const ( // ContentTypeAll is the '*/*' type ContentTypeAll = "*/*" // ContentTypeForm is the form url encoded ContentTypeForm = "application/x-www-form-urlencoded" // ContentTypeGRPC represents 'application/grpc' content-type ContentTypeGRPCProto = "application/grpc" // ContentTypeGRPC represents 'application/grpc' content-type ContentTypeGRPCJSON = "application/grpc+json" // ContentTypeJSON represents 'application/json' content-type ContentTypeJSON = "application/json" )
Variables ¶
var ( // WithFormMarshaler allows marshaling application/x-www-form-urlencoded requests WithFormMarshaler = runtime.WithMarshalerOption(ContentTypeForm, &runtime.HTTPBodyMarshaler{ Marshaler: &FormMarshaler{}, }) // WithJSONMarshaler allows marshaling application/json requests WithJSONMarshaler = runtime.WithMarshalerOption(ContentTypeJSON, &runtime.HTTPBodyMarshaler{ Marshaler: &runtime.JSONPb{ MarshalOptions: protojson.MarshalOptions{ UseProtoNames: true, }, UnmarshalOptions: protojson.UnmarshalOptions{ DiscardUnknown: true, }, }, }) )
var ( // HeaderContentType represents a header Content-Type key HeaderContentType = textproto.CanonicalMIMEHeaderKey("Content-Type") // HeaderAccept represents a header Accept key HeaderAccept = textproto.CanonicalMIMEHeaderKey("Accept") )
var ( // 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. WithForwardResponseOption = runtime.WithForwardResponseOption // 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. WithIncomingHeaderMatcher = runtime.WithIncomingHeaderMatcher // 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. WithOutgoingHeaderMatcher = runtime.WithOutgoingHeaderMatcher // 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. WithMetadata = runtime.WithMetadata // WithErrorHandler returns a ServeMuxOption for passing metadata to a gRPC context. // // This can be used to handle an error as general proto message defined by gRPC. // The response including body and status is not backward compatible with the default error handler. // When this option is used, HTTPError and OtherErrorHandler are overwritten on initialization. WithErrorHandler = runtime.WithErrorHandler // WithDisablePathLengthFallback returns a ServeMuxOption for disable path length fallback. WithDisablePathLengthFallback = runtime.WithDisablePathLengthFallback // 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 // ProtoErrorHandler 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. WithStreamErrorHandler = runtime.WithStreamErrorHandler // WithMarshaler returns a ServeMuxOption which associates inbound and outbound // Marshalers to a MIME type in mux. WithMarshaler = runtime.WithMarshalerOption )
var ( // AllIncomingHeaders allows the service to handle all incoming request AllIncomingHeaders = runtime.WithIncomingHeaderMatcher(preserve) // AllOutgoingHeaders allows the service to handle all incoming request AllOutgoingHeaders = runtime.WithOutgoingHeaderMatcher(preserve) // WithForwardResponse represents a forward response WithForwardResponse = runtime.WithForwardResponseOption(response) )
Functions ¶
func ContentType ¶
ContentType prepare the Content-Type header for underlying requests
func PrepareMediaType ¶
PrepareMediaType prepares a media type header
func SetMediaType ¶
SetMediaType sets the media type
Types ¶
type ErrorHandlerFunc ¶
type ErrorHandlerFunc = runtime.ErrorHandlerFunc
ErrorHandlerFunc handles the error as a gRPC error generated via status package and replies to the request.
type FormDecoder ¶
FormDecoder represents a form decoder
func (*FormDecoder) Decode ¶
func (d *FormDecoder) Decode(v interface{}) error
Decode decodes the request
type FormMarshaler ¶
type FormMarshaler struct{}
FormMarshaler defines a conversion between byte sequence and gRPC payloads / fields.
func (*FormMarshaler) ContentType ¶
func (m *FormMarshaler) ContentType(_ interface{}) string
ContentType returns the Content-Type which this marshaler is responsible for.
func (*FormMarshaler) Marshal ¶
func (m *FormMarshaler) Marshal(v interface{}) ([]byte, error)
Marshal marshals "v" into byte sequence.
func (*FormMarshaler) NewDecoder ¶
func (m *FormMarshaler) NewDecoder(r io.Reader) runtime.Decoder
NewDecoder returns a Decoder which reads byte sequence from "r".
func (*FormMarshaler) NewEncoder ¶
func (m *FormMarshaler) NewEncoder(w io.Writer) runtime.Encoder
NewEncoder returns an Encoder which writes bytes sequence into "w".
func (*FormMarshaler) Unmarshal ¶
func (m *FormMarshaler) Unmarshal(data []byte, v interface{}) error
Unmarshal unmarshals "data" into "v". "v" must be a pointer value.
type HeaderMatcherFunc ¶
type HeaderMatcherFunc = runtime.HeaderMatcherFunc
HeaderMatcherFunc checks whether a header key should be forwarded to/from gRPC context.
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
Proxy represents a http proxy to the server
func (*Proxy) OnError ¶
func (proxy *Proxy) OnError(fn runtime.ErrorHandlerFunc)
OnError handles response errors
func (*Proxy) UseDialOption ¶
func (proxy *Proxy) UseDialOption(opt grpc.DialOption)
UseDialOption uses specific dial option
func (*Proxy) WithErrorHandler ¶
func (proxy *Proxy) WithErrorHandler() runtime.ServeMuxOption
WithErrorHandler creates a error handler proxy
type ProxyHandlerFunc ¶
type ProxyHandlerFunc = func(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error
ProxyHandlerFunc handles the proxy call
type ServeMuxOption ¶
type ServeMuxOption = runtime.ServeMuxOption
ServeMuxOption is an option that can be given to a ServeMux on construction.