Documentation ¶
Overview ¶
The `util` package provides utility methods for decoding request parameters and bodies, and providing responses over HTTP
Index ¶
- Constants
- func ReqDecodeBody(req *http.Request, v interface{}) ([]string, error)
- func ReqPrefixPathParams(req *http.Request) (string, string, []string)
- func RequestBodyForm(req *http.Request, params map[string]string, v interface{}) ([]string, error)
- func RequestBodyJSON(req *http.Request, v interface{}) ([]string, error)
- func RequestBodyPost(req *http.Request, v interface{}) ([]string, error)
- func ServeEmpty(w http.ResponseWriter, code uint)
- func ServeError(w http.ResponseWriter, code uint, reason ...string) error
- func ServeJSON(w http.ResponseWriter, v interface{}, code, indent uint) error
- func ServeText(w http.ResponseWriter, v string, code uint)
- type ErrorResponse
Constants ¶
const ( ContentTypeKey = "Content-Type" ContentLengthKey = "Content-Length" ContentTypeJSON = "application/json" ContentTypeText = "text/plain" ContentTypeMultipartForm = "multipart/form-data" ContentTypeUrlEncodedForm = "application/x-www-form-urlencoded" )
Variables ¶
This section is empty.
Functions ¶
func ReqDecodeBody ¶
Decode a request body into a struct, and return the fields which were decoded.
func ReqPrefixPathParams ¶
Return prefix and parameters from a request
func RequestBodyForm ¶
RequestBodyForm returns the body of a request as a struct where the request is of type multipart/form-data
func RequestBodyJSON ¶
RequestBodyJSON returns the body of a request as a struct where the request is of type application/json
func RequestBodyPost ¶
RequestBodyPost returns the body of a request as a struct where the request is of type application/x-www-form-urlencoded
func ServeEmpty ¶
func ServeEmpty(w http.ResponseWriter, code uint)
ServeEmpty is a utility function to serve an empty response
func ServeError ¶
func ServeError(w http.ResponseWriter, code uint, reason ...string) error
ServeError is a utility function to serve a JSON error notice
Types ¶
type ErrorResponse ¶
ErrorResponse is a generic error response which is served as JSON using the ServeError method