Documentation ¶
Overview ¶
Package web contains a handful of very useful functions for parsing types from request queries and payloads.
Index ¶
- Variables
- func GetInt64Var(r *http.Request, key string) int64
- func GetUInt64Var(r *http.Request, key string) uint64
- func ParseDateRange(vars map[string]string) (startDate time.Time, endDate time.Time, err error)
- func ParseDateRangeFullDay(vars map[string]string) (startDate time.Time, endDate time.Time, err error)
- func ParseISODate(dateStr string) (date time.Time, err error)
- func ParseTruthyFalsy(flag interface{}) (result bool, err error)
- func SetRouteVars(r *http.Request, val interface{})
- func Vars(r *http.Request) map[string]string
Constants ¶
This section is empty.
Variables ¶
var ( JSONContentType = "application/json; charset=UTF-8" DateISOFormat = "2006-01-02" )
Let's have generic errors for expected conditions. Typically these would be http.StatusBadRequest (400)
Functions ¶
func GetInt64Var ¶
GetInt64Var is a helper to pull gorilla mux Vars. If the value is empty, it falls back to the URL query string. We are ignoring the error here bc we're assuming the path had a [0-9]+ descriptor on this var.
func GetUInt64Var ¶
GetUInt64Var is a helper to pull gorilla mux Vars. If the value is empty, it falls back to the URL query string. We are ignoring the error here bc we're assuming the path had a [0-9]+ descriptor on this var.
func ParseDateRange ¶
ParseDateRange will look for and parse 'startDate' and 'endDate' ISO date strings in the given vars map.
func ParseDateRangeFullDay ¶
func ParseDateRangeFullDay(vars map[string]string) (startDate time.Time, endDate time.Time, err error)
ParseDateRangeFullDay will look for and parse 'startDate' and 'endDate' ISO date strings in the given vars map. It will then set the startDate time to midnight and the endDate time to 23:59:59.
func ParseISODate ¶
ParseISODate is a handy function to accept
func ParseTruthyFalsy ¶
ParseTruthyFalsy is a helper method to attempt to parse booleans in APIs that have no set contract on what a boolean should look like.
func SetRouteVars ¶
SetRouteVars will set the given value into into the request context with the shared 'vars' storage key.
Types ¶
This section is empty.