{"modulePath":"github.com/mutablelogic/go-server","version":"v1.1.4","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package util\n\nThe \\`util\\` package provides utility methods for decoding request parameters and bodies, and providing responses over HTTP\n\n## Constants\n\n```go\nconst (\n\tContentTypeKey            = \"Content-Type\"\n\tContentLengthKey          = \"Content-Length\"\n\tContentTypeJSON           = \"application/json\"\n\tContentTypeText           = \"text/plain\"\n\tContentTypeMultipartForm  = \"multipart/form-data\"\n\tContentTypeUrlEncodedForm = \"application/x-www-form-urlencoded\"\n)\n```\n\n## Functions\n\n```go\nfunc ReqDecodeBody(req *http.Request, v interface{}) ([]string, error)\n```\nDecode a request body into a struct, and return the fields which were decoded.\n\n```go\nfunc ReqPrefixPathParams(req *http.Request) (string, string, []string)\n```\nReturn prefix and parameters from a request\n\n```go\nfunc RequestBodyForm(req *http.Request, params map[string]string, v interface{}) ([]string, error)\n```\nRequestBodyForm returns the body of a request as a struct where the request is of type multipart/form-data\n\n```go\nfunc RequestBodyJSON(req *http.Request, v interface{}) ([]string, error)\n```\nRequestBodyJSON returns the body of a request as a struct where the request is of type application/json\n\n```go\nfunc RequestBodyPost(req *http.Request, v interface{}) ([]string, error)\n```\nRequestBodyPost returns the body of a request as a struct where the request is of type application/x-www-form-urlencoded\n\n```go\nfunc ServeEmpty(w http.ResponseWriter, code uint)\n```\nServeEmpty is a utility function to serve an empty response\n\n```go\nfunc ServeError(w http.ResponseWriter, code uint, reason ...string) error\n```\nServeError is a utility function to serve a JSON error notice\n\n```go\nfunc ServeJSON(w http.ResponseWriter, v interface{}, code, indent uint) error\n```\nServeJSON is a utility function to serve an arbitary object as JSON\n\n```go\nfunc ServeText(w http.ResponseWriter, v string, code uint)\n```\nServeText is a utility function to serve plaintext\n\n## Types\n\n```go\ntype ErrorResponse struct {\n\tCode   uint   `json:\"code\"`\n\tReason string `json:\"reason,omitempty\"`\n}\n```\nErrorResponse is a generic error response which is served as JSON using the ServeError method\n\n","path":"github.com/mutablelogic/go-server/pkg/httpserver/util","name":"util","synopsis":"The `util` package provides utility methods for decoding request parameters and bodies, and providing responses over HTTP","isRedistributable":true}
