Documentation ¶
Overview ¶
A wrapper to make map[string]any a little more type-safe
Index ¶
- Variables
- type Typed
- func (t Typed) Any(key string) any
- func (t Typed) AnyIf(key string) (any, bool)
- func (t Typed) AnyMust(key string) any
- func (t Typed) AnyOr(key string, d any) any
- func (t Typed) Anys(key string) []any
- func (t Typed) AnysIf(key string) ([]any, bool)
- func (t Typed) AnysMust(key string) []any
- func (t Typed) AnysOr(key string, d []any) []any
- func (t Typed) Bool(key string) bool
- func (t Typed) BoolIf(key string) (bool, bool)
- func (t Typed) BoolMust(key string) bool
- func (t Typed) BoolOr(key string, d bool) bool
- func (t Typed) Bools(key string) []bool
- func (t Typed) BoolsIf(key string) ([]bool, bool)
- func (t Typed) BoolsOr(key string, d []bool) []bool
- func (t Typed) Bytes(key string) []byte
- func (t Typed) BytesIf(key string) ([]byte, bool)
- func (t Typed) BytesMust(key string) []byte
- func (t Typed) BytesOr(key string, d []byte) []byte
- func (t Typed) Exists(key string) bool
- func (t Typed) Float(key string) float64
- func (t Typed) FloatIf(key string) (float64, bool)
- func (t Typed) FloatMust(key string) float64
- func (t Typed) FloatOr(key string, d float64) float64
- func (t Typed) Floats(key string) []float64
- func (t Typed) FloatsIf(key string) ([]float64, bool)
- func (t Typed) FloatsOr(key string, d []float64) []float64
- func (t Typed) Int(key string) int
- func (t Typed) IntIf(key string) (int, bool)
- func (t Typed) IntMust(key string) int
- func (t Typed) IntOr(key string, d int) int
- func (t Typed) Ints(key string) []int
- func (t Typed) Ints64(key string) []int64
- func (t Typed) Ints64If(key string) ([]int64, bool)
- func (t Typed) Ints64Or(key string, d []int64) []int64
- func (t Typed) IntsIf(key string) ([]int, bool)
- func (t Typed) IntsOr(key string, d []int) []int
- func (t Typed) Json(key string) (Typed, error)
- func (t Typed) JsonMust(key string) Typed
- func (t Typed) Keys() []string
- func (t Typed) Map(key string) map[string]any
- func (t Typed) MapIf(key string) (map[string]any, bool)
- func (t Typed) MapOr(key string, d map[string]any) map[string]any
- func (t Typed) Maps(key string) []map[string]any
- func (t Typed) Object(key string) Typed
- func (t Typed) ObjectIf(key string) (Typed, bool)
- func (t Typed) ObjectMust(key string) Typed
- func (t Typed) ObjectOr(key string, d map[string]any) Typed
- func (t Typed) Objects(key string) []Typed
- func (t Typed) ObjectsIf(key string) ([]Typed, bool)
- func (t Typed) ObjectsMust(key string) []Typed
- func (t Typed) String(key string) string
- func (t Typed) StringBool(key string) map[string]bool
- func (t Typed) StringFloat(key string) map[string]float64
- func (t Typed) StringIf(key string) (string, bool)
- func (t Typed) StringInt(key string) map[string]int
- func (t Typed) StringMust(key string) string
- func (t Typed) StringObject(key string) map[string]Typed
- func (t Typed) StringOr(key string, d string) string
- func (t Typed) StringString(key string) map[string]string
- func (t Typed) Strings(key string) []string
- func (t Typed) StringsIf(key string) ([]string, bool)
- func (t Typed) StringsOr(key string, d []string) []string
- func (t Typed) Time(key string) time.Time
- func (t Typed) TimeIf(key string) (time.Time, bool)
- func (t Typed) TimeMust(key string) time.Time
- func (t Typed) TimeOr(key string, d time.Time) time.Time
Constants ¶
This section is empty.
Variables ¶
var ( // Used by ToBytes to indicate that the key was not // present in the type KeyNotFound = errors.New("Key not found") Empty = Typed(nil) )
Functions ¶
This section is empty.
Types ¶
type Typed ¶
A Typed type helper for accessing a map
func JsonString ¶
Create a Typed helper from the given JSON string
func (Typed) AnyIf ¶ added in v0.0.5
Returns an string at the key and whether or not the key existed and the value was an string
func (Typed) AnyOr ¶ added in v0.0.5
Returns a string at the key, or the specified value if it doesn't exist or isn't a strin
func (Typed) AnysIf ¶ added in v0.0.5
Returns an string at the key and whether or not the key existed and the value was an string
func (Typed) AnysOr ¶ added in v0.0.5
Returns a string at the key, or the specified value if it doesn't exist or isn't a strin
func (Typed) Bool ¶
Returns a boolean at the key, or false if it doesn't exist, or if it isn't a bool
func (Typed) BoolIf ¶
Returns a boolean at the key and whether or not the key existed and the value was a bolean
func (Typed) BoolOr ¶
Returns a boolean at the key, or the specified value if it doesn't exist or isn't a bool
func (Typed) BoolsIf ¶
Returns a boolean slice + true if valid Returns nil + false otherwise (returns nil+false if one of the values is not a valid boolean)
func (Typed) BytesIf ¶
Returns an []byte at the key and whether or not the key existed and the value was an string
func (Typed) BytesOr ¶
Returns a []byte at the key, or the specified value if it doesn't exist or isn't a []byte
func (Typed) FloatIf ¶
Returns an float at the key and whether or not the key existed and the value was an float
func (Typed) FloatOr ¶
Returns a float at the key, or the specified value if it doesn't exist or isn't a float
func (Typed) FloatsIf ¶
Returns a float slice + true if valid Returns nil + false otherwise (returns nil+false if one of the values is not a valid float)
func (Typed) FloatsOr ¶
Returns an slice of floats, or the specified slice if the key doesn't exist or isn't a valid []float64
func (Typed) IntIf ¶
Returns an int at the key and whether or not the key existed and the value was an int
func (Typed) IntOr ¶
Returns a int at the key, or the specified value if it doesn't exist or isn't a int
func (Typed) Ints ¶
Returns an slice of ints, or the specified slice Some conversion is done to handle the fact that JSON ints are represented as floats.
func (Typed) Ints64 ¶
Returns an slice of ints64, or the specified slice Some conversion is done to handle the fact that JSON ints are represented as floats.
func (Typed) Ints64If ¶
Returns a boolean slice + true if valid Returns nil + false otherwise (returns nil+false if one of the values is not a valid boolean)
func (Typed) Ints64Or ¶
Returns an slice of ints, or the specified slice if the key doesn't exist or isn't a valid []int. Some conversion is done to handle the fact that JSON ints are represented as floats.
func (Typed) IntsIf ¶
Returns a int slice + true if valid Returns nil + false otherwise (returns nil+false if one of the values is not a valid int)
func (Typed) IntsOr ¶
Returns an slice of ints, or the specified slice if the key doesn't exist or isn't a valid []int. Some conversion is done to handle the fact that JSON ints are represented as floats.
func (Typed) Map ¶
Returns a map[string]any at the key or a nil map if the key doesn't exist or if the key isn't a map[string]interface
func (Typed) MapIf ¶
Returns a map[string]interface at the key and whether or not the key existed and the value was an map[string]any
func (Typed) MapOr ¶
Returns a map[string]any at the key or the specified default if the key doesn't exist or if the key isn't a map[string]interface
func (Typed) Object ¶
Returns a Typed helper at the key If the key doesn't exist, a default Typed helper is returned (which will return default values for any subsequent sub queries)
func (Typed) ObjectIf ¶
Returns a Typed helper at the key and whether or not the key existed and the value was an map[string]any
func (Typed) ObjectMust ¶
Returns an typed object or panics
func (Typed) ObjectOr ¶
Returns a Typed helper at the key or the specified default if the key doesn't exist or if the key isn't a map[string]any
func (Typed) ObjectsIf ¶
Returns a slice of Typed helpers and true if exists, otherwise; nil and false.
func (Typed) ObjectsMust ¶
func (Typed) StringBool ¶
Returns an map[string]bool
func (Typed) StringFloat ¶
Returns an map[string]float64
func (Typed) StringIf ¶
Returns an string at the key and whether or not the key existed and the value was an string
func (Typed) StringInt ¶
Returns an map[string]int Some work is done to handle the fact that JSON ints are represented as floats.
func (Typed) StringObject ¶
Returns an map[string]Typed
func (Typed) StringOr ¶
Returns a string at the key, or the specified value if it doesn't exist or isn't a string
func (Typed) StringString ¶
Returns an map[string]string
func (Typed) StringsIf ¶
Returns a string slice + true if valid Returns nil + false otherwise (returns nil+false if one of the values is not a valid string)
func (Typed) StringsOr ¶
Returns an slice of strings, or the specified slice if the key doesn't exist or isn't a valid []string