Documentation
¶
Overview ¶
Package parameters parses json into parameters object usage:
- parse json to parameters:
parameters.MakeParsedReq(fn http.HandlerFunc)
- get the parameters:
params := parameters.GetParams(req) val := params.GetXXX("key")
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) Get(key string) (interface{}, 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)
Constants ¶
const ( 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" )
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
GeneralJSONRequest calls the default wrappers for a json response: EnableGZIP, JSONResp, LogRequest, CORSHeaders
func GeneralResponse ¶
func GeneralResponse(fn http.HandlerFunc) httprouter.Handle
GeneralResponse calls the default wrappers: EnableGZIP, LogRequest, 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
func MakeParsedReq ¶
func MakeParsedReq(fn http.HandlerFunc) http.HandlerFunc
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
Types ¶
type CustomTypeHandler ¶
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 }