Documentation
¶
Overview ¶
Package mapof provides string-keyed map types with typed values and helper methods.
Any, String, Int, Int64, Float, Bool, and the generic Object[T] are all plain map types under their methods, so they can be ranged over, indexed, and serialized exactly like the maps they wrap. What they add is typed accessors — GetString, GetInt, GetBool, and their OK-returning variants — that convert a loosely-typed value on the way out, plus the Getter and Setter implementations that let the schema package address them by path.
That schema integration is the reason these types exist: they are the carriers a JSON-Schema-shaped document is read into and written back out of when there is no Go struct to bind to.
Index ¶
- type Any
- func (x *Any) Append(key string, value any)
- func (x Any) Equal(value map[string]any) bool
- func (x Any) GetAny(key string) any
- func (x Any) GetAnyOK(key string) (any, bool)
- func (x Any) GetBool(key string) bool
- func (x Any) GetBoolOK(key string) (value bool, ok bool)
- func (x Any) GetFloat(key string) float64
- func (x Any) GetFloatOK(key string) (value float64, ok bool)
- func (x Any) GetInt(key string) int
- func (x Any) GetInt64(key string) int64
- func (x Any) GetInt64OK(key string) (value int64, ok bool)
- func (x Any) GetIntOK(key string) (value int, ok bool)
- func (m Any) GetMap(name string) Any
- func (m Any) GetMapOfAny(name string) Any
- func (m Any) GetMapOfString(name string) String
- func (x Any) GetPointer(key string) (any, bool)
- func (m Any) GetSliceOfAny(name string) []any
- func (m Any) GetSliceOfFloat(name string) []float64
- func (m Any) GetSliceOfInt(name string) []int
- func (m Any) GetSliceOfMap(name string) []Any
- func (m Any) GetSliceOfPlainMap(name string) []map[string]any
- func (m Any) GetSliceOfString(name string) []string
- func (x Any) GetString(key string) string
- func (x Any) GetStringOK(key string) (value string, ok bool)
- func (x Any) GetTime(key string) time.Time
- func (x Any) GetTimeOK(key string) (value time.Time, ok bool)
- func (x Any) IsEmpty() bool
- func (x Any) IsMap() bool
- func (m Any) IsZeroValue(name string) bool
- func (x Any) Keys() []string
- func (x Any) Length() int
- func (m Any) MapOfAny() map[string]any
- func (m Any) MapOfString() map[string]string
- func (x Any) NotEmpty() bool
- func (x Any) NotEqual(value map[string]any) bool
- func (x *Any) Remove(key string) bool
- func (x *Any) SetAny(key string, value any) bool
- func (x *Any) SetBool(key string, value bool) bool
- func (x *Any) SetFloat(key string, value float64) bool
- func (x *Any) SetInt(key string, value int) bool
- func (x *Any) SetInt64(key string, value int64) bool
- func (x *Any) SetObject(element schema.Element, path list.List, value any) error
- func (x *Any) SetString(key string, value string) bool
- func (x *Any) SetValue(value any) error
- type Bool
- func (x Bool) Equal(value Bool) bool
- func (x Bool) GetBool(key string) bool
- func (x Bool) GetBoolOK(key string) (bool, bool)
- func (x Bool) IsEmpty() bool
- func (x Bool) IsMap() bool
- func (x Bool) Keys() []string
- func (x Bool) Length() int
- func (x Bool) NotEmpty() bool
- func (x Bool) NotEqual(value Bool) bool
- func (x *Bool) Remove(key string) bool
- func (x *Bool) SetBool(key string, value bool) bool
- type Float
- func (x Float) Equal(value map[string]float64) bool
- func (x Float) GetFloat(key string) float64
- func (x Float) GetFloatOK(key string) (float64, bool)
- func (x Float) IsEmpty() bool
- func (x Float) IsMap() bool
- func (x Float) Keys() []string
- func (x Float) Length() int
- func (x Float) NotEmpty() bool
- func (x Float) NotEqual(value map[string]float64) bool
- func (x *Float) Remove(key string) bool
- func (x *Float) SetFloat(key string, value float64) bool
- type Int
- func (x Int) Equal(value map[string]int) bool
- func (x Int) GetInt(key string) int
- func (x Int) GetIntOK(key string) (int, bool)
- func (x Int) IsEmpty() bool
- func (x Int) IsMap() bool
- func (x Int) Keys() []string
- func (x Int) Length() int
- func (x Int) NotEmpty() bool
- func (x Int) NotEqual(value map[string]int) bool
- func (x *Int) Remove(key string) bool
- func (x *Int) SetInt(key string, value int) bool
- type Int64
- func (x Int64) Equal(value map[string]int64) bool
- func (x Int64) GetInt64(key string) int64
- func (x Int64) GetInt64OK(key string) (int64, bool)
- func (x Int64) IsEmpty() bool
- func (x Int64) IsMap() bool
- func (x Int64) Keys() []string
- func (x Int64) Length() int
- func (x Int64) NotEmpty() bool
- func (x Int64) NotEqual(value map[string]int64) bool
- func (x *Int64) Remove(key string) bool
- func (x *Int64) SetInt64(key string, value int64) bool
- type Matchable
- func (m Matchable[T]) Equal(value map[string]any) bool
- func (m Matchable[T]) GetPointer(key string) (any, bool)
- func (m Matchable[T]) IsEmpty() bool
- func (m Matchable[T]) IsMap() bool
- func (m Matchable[T]) IsZeroValue(name string) bool
- func (m Matchable[T]) Keys() []string
- func (m Matchable[T]) Length() int
- func (m Matchable[T]) MapOfAny() map[string]any
- func (m Matchable[T]) MapOfString() map[string]string
- func (m Matchable[T]) Match(expression exp.Expression) Matchable[T]
- func (m Matchable[T]) MatchOne(expression exp.Expression) (T, bool)
- func (m Matchable[T]) NotEmpty() bool
- func (m Matchable[T]) NotEqual(value map[string]any) bool
- func (m *Matchable[T]) Remove(key string) bool
- func (m Matchable[T]) Values() []T
- type Matcher
- type Object
- func (object Object[T]) GetPointer(name string) (any, bool)
- func (x Object[T]) IsEmpty() bool
- func (x Object[T]) IsMap() bool
- func (object Object[T]) IsZeroValue(name string) bool
- func (x Object[T]) Keys() []string
- func (x Object[T]) Length() int
- func (x Object[T]) NotEmpty() bool
- func (object *Object[T]) Remove(key string) bool
- func (object *Object[T]) SetObject(element schema.Element, path list.List, value any) error
- type Slices
- type String
- func (x String) Equal(value map[string]string) bool
- func (x String) GetString(key string) string
- func (x String) GetStringOK(key string) (string, bool)
- func (x String) IsEmpty() bool
- func (x String) IsMap() bool
- func (x String) Keys() []string
- func (x String) Length() int
- func (x String) MapOfAny() map[string]any
- func (x String) MapOfString() map[string]string
- func (x String) NotEmpty() bool
- func (x String) NotEqual(value map[string]string) bool
- func (x *String) Remove(key string) bool
- func (x *String) SetString(key string, value string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Any ¶
Any is a map of string keys to arbitrary values with typed, coercing accessors.
func MapOfAny ¶ added in v0.22.0
MapOfAny converts a supported map type (any of the mapof types, or a plain/pointer map[string]X) into a mapof.Any, returning the result and TRUE on success, or (nil, false) for unsupported types.
func (*Any) Append ¶ added in v0.16.0
Append adds a new value to the provided key. If a value already exists for this key then it will be forced into a slice of values.
func (Any) GetAnyOK ¶ added in v0.11.0
GetAnyOK returns the raw value for the key and TRUE if it is present, or (nil, false) if not.
func (Any) GetBool ¶
GetBool returns the value for the key coerced to bool, or FALSE if absent or not coercible.
func (Any) GetBoolOK ¶ added in v0.11.0
GetBoolOK returns the value for the key coerced to bool, with TRUE if it was present and coercible.
func (Any) GetFloat ¶
GetFloat returns the value for the key coerced to float64, or 0 if absent or not coercible.
func (Any) GetFloatOK ¶ added in v0.11.0
GetFloatOK returns the value for the key coerced to float64, with TRUE if it was present and coercible.
func (Any) GetInt ¶
GetInt returns the value for the key coerced to int, or 0 if absent or not coercible.
func (Any) GetInt64 ¶
GetInt64 returns the value for the key coerced to int64, or 0 if absent or not coercible.
func (Any) GetInt64OK ¶ added in v0.11.0
GetInt64OK returns the value for the key coerced to int64, with TRUE if it was present and coercible.
func (Any) GetIntOK ¶ added in v0.11.0
GetIntOK returns the value for the key coerced to int, with TRUE if it was present and coercible.
func (Any) GetMapOfAny ¶ added in v0.25.26
GetMapOfAny returns a named property as a mapof.Any
func (Any) GetMapOfString ¶ added in v0.25.26
GetMapOfString returns a named property as a mapof.String
func (Any) GetPointer ¶ added in v0.14.0
GetPointer returns the raw value for the key (implements the schema PointerGetter interface).
func (Any) GetSliceOfAny ¶ added in v0.23.1
GetSliceOfAny returns a named property as a slice of any values
func (Any) GetSliceOfFloat ¶ added in v0.11.0
GetSliceOfFloat returns a named property as a slice of float64 values
func (Any) GetSliceOfInt ¶ added in v0.11.0
GetSliceOfInt returns a named property as a slice of int values
func (Any) GetSliceOfMap ¶ added in v0.11.0
GetSliceOfMap returns a named property as a slice of mapof.Any objects.
func (Any) GetSliceOfPlainMap ¶ added in v0.23.2
GetSliceOfPlainMap returns a named property as a slice of plain map[string]any objects.
func (Any) GetSliceOfString ¶ added in v0.11.0
GetSliceOfString returns a named property as a slice of strings
func (Any) GetString ¶
GetString returns the value for the key coerced to string, or "" if absent or not coercible.
func (Any) GetStringOK ¶ added in v0.11.0
GetStringOK returns the value for the key coerced to string, with TRUE if it was present and coercible.
func (Any) GetTime ¶ added in v0.24.6
GetTime returns the value for the key coerced to time.Time, or the zero time if absent or not coercible.
func (Any) GetTimeOK ¶ added in v0.24.6
GetTimeOK returns the value for the key coerced to time.Time, with TRUE if it was present and coercible.
func (Any) IsMap ¶ added in v0.29.0
IsMap returns TRUE, declaring this type a map for schema traversal. Implements schema.MapTyper.
func (Any) IsZeroValue ¶ added in v0.12.2
IsZeroValue returns TRUE if the named property is absent or holds a zero value.
func (Any) MapOfAny ¶ added in v0.21.3
MapOfAny implements the MapOfAny interface. It returns this value as a map[string]any
func (Any) MapOfString ¶ added in v0.21.3
MapOfString implements the MapOfString interface. It returns this value as a map[string]string
func (Any) NotEmpty ¶ added in v0.16.3
NotEmpty returns TRUE if the map contains one or more elements.
func (Any) NotEqual ¶ added in v0.24.8
NotEqual returns TRUE if this map does not deeply equal the provided map.
func (*Any) SetAny ¶
SetAny stores a non-zero value at the key (deleting the key when the value is zero to keep the map sparse).
func (*Any) SetFloat ¶
SetFloat stores a non-zero float64 at the key (deleting the key when the value is zero).
func (*Any) SetInt ¶
SetInt stores a non-zero int at the key (deleting the key when the value is zero).
func (*Any) SetInt64 ¶
SetInt64 stores a non-zero int64 at the key (deleting the key when the value is zero).
func (*Any) SetObject ¶ added in v0.11.0
SetObject descends the path (creating child maps as needed) and sets the value (implements the schema ObjectSetter interface).
type Bool ¶
Bool is a map of string keys to bool values with typed accessors.
func (Bool) Equal ¶ added in v0.13.0
Equal returns TRUE if this map has the same keys and values as the provided map.
func (Bool) GetBoolOK ¶ added in v0.11.0
GetBoolOK returns the value for the key and TRUE if it is present, or (false, false) if not.
func (Bool) IsMap ¶ added in v0.29.0
IsMap returns TRUE, declaring this type a map for schema traversal. Implements schema.MapTyper.
func (Bool) NotEmpty ¶ added in v0.16.3
NotEmpty returns TRUE if the map contains one or more elements.
func (Bool) NotEqual ¶ added in v0.24.8
NotEqual returns TRUE if this map differs from the provided map.
type Float ¶
Float is a map of string keys to float64 values with typed accessors.
func NewFloat ¶ added in v0.11.0
func NewFloat() Float
NewFloat returns a new, initialized Float map.
func (Float) Equal ¶ added in v0.13.0
Equal returns TRUE if this map has the same keys and values as the provided map.
func (Float) GetFloatOK ¶ added in v0.10.0
GetFloatOK returns the value for the key and TRUE if it is present, or (0, false) if not.
func (Float) IsMap ¶ added in v0.29.0
IsMap returns TRUE, declaring this type a map for schema traversal. Implements schema.MapTyper.
func (Float) NotEmpty ¶ added in v0.16.3
NotEmpty returns TRUE if the map contains one or more elements.
func (Float) NotEqual ¶ added in v0.24.8
NotEqual returns TRUE if this map differs from the provided map.
type Int ¶
Int is a map of string keys to int values with typed accessors.
func (Int) Equal ¶ added in v0.13.0
Equal returns TRUE if this map has the same keys and values as the provided map.
func (Int) GetIntOK ¶ added in v0.11.0
GetIntOK returns the value for the key and TRUE if it is present, or (0, false) if not.
func (Int) IsMap ¶ added in v0.29.0
IsMap returns TRUE, declaring this type a map for schema traversal. Implements schema.MapTyper.
func (Int) NotEmpty ¶ added in v0.16.3
NotEmpty returns TRUE if the map contains one or more elements.
func (Int) NotEqual ¶ added in v0.24.8
NotEqual returns TRUE if this map differs from the provided map.
type Int64 ¶
Int64 is a map of string keys to int64 values with typed accessors.
func NewInt64 ¶ added in v0.11.0
func NewInt64() Int64
NewInt64 returns a new, initialized Int64 map.
func (Int64) Equal ¶ added in v0.13.0
Equal returns TRUE if this map has the same keys and values as the provided map.
func (Int64) GetInt64OK ¶ added in v0.11.0
GetInt64OK returns the value for the key and TRUE if it is present, or (0, false) if not.
func (Int64) IsMap ¶ added in v0.29.0
IsMap returns TRUE, declaring this type a map for schema traversal. Implements schema.MapTyper.
func (Int64) NotEmpty ¶ added in v0.16.3
NotEmpty returns TRUE if the map contains one or more elements.
func (Int64) NotEqual ¶ added in v0.24.8
NotEqual returns TRUE if this map differs from the provided map.
type Matchable ¶ added in v0.25.35
Matchable is a map of objects that implement the Matcher interface and can be queried using the Match and MatchOne methods.
func NewMatchable ¶ added in v0.25.35
NewMatchable returns a fully initialized Matchable object
func (Matchable[T]) Equal ¶ added in v0.25.35
Equal returns TRUE if this map deeply equals the provided map.
func (Matchable[T]) GetPointer ¶ added in v0.25.35
GetPointer returns the value for the key (implements the schema PointerGetter interface).
func (Matchable[T]) IsEmpty ¶ added in v0.25.35
IsEmpty returns TRUE if the map contains no elements.
func (Matchable[T]) IsMap ¶ added in v0.29.0
IsMap returns TRUE, declaring this type a map for schema traversal. Implements schema.MapTyper.
func (Matchable[T]) IsZeroValue ¶ added in v0.25.35
IsZeroValue returns TRUE if the named property is absent or holds a zero value.
func (Matchable[T]) MapOfAny ¶ added in v0.25.35
MapOfAny implements the MapOfAny interface. It returns this value as a map[string]any
func (Matchable[T]) MapOfString ¶ added in v0.25.35
MapOfString implements the MapOfString interface. It returns this value as a map[string]string
func (Matchable[T]) Match ¶ added in v0.25.35
func (m Matchable[T]) Match(expression exp.Expression) Matchable[T]
Match returns a new map containing all elements that match the given expression.
func (Matchable[T]) MatchOne ¶ added in v0.25.35
func (m Matchable[T]) MatchOne(expression exp.Expression) (T, bool)
MatchOne returns the first element that matches the given expression, along with a boolean indicating if a match was found.
func (Matchable[T]) NotEmpty ¶ added in v0.25.35
NotEmpty returns TRUE if the map contains one or more elements.
func (Matchable[T]) NotEqual ¶ added in v0.25.35
NotEqual returns TRUE if this map does not deeply equal the provided map.
type Matcher ¶ added in v0.25.35
type Matcher interface {
// Match returns TRUE if this object matches the provided predicate
Match(predicate exp.Predicate) bool
}
Matcher interface wraps the Match method, which allows objects to declare if they match a given predicate
type Object ¶ added in v0.10.0
Object is a map of string keys to values of a single type T, with schema-traversal support.
func (Object[T]) GetPointer ¶ added in v0.14.0
GetPointer returns the value for the key (implements the schema PointerGetter interface).
func (Object[T]) IsMap ¶ added in v0.29.0
IsMap returns TRUE, declaring this type a map for schema traversal. Implements schema.MapTyper.
func (Object[T]) IsZeroValue ¶ added in v0.12.2
IsZeroValue returns TRUE if the named property is absent or holds a zero value.
func (Object[T]) NotEmpty ¶ added in v0.16.3
NotEmpty returns TRUE if the map contains one or more elements.
type Slices ¶ added in v0.25.10
type Slices[K comparable, V comparable] map[K][]V
Slices is a map from keys to slices of values, i.e. a one-to-many multimap.
type String ¶
String is a map of string keys to string values with typed accessors.
func NewString ¶ added in v0.11.0
func NewString() String
NewString returns a new, initialized String map.
func (String) Equal ¶ added in v0.13.0
Equal returns TRUE if this map has the same keys and values as the provided map.
func (String) GetStringOK ¶ added in v0.11.0
GetStringOK returns the value for the key and TRUE if it is present, or ("", false) if not.
func (String) IsMap ¶ added in v0.29.0
IsMap returns TRUE, declaring this type a map for schema traversal. Implements schema.MapTyper.
func (String) MapOfString ¶ added in v0.21.3
MapOfString returns the underlying map[string]string.
func (String) NotEmpty ¶ added in v0.16.3
NotEmpty returns TRUE if the map contains one or more elements.
func (String) NotEqual ¶ added in v0.24.8
NotEqual returns TRUE if this map differs from the provided map.