parameters

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2019 License: GPL-3.0 Imports: 20 Imported by: 1

README

Build Status

// usage:
//   1) parse json to parameters:
// parameters.MakeParsedReq(fn http.HandlerFunc)
//   2) get the parameters:
// params := parameters.GetParams(req)
// val := params.GetXXX("key")

Documentation

Overview

Package parameters parses json, msg pack, or multi-part form data into a parameters object

Index

Constants

View Source
const (
	// ParametersKeyName standard key name for parameter data
	ParametersKeyName 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"
)

Constants for parameters package

Variables

View Source
var FilteredKeys []string

FilteredKeys is a lower case array of keys to filter when logging

View Source
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

func CamelToSnakeCase(str string) string

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

func MakeFirstUpperCase(s string) string

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

func SnakeToCamelCase(str string, ucFirst bool) string

SnakeToCamelCase converts snake_case to CamelCase. When:

ucFirst = false - snake_case -> snakeCase
ucFirst = true  - snake_case -> SnakeCase

func UniqueUint64

func UniqueUint64(in []uint64) []uint64

UniqueUint64 removes duplicates from uint64 arrays

Types

type CustomTypeHandler

type CustomTypeHandler func(field *reflect.Value, value interface{})

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 GetParams

func GetParams(req *http.Request) *Params

GetParams get parameters

func ParseParams

func ParseParams(req *http.Request) *Params

ParseParams parse parameters

func (*Params) Clone

func (p *Params) Clone() *Params

Clone makes a copy of this params object

func (*Params) Get

func (p *Params) Get(key string) (interface{}, bool)

Get the param by key, return interface

func (*Params) GetBool

func (p *Params) GetBool(key string) bool

GetBool get param by key, return boolean

func (*Params) GetBoolOk

func (p *Params) GetBoolOk(key string) (bool, bool)

GetBoolOk get param by key, return boolean

func (*Params) GetBytes

func (p *Params) GetBytes(key string) []byte

GetBytes get param by key, return slice of bytes

func (*Params) GetBytesOk

func (p *Params) GetBytesOk(key string) ([]byte, bool)

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) GetFloat

func (p *Params) GetFloat(key string) float64

GetFloat get param by key, return float

func (*Params) GetFloatOk

func (p *Params) GetFloatOk(key string) (float64, bool)

GetFloatOk get param by key, return float

func (*Params) GetFloatSlice

func (p *Params) GetFloatSlice(key string) []float64

GetFloatSlice get param by key, return slice of floats

func (*Params) GetFloatSliceOk

func (p *Params) GetFloatSliceOk(key string) ([]float64, bool)

GetFloatSliceOk get param by key, return slice of floats

func (*Params) GetInt

func (p *Params) GetInt(key string) int

GetInt get param by key, return integer

func (*Params) GetInt16

func (p *Params) GetInt16(key string) int16

GetInt16 get param by key, return integer

func (*Params) GetInt16Ok

func (p *Params) GetInt16Ok(key string) (int16, bool)

GetInt16Ok get param by key, return integer

func (*Params) GetInt32

func (p *Params) GetInt32(key string) int32

GetInt32 get param by key, return integer

func (*Params) GetInt32Ok

func (p *Params) GetInt32Ok(key string) (int32, bool)

GetInt32Ok get param by key, return integer

func (*Params) GetInt64

func (p *Params) GetInt64(key string) int64

GetInt64 get param by key, return integer

func (*Params) GetInt64Ok

func (p *Params) GetInt64Ok(key string) (int64, bool)

GetInt64Ok get param by key, return integer

func (*Params) GetInt8

func (p *Params) GetInt8(key string) int8

GetInt8 get param by key, return integer

func (*Params) GetInt8Ok

func (p *Params) GetInt8Ok(key string) (int8, bool)

GetInt8Ok get param by key, return integer

func (*Params) GetIntOk

func (p *Params) GetIntOk(key string) (int, bool)

GetIntOk get param by key, return integer

func (*Params) GetIntSlice

func (p *Params) GetIntSlice(key string) []int

GetIntSlice get param by key, return slice of integers

func (*Params) GetIntSliceOk

func (p *Params) GetIntSliceOk(key string) ([]int, bool)

GetIntSliceOk get param by key, return slice of integers

func (*Params) GetJSON

func (p *Params) GetJSON(key string) map[string]interface{}

GetJSON get param by key, return map of string interface

func (*Params) GetJSONOk

func (p *Params) GetJSONOk(key string) (map[string]interface{}, bool)

GetJSONOk get param by key, return map of string interface

func (*Params) GetString

func (p *Params) GetString(key string) string

GetString get param by key, return string

func (*Params) GetStringOk

func (p *Params) GetStringOk(key string) (string, bool)

GetStringOk get param by key, return string

func (*Params) GetStringSlice

func (p *Params) GetStringSlice(key string) []string

GetStringSlice get param by key, return slice of strings

func (*Params) GetStringSliceOk

func (p *Params) GetStringSliceOk(key string) ([]string, bool)

GetStringSliceOk get param by key, return slice of strings

func (*Params) GetTime

func (p *Params) GetTime(key string) time.Time

GetTime get param by key, return time

func (*Params) GetTimeInLocation

func (p *Params) GetTimeInLocation(key string, loc *time.Location) time.Time

GetTimeInLocation get param by key, return time

func (*Params) GetTimeInLocationOk

func (p *Params) GetTimeInLocationOk(key string, loc *time.Location) (time.Time, bool)

GetTimeInLocationOk get param by key, return time

func (*Params) GetTimeOk

func (p *Params) GetTimeOk(key string) (time.Time, bool)

GetTimeOk get param by key, return time

func (*Params) GetUint64

func (p *Params) GetUint64(key string) uint64

GetUint64 get param by key, return unsigned integer

func (*Params) GetUint64Ok

func (p *Params) GetUint64Ok(key string) (uint64, bool)

GetUint64Ok get param by key, return unsigned integer

func (*Params) GetUint64Slice

func (p *Params) GetUint64Slice(key string) []uint64

GetUint64Slice get param by key, return slice of unsigned integers

func (*Params) GetUint64SliceOk

func (p *Params) GetUint64SliceOk(key string) ([]uint64, bool)

GetUint64SliceOk get param by key, return slice of unsigned integers

func (*Params) HasAll

func (p *Params) HasAll(keys ...string) (bool, []string)

HasAll will return if all specified keys are found in the params object

func (*Params) Imbue

func (p *Params) Imbue(obj interface{})

Imbue sets the parameters to the object by type; does not handle nested parameters

func (*Params) Permit

func (p *Params) Permit(allowedKeys []string)

Permit permits only the allowed fields given by allowedKeys

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL