Documentation
¶
Index ¶
- Variables
- type Bool
- func (b *Bool) FormValue(value string, options interface{}) Errorable
- func (b *Bool) JSONValue(path string, i interface{}, options interface{}) Errorable
- func (b Bool) MarshalJSON() ([]byte, error)
- func (b *Bool) ParseOptions(tag reflect.StructTag) interface{}
- func (b Bool) Value() (driver.Value, error)
- type BoolOptions
- type Decoder
- func (d *Decoder) Decode(dest interface{}, values url.Values, b []byte) ErrorHash
- func (d *Decoder) DecodeJSON(dest interface{}, b []byte) ErrorHash
- func (d *Decoder) DecodeMap(dest interface{}, m map[string]interface{}) ErrorHash
- func (d *Decoder) DecodeValues(dest interface{}, values url.Values) ErrorHash
- func (d *Decoder) NewDecoded(values url.Values, r io.Reader) (interface{}, ErrorHash)
- func (d *Decoder) NewDecodedValues(values url.Values) (interface{}, ErrorHash)
- type DecoderField
- type DecoderOptions
- type ErrorAtom
- type ErrorHash
- type ErrorSlice
- type Errorable
- type Float64
- func (i *Float64) FormValue(value string, options interface{}) Errorable
- func (f *Float64) JSONValue(path string, i interface{}, options interface{}) Errorable
- func (i Float64) MarshalJSON() ([]byte, error)
- func (i *Float64) ParseOptions(tag reflect.StructTag) interface{}
- func (i Float64) Value() (driver.Value, error)
- type FloatOptions
- type Int64
- func (i *Int64) FormValue(value string, options interface{}) Errorable
- func (n *Int64) JSONValue(path string, i interface{}, options interface{}) Errorable
- func (i Int64) MarshalJSON() ([]byte, error)
- func (i *Int64) ParseOptions(tag reflect.StructTag) interface{}
- func (i Int64) Value() (driver.Value, error)
- type Int64Slice
- type IntOptions
- type IntSliceOptions
- type JsonLoader
- type Nullity
- type Optionaler
- type Presence
- type SliceOptions
- type String
- func (s *String) FormValue(value string, options interface{}) Errorable
- func (s *String) JSONValue(path string, i interface{}, options interface{}) Errorable
- func (s String) MarshalJSON() ([]byte, error)
- func (s *String) ParseOptions(tag reflect.StructTag) interface{}
- func (s String) Value() (driver.Value, error)
- type StringOptions
- type StringSlice
- type StringSliceOptions
- type Time
- func (t *Time) FormValue(value string, options interface{}) Errorable
- func (t *Time) JSONValue(path string, i interface{}, options interface{}) Errorable
- func (t Time) MarshalJSON() ([]byte, error)
- func (t *Time) ParseOptions(tag reflect.StructTag) interface{}
- func (t Time) Value() (driver.Value, error)
- type TimeOptions
- type Uint64
- func (i *Uint64) FormValue(value string, options interface{}) Errorable
- func (n *Uint64) JSONValue(path string, i interface{}, options interface{}) Errorable
- func (i Uint64) MarshalJSON() ([]byte, error)
- func (i *Uint64) ParseOptions(tag reflect.StructTag) interface{}
- func (i Uint64) Value() (driver.Value, error)
- type UintOptions
- type Valuer
Constants ¶
This section is empty.
Variables ¶
var ( ErrMalformed = ErrorAtom("malformed_json") ErrBlank = ErrorAtom("blank") ErrRequired = ErrorAtom("required") ErrMinRunes = ErrorAtom("min_runes") ErrMaxRunes = ErrorAtom("max_runes") ErrMaxBytes = ErrorAtom("max_bytes") ErrUtf8 = ErrorAtom("utf8") ErrBool = ErrorAtom("bool") ErrTime = ErrorAtom("time") ErrInt = ErrorAtom("int") ErrIntRange = ErrorAtom("int_range") ErrString = ErrorAtom("string") ErrFloat = ErrorAtom("float") ErrFloatRange = ErrorAtom("float_range") ErrMin = ErrorAtom("min") ErrMax = ErrorAtom("max") ErrIn = ErrorAtom("in") ErrMinLength = ErrorAtom("min_length") ErrMaxLength = ErrorAtom("max_length") )
var NameMapping = camelCaseToSnakeCase
Functions ¶
This section is empty.
Types ¶
type BoolOptions ¶
type Decoder ¶
type Decoder struct { StructType reflect.Type Fields []DecoderField Options DecoderOptions }
func NewDecoder ¶
func NewDecoder(destStruct interface{}) *Decoder
func NewDecoderWithOptions ¶
func NewDecoderWithOptions(destStruct interface{}, options DecoderOptions) *Decoder
func (*Decoder) DecodeJSON ¶
func (*Decoder) DecodeValues ¶
func (*Decoder) NewDecoded ¶
NewDecoded empties io.Reader and uses its []byte to create json source.
It is often common to call req.ParseForm() before calling this function to obtain url.Values from http request. Although ParseForm also reads http request body, it will only do so if the content type is either "application/x-www-form-urlencoded" or "multipart/form-data". Therefore, in this case, this function can handle both json and form-encoded input.
type DecoderField ¶
type DecoderField struct { Name string // key in the input Required bool DiscardInvalid bool Options interface{} Default string Doc string DocPattern string *SliceOptions StructDecoder *Decoder // If the field is a nested struct or a slice of nested structs, this is set to the decoder. // contains filtered or unexported fields }
type DecoderOptions ¶
type DecoderOptions struct {
TimeFormats []string
}
type ErrorHash ¶
type ErrorSlice ¶
type ErrorSlice []Errorable
func (ErrorSlice) Error ¶
func (ea ErrorSlice) Error() string
func (ErrorSlice) ErrorKind ¶
func (ea ErrorSlice) ErrorKind() string
type Float64 ¶
func NewFloat64 ¶
func (Float64) MarshalJSON ¶
func (*Float64) ParseOptions ¶
type FloatOptions ¶
type Int64Slice ¶
func (*Int64Slice) FormValue ¶
func (i *Int64Slice) FormValue(value string, options interface{}) Errorable
func (*Int64Slice) JSONValue ¶
func (n *Int64Slice) JSONValue(path string, i interface{}, options interface{}) Errorable
func (Int64Slice) MarshalJSON ¶
func (s Int64Slice) MarshalJSON() ([]byte, error)
func (*Int64Slice) ParseOptions ¶
func (i *Int64Slice) ParseOptions(tag reflect.StructTag) interface{}
type IntOptions ¶
type IntSliceOptions ¶
type IntSliceOptions struct { *IntOptions *SliceOptions }
type JsonLoader ¶
type JsonLoader interface { Marshal(v interface{}) ([]byte, error) Unmarshal(data []byte, v interface{}) error UnmarshalUsingNumber(data []byte, v interface{}) error }
Expose json loader interface that can be implemneted in client code for customization
var MetaJson JsonLoader
type Optionaler ¶
type Optionaler interface {
Optional() bool
}
type Presence ¶
type Presence struct {
Present bool
}
func (*Presence) SetPresence ¶
Sets p.Present to true or false based on err and discardBlank. err is the output of FormValue. It could be nil or some error or ErrBlank. If err is ErrBlank and discardBlank, then it's like the field is not present. Returns the input err unless we discarded a blank, in which case it returns nil.
type SliceOptions ¶
type SliceOptions struct { MinLengthPresent bool MinLength int MaxLengthPresent bool MaxLength int }
func ParseSliceOptions ¶
func ParseSliceOptions(tag reflect.StructTag) *SliceOptions
type StringOptions ¶
type StringSlice ¶
func (*StringSlice) FormValue ¶
func (i *StringSlice) FormValue(value string, options interface{}) Errorable
func (*StringSlice) JSONValue ¶
func (n *StringSlice) JSONValue(path string, i interface{}, options interface{}) Errorable
func (StringSlice) MarshalJSON ¶
func (s StringSlice) MarshalJSON() ([]byte, error)
func (*StringSlice) ParseOptions ¶
func (i *StringSlice) ParseOptions(tag reflect.StructTag) interface{}
type StringSliceOptions ¶
type StringSliceOptions struct { *StringOptions *SliceOptions }