parameters

package module
v0.0.0-...-fb58ff8 Latest Latest
Warning

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

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

README

Build Status

Documentation

Overview

Package parameters parses json into parameters object usage:

  1. parse json to parameters:

parameters.MakeParsedReq(fn http.HandlerFunc)

  1. get the parameters:

params := parameters.GetParams(req) val := params.GetXXX("key")

Index

Constants

View Source
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"
)
View Source
const (
	ParamsKey = "params"
)

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

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

func MakeFirstUpperCase(s string) string

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

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{})
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
}

func GetParams

func GetParams(req *http.Request) *Params

func ParseParams

func ParseParams(req *http.Request) *Params

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)

func (*Params) GetBool

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

func (*Params) GetBoolOk

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

func (*Params) GetBytes

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

func (*Params) GetBytesOk

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

func (*Params) GetFileOk

func (p *Params) GetFileOk(key string) (*multipart.FileHeader, bool)

func (*Params) GetFloat

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

func (*Params) GetFloatOk

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

func (*Params) GetFloatSlice

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

func (*Params) GetFloatSliceOk

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

func (*Params) GetInt

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

func (*Params) GetInt16

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

func (*Params) GetInt16Ok

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

func (*Params) GetInt32

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

func (*Params) GetInt32Ok

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

func (*Params) GetInt64

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

func (*Params) GetInt64Ok

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

func (*Params) GetInt8

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

func (*Params) GetInt8Ok

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

func (*Params) GetIntOk

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

func (*Params) GetIntSlice

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

func (*Params) GetIntSliceOk

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

func (*Params) GetJSON

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

func (*Params) GetJSONOk

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

func (*Params) GetString

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

func (*Params) GetStringOk

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

func (*Params) GetStringSlice

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

func (*Params) GetStringSliceOk

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

func (*Params) GetTime

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

func (*Params) GetTimeInLocation

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

func (*Params) GetTimeInLocationOk

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

func (*Params) GetTimeOk

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

func (*Params) GetUint64

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

func (*Params) GetUint64Ok

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

func (*Params) GetUint64Slice

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

func (*Params) GetUint64SliceOk

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

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{})

Sets the parameters to the object by type; does not handle nested parameters

func (*Params) Permit

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

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