meta

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

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

Go to latest
Published: Oct 5, 2023 License: MIT Imports: 13 Imported by: 0

README

meta

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
var NameMapping = camelCaseToSnakeCase

Functions

This section is empty.

Types

type Bool

type Bool struct {
	Val bool
	Nullity
	Presence
	Path string
}

func NewBool

func NewBool(b bool) Bool

func (*Bool) FormValue

func (b *Bool) FormValue(value string, options interface{}) Errorable

func (*Bool) JSONValue

func (b *Bool) JSONValue(path string, i interface{}, options interface{}) Errorable

func (Bool) MarshalJSON

func (b Bool) MarshalJSON() ([]byte, error)

func (*Bool) ParseOptions

func (b *Bool) ParseOptions(tag reflect.StructTag) interface{}

func (Bool) Value

func (b Bool) Value() (driver.Value, error)

type BoolOptions

type BoolOptions struct {
	Required     bool
	DiscardBlank bool
	Null         bool
}

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

func (d *Decoder) Decode(dest interface{}, values url.Values, b []byte) ErrorHash

func (*Decoder) DecodeJSON

func (d *Decoder) DecodeJSON(dest interface{}, b []byte) ErrorHash

func (*Decoder) DecodeMap

func (d *Decoder) DecodeMap(dest interface{}, m map[string]interface{}) ErrorHash

func (*Decoder) DecodeValues

func (d *Decoder) DecodeValues(dest interface{}, values url.Values) ErrorHash

func (*Decoder) NewDecoded

func (d *Decoder) NewDecoded(values url.Values, r io.Reader) (interface{}, ErrorHash)

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.

func (*Decoder) NewDecodedValues

func (d *Decoder) NewDecodedValues(values url.Values) (interface{}, ErrorHash)

Given the decoder, makes a new struct and tries to map the values onto it. If it succeeds, returns that struct. Otherwise, returns the errors.

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 ErrorAtom

type ErrorAtom string

func (ErrorAtom) Error

func (e ErrorAtom) Error() string

func (ErrorAtom) ErrorKind

func (e ErrorAtom) ErrorKind() string

type ErrorHash

type ErrorHash map[string]Errorable

func NewHash

func NewHash(key, value string) ErrorHash

NewHash returns a new hash with a single key/value in it, eg {"error": "too_big"}

func (ErrorHash) Error

func (eh ErrorHash) Error() string

func (ErrorHash) ErrorKind

func (eh ErrorHash) ErrorKind() string

type ErrorSlice

type ErrorSlice []Errorable

func (ErrorSlice) Error

func (ea ErrorSlice) Error() string

func (ErrorSlice) ErrorKind

func (ea ErrorSlice) ErrorKind() string

func (ErrorSlice) Len

func (ea ErrorSlice) Len() (n int)

Len returns the number of non-nil error

type Errorable

type Errorable interface {
	// Errorable should be a go error
	error
	// ErrorKind is a useless method, and probably a poor design of this. My goal is a recursive Errorable type which is an ErrorHash OR ErrorAtom OR ErrorSlice
	ErrorKind() string
}

type Float64

type Float64 struct {
	Val float64
	Nullity
	Presence
	Path string
}

func NewFloat64

func NewFloat64(f float64) Float64

func (*Float64) FormValue

func (i *Float64) FormValue(value string, options interface{}) Errorable

func (*Float64) JSONValue

func (f *Float64) JSONValue(path string, i interface{}, options interface{}) Errorable

func (Float64) MarshalJSON

func (i Float64) MarshalJSON() ([]byte, error)

func (*Float64) ParseOptions

func (i *Float64) ParseOptions(tag reflect.StructTag) interface{}

func (Float64) Value

func (i Float64) Value() (driver.Value, error)

type FloatOptions

type FloatOptions struct {
	Required     bool
	DiscardBlank bool
	Null         bool
	MinPresent   bool
	Min          float64
	MaxPresent   bool
	Max          float64
	In           []float64
}

type Int64

type Int64 struct {
	Val int64
	Nullity
	Presence
	Path string
}

func NewInt64

func NewInt64(val int64) Int64

func (*Int64) FormValue

func (i *Int64) FormValue(value string, options interface{}) Errorable

func (*Int64) JSONValue

func (n *Int64) JSONValue(path string, i interface{}, options interface{}) Errorable

func (Int64) MarshalJSON

func (i Int64) MarshalJSON() ([]byte, error)

func (*Int64) ParseOptions

func (i *Int64) ParseOptions(tag reflect.StructTag) interface{}

func (Int64) Value

func (i Int64) Value() (driver.Value, error)

type Int64Slice

type Int64Slice struct {
	Val  []int64
	Path string
}

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 IntOptions struct {
	Required     bool
	Null         bool
	DiscardBlank bool
	MinPresent   bool
	Min          int64
	MaxPresent   bool
	Max          int64
	In           []int64
}

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 Nullity

type Nullity struct {
	Null bool
}

func (*Nullity) SetNullity

func (n *Nullity) SetNullity(err Errorable) Errorable

type Optionaler

type Optionaler interface {
	Optional() bool
}

type Presence

type Presence struct {
	Present bool
}

func (*Presence) Optional

func (p *Presence) Optional() bool

func (*Presence) SetPresence

func (p *Presence) SetPresence(err Errorable, discardBlank bool) Errorable

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 String

type String struct {
	Val string
	Nullity
	Presence
	Path string
}

func NewString

func NewString(s string) String

func (*String) FormValue

func (s *String) FormValue(value string, options interface{}) Errorable

func (*String) JSONValue

func (s *String) JSONValue(path string, i interface{}, options interface{}) Errorable

func (String) MarshalJSON

func (s String) MarshalJSON() ([]byte, error)

func (*String) ParseOptions

func (s *String) ParseOptions(tag reflect.StructTag) interface{}

func (String) Value

func (s String) Value() (driver.Value, error)

type StringOptions

type StringOptions struct {
	Required        bool
	DiscardBlank    bool
	Strip           bool
	Blank           bool
	Null            bool
	MinRunesPresent bool
	MinRunes        int
	MaxRunesPresent bool
	MaxRunes        int
	MaxBytesPresent bool
	MaxBytes        int
	In              []string
}

type StringSlice

type StringSlice struct {
	Val  []string
	Path string
}

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
}

type Time

type Time struct {
	Val time.Time
	Nullity
	Presence
	Path string
}

func NewTime

func NewTime(t time.Time) Time

func (*Time) FormValue

func (t *Time) FormValue(value string, options interface{}) Errorable

func (*Time) JSONValue

func (t *Time) JSONValue(path string, i interface{}, options interface{}) Errorable

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

func (*Time) ParseOptions

func (t *Time) ParseOptions(tag reflect.StructTag) interface{}

func (Time) Value

func (t Time) Value() (driver.Value, error)

type TimeOptions

type TimeOptions struct {
	Required     bool
	DiscardBlank bool
	Null         bool
	Format       []string
}

type Uint64

type Uint64 struct {
	Val uint64
	Nullity
	Presence
	Path string
}

func NewUint64

func NewUint64(val uint64) Uint64

func (*Uint64) FormValue

func (i *Uint64) FormValue(value string, options interface{}) Errorable

func (*Uint64) JSONValue

func (n *Uint64) JSONValue(path string, i interface{}, options interface{}) Errorable

func (Uint64) MarshalJSON

func (i Uint64) MarshalJSON() ([]byte, error)

func (*Uint64) ParseOptions

func (i *Uint64) ParseOptions(tag reflect.StructTag) interface{}

func (Uint64) Value

func (i Uint64) Value() (driver.Value, error)

NOTE: I know I am casting uints to int64's. This is per Go's docs, which does NOT list uint64 as a viable type. Unsure what that means for a large Uint64.

type UintOptions

type UintOptions struct {
	Required     bool
	Null         bool
	DiscardBlank bool
	MinPresent   bool
	Min          uint64
	MaxPresent   bool
	Max          uint64
	In           []uint64
}

type Valuer

type Valuer interface {
	ParseOptions(tag reflect.StructTag) interface{}
	JSONValue(path string, value interface{}, options interface{}) Errorable
}

Jump to

Keyboard shortcuts

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