Documentation
¶
Index ¶
- Constants
- func FromRequestUri(req *http.Request) url.Valuesdeprecated
- func RequestWithUri(req *http.Request, uri url.Values) *http.Requestdeprecated
- type Encoding
- func (r *Encoding) Bind(req *http.Request, v any) error
- func (r *Encoding) BindQuery(req *http.Request, v any) error
- func (r *Encoding) BindURI(raws url.Values, v any) error
- func (r *Encoding) BindUri(req *http.Request, v any) errordeprecated
- func (r *Encoding) Delete(mime string) error
- func (r *Encoding) Encode(contentType string, v any) ([]byte, error)
- func (r *Encoding) EncodeQuery(v any) (url.Values, error)
- func (r *Encoding) EncodeURL(athTemplate string, msg any, needQuery bool) string
- func (r *Encoding) Get(mime string) codec.Marshaler
- func (r *Encoding) InboundForRequest(req *http.Request) (string, codec.Marshaler)
- func (r *Encoding) InboundForResponse(resp *http.Response) codec.Marshaler
- func (r *Encoding) OutboundForRequest(req *http.Request) codec.Marshaler
- func (r *Encoding) Register(mime string, marshaler codec.Marshaler) error
- func (r *Encoding) Render(w http.ResponseWriter, req *http.Request, v any) error
- type HTTPBodyCodec
Constants ¶
const ( // MIMEURI is special form query. MIMEQuery = "__MIME__/QUERY" // MIMEURI is special form uri. MIMEURI = "__MIME__/URI" // MIMEWildcard is the fallback special MIME type used for requests which do not match // a registered MIME type. MIMEWildcard = "*" MIMEJSON = "application/json" MIMEHTML = "text/html" MIMEXML = "application/xml" MIMEXML2 = "text/xml" MIMEPlain = "text/plain" MIMEPOSTForm = "application/x-www-form-urlencoded" MIMEMultipartPOSTForm = "multipart/form-data" MIMEPROTOBUF = "application/x-protobuf" MIMEMSGPACK = "application/x-msgpack" MIMEMSGPACK2 = "application/msgpack" MIMEYAML = "application/x-yaml" MIMETOML = "application/toml" )
Content-Type MIME of the most common data formats.
Variables ¶
This section is empty.
Functions ¶
func FromRequestUri
deprecated
func RequestWithUri
deprecated
RequestWithUri sets the URL variables for the given request, Arguments are not modified, a shallow copy is returned. URL variables can be set by making a route that captures the required variables, starting a server and sending the request to that server.
Deprecated: Because BindUri is deprecated.
Types ¶
type Encoding ¶
type Encoding struct {
// contains filtered or unexported fields
}
Encoding is a mapping from MIME types to Marshalers.
func (*Encoding) Bind ¶
Bind checks the Method and Content-Type to select codec.Marshaler automatically, Depending on the "Content-Type" header different bind are used, for example:
"application/json" --> JSON codec.Marshaler "application/xml" --> XML codec.Marshaler
It parses the request's body as JSON if Content-Type == "application/json" using JSON or XML as a JSON input. It decodes the json payload into the struct specified as a pointer.
func (*Encoding) BindQuery ¶
BindQuery binds the passed struct pointer using the query codec.Marshaler.
func (*Encoding) BindURI ¶ added in v0.1.0
BindUri binds the passed struct pointer using the uri codec.Marshaler.
func (*Encoding) Delete ¶
Delete remove the MIME type marshaler. MIMEWildcard, MIMEQuery, MIMEURI should be always exist and valid.
func (*Encoding) EncodeQuery ¶
EncodeQuery encode v to the query url.Values.
func (*Encoding) EncodeURL ¶
EncodeURL encode msg to url path. pathTemplate is a template of url path like http://helloworld.dev/{name}/sub/{sub.name},
func (*Encoding) Get ¶
Get returns the marshalers with a case-sensitive MIME type string It checks the MIME type on the Encoding. Otherwise, it follows the above logic for "*" Marshaler.
func (*Encoding) InboundForRequest ¶
InboundForRequest returns the inbound `Content-Type` and marshalers for this request. It checks the registry on the Encoding 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 "*" Marshaler.
func (*Encoding) InboundForResponse ¶ added in v0.0.2
InboundForResponse returns the inbound marshaler for this response. It checks the registry on the Encoding for the MIME type set by the `Content-Type` header. If it isn't set (or the response `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 "*" Marshaler.
func (*Encoding) OutboundForRequest ¶
OutboundForRequest returns the marshalers for this request. It checks the registry on the Encoding for the MIME type set by the `Accept` header. If it isn't set (or the request `Accept` is empty), checks for "*". If there are multiple `Accept` headers set, choose the first one that it can exactly match in the registry. Otherwise, it follows the above logic for "*" Marshaler.
func (*Encoding) Register ¶
Register a marshaler for a case-sensitive MIME type string ("*" to match any MIME type). you can override default marshaler with same MIME type
func (*Encoding) Render ¶
Render writes the response headers and calls the outbound marshalers for this request. It checks the registry on the Encoding for the MIME type set by the Accept header. If it isn't set (or the request Accept is empty), checks for "*". for example:
"application/json" --> JSON codec.Marshaler "application/xml" --> XML codec.Marshaler
If there are multiple Accept headers set, choose the first one that it can exactly match in the registry. Otherwise, it follows the above logic for "*" Marshaler.
type HTTPBodyCodec ¶
HTTPBodyCodec 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.
func (*HTTPBodyCodec) ContentType ¶
func (h *HTTPBodyCodec) ContentType(v any) string
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.