{"modulePath":"github.com/swithek/httpflow","version":"v0.0.0-20210302114855-3975a26f6022","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package httpflow\n\nPackage httpflow provides helper functions and types to simplify work with HTTP requests.\n\n## Variables\n\n```go\nvar (\n\t// ErrUnauthorized is returned when authorization process fails.\n\tErrUnauthorized = NewError(nil, http.StatusUnauthorized, \"\")\n\n\t// ErrNotFound is returned when target resource is not found.\n\tErrNotFound = NewError(nil, http.StatusNotFound, \"\")\n\n\t// ErrMethodNotAllowed is returned when request's method is not\n\t// supported for the requested endpoint.\n\tErrMethodNotAllowed = NewError(nil, http.StatusMethodNotAllowed, \"\")\n)\n```\n\n```go\nvar (\n\t// ErrInvalidJSON is returned when request's body contains invalid\n\t// JSON data.\n\tErrInvalidJSON = NewError(nil, http.StatusBadRequest, \"invalid JSON body\")\n\n\t// ErrInvalidForm is returned when request's form contains invalid\n\t// JSON data.\n\tErrInvalidForm = NewError(nil, http.StatusBadRequest, \"invalid form data\")\n)\n```\n\n```go\nvar (\n\t// ErrInvalidFilterKey is returned when filter key is\n\t// determined to be invalid.\n\tErrInvalidFilterKey = NewError(nil, http.StatusBadRequest, \"invalid filter key\")\n\n\t// ErrInvalidSortKey is returned when sort key is\n\t// determined to be invalid.\n\tErrInvalidSortKey = NewError(nil, http.StatusBadRequest, \"invalid sort key\")\n)\n```\n\n## Functions\n\n```go\nfunc DecodeForm(r *http.Request, v interface{}) error\n```\nDecodeForm decodes request's form values into destination object.\n\n```go\nfunc DecodeJSON(r *http.Request, v interface{}) error\n```\nDecodeJSON decodes request's JSON body into destination object.\n\n```go\nfunc DetectError(err error) error\n```\nDetectError wraps the provided error with additional information useful for applications.\n\n```go\nfunc ErrorCode(err error) int\n```\nErrorCode returns status code associated with the error.\n\n```go\nfunc ErrorMessage(err error) string\n```\nErrorMessage returns message associated with the error.\n\n```go\nfunc ExtractIP(r *http.Request) (net.IP, error)\n```\nExtractIP extracts request origin's IP address.\n\n```go\nfunc ExtractParam(r *http.Request, p string) (string, error)\n```\nExtractParam extracts a value by the the provided parameter name from the URL.\n\n```go\nfunc ExtractSession(ctx context.Context) (sessionup.Session, xid.ID, error)\n```\nExtractSession checks whether the session is present and returns it as well as user's ID.\n\n```go\nfunc ExtractTargetID(r *http.Request) (xid.ID, error)\n```\nExtractTargetID extracts ID from the URL.\n\n```go\nfunc Location(loc string) func(http.Handler) http.Handler\n```\nLocation is a middleware that adds or expands location header. It will only execute after the next http handler completes. If the location header is already present, it is not possible to overwrite it, but you may use {loc} in the provided location string to embed the previous value into the new one:\n\n\t// Existing Location header: userID123\n\tLocation(\"/users/{loc}\") // header will be set to \"/users/userID123\"\n\n```go\nfunc MethodNotAllowed(log zerolog.Logger) http.HandlerFunc\n```\nMethodNotAllowed handles cases when request's method is not supported for the requested endpoint.\n\n```go\nfunc NewError(err error, code int, msg string, args ...interface{}) error\n```\nNewError creates a new status error by optionally wrapping another error.\n\n```go\nfunc NotFound(log zerolog.Logger) http.HandlerFunc\n```\nNotFound handles cases when request is sent to a non-existing endpoint.\n\n```go\nfunc Respond(log zerolog.Logger, w http.ResponseWriter, r *http.Request, data interface{}, code int)\n```\nRespond sends JSON type response to the client.\n\n```go\nfunc RespondError(log zerolog.Logger, w http.ResponseWriter, r *http.Request, err error)\n```\nRespondError sends the provided error in a JSON format to the client.\n\n```go\nfunc SessionReject(log zerolog.Logger) func(error) http.Handler\n```\nSessionReject should be used as sessionup's rejection function.\n\n## Types\n\n```go\ntype LinkKey string\n```\nLinkKey is used to access links in the map.\n\n```go\nconst (\n\tLinkActivation         LinkKey = \"activation\"\n\tLinkActivationCancel   LinkKey = \"activation_cancel\"\n\tLinkVerification       LinkKey = \"verification\"\n\tLinkVerificationCancel LinkKey = \"verification_cancel\"\n\tLinkRecovery           LinkKey = \"recovery\"\n\tLinkRecoveryCancel     LinkKey = \"recovery_cancel\"\n)\n```\nLink-prefixed constants define core link keys.\n\n```go\ntype Links struct {\n\t// contains filtered or unexported fields\n}\n```\nLinks holds a map of link strings ready to formatted and built with arguments. Useful for sending emails etc. Strings should abide standard rules of formatting, example: \"[http://yoursite.com/user/activ?token=%s](http://yoursite.com/user/activ?token=%s)\"\n\n```go\nfunc NewLinks(ll map[LinkKey]string) Links\n```\nNewLinks creates a new link store.\n\n```go\nfunc (l Links) Exist(kk ...LinkKey) bool\n```\nExist checks whether the links accessed by the specified keys exist or not.\n\n```go\nfunc (l Links) Prep(k LinkKey, args ...interface{}) string\n```\nPrep finds the link by the specified key and inserts all provided arguments into it (if allowed).\n\n```go\ntype Query struct {\n\t// Limit specifies the total amount of data elements per page.\n\tLimit uint64 `schema:\"count\"`\n\n\t// Page specifies data batch number.\n\tPage uint64 `schema:\"page\"`\n\n\t// FilterBy specifies a column by which filtering should be done.\n\t// If FilterVal is empty, no filtering should be done.\n\t// NOTE: should be checked before use.\n\tFilterBy string `schema:\"filter_by\"`\n\n\t// FilterVal specifies a string by which rows should be searched and\n\t// filtered.\n\tFilterVal string `schema:\"filter_val\"`\n\n\t// SortBy specifies which column should be used for sorting.\n\t// NOTE: should be checked before use.\n\tSortBy string `schema:\"sort_by\"`\n\n\t// Asc specifies whether ascending sorting order should be used.\n\tAsc bool `schema:\"asc\"`\n}\n```\nQuery is used to filter and retrieve bulk data from data stores.\n\n```go\nfunc (q Query) Validate(fck func(k, v string) error, sck func(k string) error) error\n```\nValidate checks whether query field values go out the bounds of sanity or not. First parameter should be filter key and value checking func, second - sort key checking func.\n\n","path":"github.com/swithek/httpflow","name":"httpflow","synopsis":"Package httpflow provides helper functions and types to simplify work with HTTP requests.","isRedistributable":true}
