Documentation
¶
Overview ¶
Package parameters parses json, msg pack, or multi-part form data into a parameters object
Index ¶
- Constants
- Variables
- func CORSHeaders(fn http.HandlerFunc) httprouter.Handle
- func CamelToSnakeCase(str string) string
- func EnableGZIP(fn httprouter.Handle) httprouter.Handle
- func GeneralJSONResponse(fn http.HandlerFunc) httprouter.Handle
- func GeneralResponse(fn http.HandlerFunc) httprouter.Handle
- func JSONResp(fn httprouter.Handle) httprouter.Handle
- func MakeFirstUpperCase(s string) string
- func MakeHTTPRouterParsedReq(fn httprouter.Handle) httprouter.Handle
- func MakeParsedReq(fn http.HandlerFunc) http.HandlerFunc
- func SendCORS(w http.ResponseWriter, req *http.Request)
- func SnakeToCamelCase(str string, ucFirst bool) string
- func UniqueUint64(in []uint64) []uint64
- type CustomTypeHandler
- type Params
- func (p *Params) Clone() *Params
- func (p *Params) Get(key string) (val interface{}, ok bool)
- func (p *Params) GetBool(key string) bool
- func (p *Params) GetBoolOk(key string) (bool, bool)
- func (p *Params) GetBytes(key string) []byte
- func (p *Params) GetBytesOk(key string) ([]byte, bool)
- func (p *Params) GetFileOk(key string) (*multipart.FileHeader, bool)
- func (p *Params) GetFloat(key string) float64
- func (p *Params) GetFloatOk(key string) (float64, bool)
- func (p *Params) GetFloatSlice(key string) []float64
- func (p *Params) GetFloatSliceOk(key string) ([]float64, bool)
- func (p *Params) GetInt(key string) int
- func (p *Params) GetInt16(key string) int16
- func (p *Params) GetInt16Ok(key string) (int16, bool)
- func (p *Params) GetInt32(key string) int32
- func (p *Params) GetInt32Ok(key string) (int32, bool)
- func (p *Params) GetInt64(key string) int64
- func (p *Params) GetInt64Ok(key string) (int64, bool)
- func (p *Params) GetInt8(key string) int8
- func (p *Params) GetInt8Ok(key string) (int8, bool)
- func (p *Params) GetIntOk(key string) (int, bool)
- func (p *Params) GetIntSlice(key string) []int
- func (p *Params) GetIntSliceOk(key string) ([]int, bool)
- func (p *Params) GetJSON(key string) map[string]interface{}
- func (p *Params) GetJSONOk(key string) (map[string]interface{}, bool)
- func (p *Params) GetString(key string) string
- func (p *Params) GetStringOk(key string) (string, bool)
- func (p *Params) GetStringSlice(key string) []string
- func (p *Params) GetStringSliceOk(key string) ([]string, bool)
- func (p *Params) GetTime(key string) time.Time
- func (p *Params) GetTimeInLocation(key string, loc *time.Location) time.Time
- func (p *Params) GetTimeInLocationOk(key string, loc *time.Location) (time.Time, bool)
- func (p *Params) GetTimeOk(key string) (time.Time, bool)
- func (p *Params) GetUint64(key string) uint64
- func (p *Params) GetUint64Ok(key string) (uint64, bool)
- func (p *Params) GetUint64Slice(key string) []uint64
- func (p *Params) GetUint64SliceOk(key string) ([]uint64, bool)
- func (p *Params) HasAll(keys ...string) (bool, []string)
- func (p *Params) Imbue(obj interface{})
- func (p *Params) Permit(allowedKeys []string)
Examples ¶
Constants ¶
const ( // ParamsKeyName standard key name for parameter data ParamsKeyName paramKey = "params" // DateOnly is only the date DateOnly = "2006-01-02" // DateTime is not recommended, rather use time.RFC3339 DateTime = "2006-01-02 15:04:05" // HTMLDateTimeLocal is the format used by the input type datetime-local HTMLDateTimeLocal = "2006-01-02T15:04" // MaxSafeInt is the maximum safe integer value MaxSafeInt = 1 << 53 // 9007199254740992 )
Constants for parameters package
const FilteredValue = "FILTERED"
FilteredValue is the value to replace filtered keys with
const Origin = "Origin"
Origin is the header key for the origin
Variables ¶
var FilteredKeys []string
FilteredKeys is a lower case array of keys to filter when logging
var KnownAbbreviations = []string{"id", "json", "html", "xml"}
KnownAbbreviations contains lower case versions of abbreviations to match. Any entry in this list will become full upper case when converting from snake_case to camelCase
user_id -> UserID
Functions ¶
func CORSHeaders ¶
func CORSHeaders(fn http.HandlerFunc) httprouter.Handle
CORSHeaders adds cross-origin resource sharing headers to a response
func CamelToSnakeCase ¶
CamelToSnakeCase converts CamelCase to snake_case Consecutive capital letters will be treated as one word:
HTML -> html
func EnableGZIP ¶
func EnableGZIP(fn httprouter.Handle) httprouter.Handle
EnableGZIP will attempt to compress the response if the client has passed a header value for Accept-Encoding which allows gzip
func GeneralJSONResponse ¶
func GeneralJSONResponse(fn http.HandlerFunc) httprouter.Handle
GeneralJSONResponse calls the default wrappers for a json response: EnableGZIP, JSONResp, MakeHTTPRouterParsedReq, CORSHeaders
func GeneralResponse ¶
func GeneralResponse(fn http.HandlerFunc) httprouter.Handle
GeneralResponse calls the default wrappers: EnableGZIP, MakeHTTPRouterParsedReq, CORSHeaders
func JSONResp ¶
func JSONResp(fn httprouter.Handle) httprouter.Handle
JSONResp will set the content-type to application/json
func MakeFirstUpperCase ¶
MakeFirstUpperCase upper cases the first letter of the string
func MakeHTTPRouterParsedReq ¶
func MakeHTTPRouterParsedReq(fn httprouter.Handle) httprouter.Handle
MakeHTTPRouterParsedReq make http router parsed request
func MakeParsedReq ¶
func MakeParsedReq(fn http.HandlerFunc) http.HandlerFunc
MakeParsedReq make parsed request
func SendCORS ¶
func SendCORS(w http.ResponseWriter, req *http.Request)
SendCORS sends a cross-origin resource sharing header only
func SnakeToCamelCase ¶
SnakeToCamelCase converts snake_case to CamelCase. When:
ucFirst = false - snake_case -> snakeCase ucFirst = true - snake_case -> SnakeCase
func UniqueUint64 ¶
UniqueUint64 removes duplicates from uint64 arrays
Example ¶
ExampleUniqueUint64 shows an example using the method
one := []uint64{3, 2, 1, 3, 3, 3, 3} unique := UniqueUint64(one) fmt.Println(unique)
Output: [3 2 1]
Types ¶
type CustomTypeHandler ¶
CustomTypeHandler custom type handler
var CustomTypeSetter CustomTypeHandler
CustomTypeSetter is used when Imbue is called on an object to handle unknown types
type Params ¶
type Params struct { Values map[string]interface{} // contains filtered or unexported fields }
Params is the parameter values
func FilterMap ¶ added in v0.0.4
FilterMap will filter the parameters and not log parameters with sensitive data. To add more parameters to filter, add the key to the FilteredKeys array
func (*Params) GetBytesOk ¶
GetBytesOk get param by key, return slice of bytes
func (*Params) GetFileOk ¶
func (p *Params) GetFileOk(key string) (*multipart.FileHeader, bool)
GetFileOk get param by key, return file
func (*Params) GetFloatOk ¶
GetFloatOk get param by key, return float
func (*Params) GetFloatSlice ¶
GetFloatSlice get param by key, return slice of floats
func (*Params) GetFloatSliceOk ¶
GetFloatSliceOk get param by key, return slice of floats
func (*Params) GetInt16Ok ¶
GetInt16Ok get param by key, return integer
func (*Params) GetInt32Ok ¶
GetInt32Ok get param by key, return integer
func (*Params) GetInt64Ok ¶
GetInt64Ok get param by key, return integer
func (*Params) GetIntSlice ¶
GetIntSlice get param by key, return slice of integers
func (*Params) GetIntSliceOk ¶
GetIntSliceOk get param by key, return slice of integers
func (*Params) GetStringOk ¶
GetStringOk get param by key, return string
func (*Params) GetStringSlice ¶
GetStringSlice get param by key, return slice of strings
func (*Params) GetStringSliceOk ¶
GetStringSliceOk get param by key, return slice of strings
func (*Params) GetTimeInLocation ¶
GetTimeInLocation get param by key, return time
func (*Params) GetTimeInLocationOk ¶
GetTimeInLocationOk get param by key, return time
func (*Params) GetUint64Ok ¶
GetUint64Ok get param by key, return unsigned integer
func (*Params) GetUint64Slice ¶
GetUint64Slice get param by key, return slice of unsigned integers
func (*Params) GetUint64SliceOk ¶
GetUint64SliceOk get param by key, return slice of unsigned integers