Documentation ¶
Overview ¶
Package httpflow provides helper functions and types to simplify work with HTTP requests.
Index ¶
- Variables
- func DecodeForm(r *http.Request, v interface{}) error
- func DecodeJSON(r *http.Request, v interface{}) error
- func DetectError(err error) error
- func ErrorCode(err error) int
- func ErrorMessage(err error) string
- func ExtractIP(r *http.Request) (net.IP, error)
- func ExtractParam(r *http.Request, p string) (string, error)
- func ExtractSession(ctx context.Context) (sessionup.Session, xid.ID, error)
- func ExtractTargetID(r *http.Request) (xid.ID, error)
- func Location(loc string) func(http.Handler) http.Handler
- func MethodNotAllowed(log zerolog.Logger) http.HandlerFunc
- func NewError(err error, code int, msg string, args ...interface{}) error
- func NotFound(log zerolog.Logger) http.HandlerFunc
- func Respond(log zerolog.Logger, w http.ResponseWriter, r *http.Request, data interface{}, ...)
- func RespondError(log zerolog.Logger, w http.ResponseWriter, r *http.Request, err error)
- func SessionReject(log zerolog.Logger) func(error) http.Handler
- type LinkKey
- type Links
- type Query
Constants ¶
This section is empty.
Variables ¶
var ( NewError(nil, http.StatusUnauthorized, "") // ErrNotFound is returned when target resource is not found. ErrNotFound = NewError(nil, http.StatusNotFound, "") // ErrMethodNotAllowed is returned when request's method is not // supported for the requested endpoint. ErrMethodNotAllowed = NewError(nil, http.StatusMethodNotAllowed, "") )ErrUnauthorized =
var ( // ErrInvalidJSON is returned when request's body contains invalid // JSON data. ErrInvalidJSON = NewError(nil, http.StatusBadRequest, "invalid JSON body") // ErrInvalidForm is returned when request's form contains invalid // JSON data. ErrInvalidForm = NewError(nil, http.StatusBadRequest, "invalid form data") )
var ( // ErrInvalidFilterKey is returned when filter key is // determined to be invalid. ErrInvalidFilterKey = NewError(nil, http.StatusBadRequest, "invalid filter key") // ErrInvalidSortKey is returned when sort key is // determined to be invalid. ErrInvalidSortKey = NewError(nil, http.StatusBadRequest, "invalid sort key") )
Functions ¶
func DecodeForm ¶
DecodeForm decodes request's form values into destination object.
func DecodeJSON ¶
DecodeJSON decodes request's JSON body into destination object.
func DetectError ¶
DetectError wraps the provided error with additional information useful for applications.
func ErrorMessage ¶
ErrorMessage returns message associated with the error.
func ExtractParam ¶
ExtractParam extracts a value by the the provided parameter name from the URL.
func ExtractSession ¶
ExtractSession checks whether the session is present and returns it as well as user's ID.
func ExtractTargetID ¶
ExtractTargetID extracts ID from the URL.
func Location ¶
Location 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:
// Existing Location header: userID123 Location("/users/{loc}") // header will be set to "/users/userID123"
func MethodNotAllowed ¶
func MethodNotAllowed(log zerolog.Logger) http.HandlerFunc
MethodNotAllowed handles cases when request's method is not supported for the requested endpoint.
func NotFound ¶
func NotFound(log zerolog.Logger) http.HandlerFunc
NotFound handles cases when request is sent to a non-existing endpoint.
func Respond ¶
func Respond(log zerolog.Logger, w http.ResponseWriter, r *http.Request, data interface{}, code int)
Respond sends JSON type response to the client.
func RespondError ¶
RespondError sends the provided error in a JSON format to the client.
Types ¶
type LinkKey ¶
type LinkKey string
LinkKey is used to access links in the map.
const ( LinkActivation LinkKey = "activation" LinkActivationCancel LinkKey = "activation_cancel" LinkVerification LinkKey = "verification" LinkVerificationCancel LinkKey = "verification_cancel" LinkRecovery LinkKey = "recovery" LinkRecoveryCancel LinkKey = "recovery_cancel" )
Link-prefixed constants define core link keys.
type Links ¶
type Links struct {
// contains filtered or unexported fields
}
Links 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"
type Query ¶
type Query struct { // Limit specifies the total amount of data elements per page. Limit uint64 `schema:"count"` // Page specifies data batch number. Page uint64 `schema:"page"` // FilterBy specifies a column by which filtering should be done. // If FilterVal is empty, no filtering should be done. // NOTE: should be checked before use. FilterBy string `schema:"filter_by"` // FilterVal specifies a string by which rows should be searched and // filtered. FilterVal string `schema:"filter_val"` // SortBy specifies which column should be used for sorting. // NOTE: should be checked before use. SortBy string `schema:"sort_by"` // Asc specifies whether ascending sorting order should be used. Asc bool `schema:"asc"` }
Query is used to filter and retrieve bulk data from data stores.
Directories ¶
Path | Synopsis |
---|---|
Package email provides email sending functionality.
|
Package email provides email sending functionality. |
Package logutil provides helper functions for more convenient logging and error tracking.
|
Package logutil provides helper functions for more convenient logging and error tracking. |
Package testutil implements helper functions for more convenient testing and may be imported in '_test.go' files only.
|
Package testutil implements helper functions for more convenient testing and may be imported in '_test.go' files only. |
Package timeutil implements helper functions for time-related logic which extends the functionality of the standard time package.
|
Package timeutil implements helper functions for time-related logic which extends the functionality of the standard time package. |
Package user provides user data handling functionality.
|
Package user provides user data handling functionality. |
postgres
Package postgres provides functionality for interaction with postgres database.
|
Package postgres provides functionality for interaction with postgres database. |