mapof

package
v0.51.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 12 Imported by: 11 modules, 37 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

mapof

Generic, map-backed types (mapof.Any, mapof.Bool, mapof.Int, mapof.Int64, mapof.Float, mapof.String, mapof.Object[T], mapof.Template, mapof.Matchable[T], and the mapof.Slices[K,V] multimap) that add type-safe getters/setters and schema integration on top of a plain Go map. Part of rosetta.

These exist so a map[string]any can be passed through the schema engine (and other rosetta tools) with typed accessors instead of repeated type assertions at every call site.

What matters here

  • Setters use pointer receivers and lazily allocate via makeNotNil(). A zero-value var m mapof.Bool is a nil map; calling m.SetBool(...) works because the setter takes *Bool and allocates the backing map on first write. This is the standard "guard the nil-map write" pattern — do not "simplify" setters to value receivers, and do not add a constructor requirement. Getters use value receivers (reading a nil map is safe).
  • The nilaway CI step runs with -exclude-test-files. .github/workflows/nilaway.yml invokes nilaway -exclude-test-files=true ./... directly, because the qbaware/nilaway-action hardcodes nilaway $PACKAGE_TO_SCAN and cannot pass the flag. The flag scopes analysis to production code; nil flows that exist only in test fixtures (e.g. a setter called on a zero-value map variable) are out of scope. The gate must exit with zero output — if it reports anything, fix the code, do not relax the gate.
  • mapof.Any, mapof.Template, and mapof.Object[T] implement the schema getter/setter interfaces without importing schema: Any implements GetPointer, SetKey, SetValue, and the typed GetXxxOK family; Template all of those but the getters, whose extra data argument keeps them off schema's interfaces; Object[T] only GetPointer and SetKey. Schema walks every nested path itself and stores one key at a time through SetKey, so it can create mapof.Any and sliceof.Any children; importing schema from here would make that an import cycle. GetPointer on these maps returns the child value itself, which schema reads before it writes into a child. Changing those method signatures breaks schema path access.
  • GetXxx returns the zero value; GetXxxOK returns (value, ok). Use the OK form when "absent" and "present-but-zero" must be distinguished — the plain getters cannot tell them apart. On Any and Template, ok is also FALSE for a present value that converts lossily (GetIntOK on 2.5 returns (2, false)).

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.

Template is the exception to "exactly like the maps they wrap": its strings may be stored as loose.Template values, compiled when decoded or set, and its getters take the data to render them against. Read it only through its methods.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Any

type Any map[string]any

Any is a map of string keys to arbitrary values with typed, coercing accessors.

func MapOfAny added in v0.22.0

func MapOfAny(value any) (Any, bool)

MapOfAny converts Any, Template, Bool, Float, Int, Int64, String, a pointer to one of those, or a plain or pointer map[string]X of those value types into a mapof.Any, and TRUE, or (nil, false) otherwise.

func NewAny added in v0.11.0

func NewAny() Any

NewAny returns a new, initialized Any map.

func (*Any) Append added in v0.16.0

func (x *Any) Append(key string, value any)

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) Equal added in v0.24.8

func (x Any) Equal(value map[string]any) bool

Equal returns TRUE if this map deeply equals the provided map.

func (Any) GetAny

func (x Any) GetAny(key string) any

GetAny returns the raw value for the key, or nil if the key is not present.

func (Any) GetAnyOK added in v0.11.0

func (x Any) GetAnyOK(key string) (any, bool)

GetAnyOK returns the raw value for the key and TRUE if it is present, or (nil, false) if not.

func (Any) GetBool

func (x Any) GetBool(key string) bool

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

func (x Any) GetBoolOK(key string) (value bool, ok bool)

GetBoolOK returns the key's value as a bool, and TRUE if it was present and converted losslessly.

func (Any) GetFloat

func (x Any) GetFloat(key string) float64

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

func (x Any) GetFloatOK(key string) (value float64, ok bool)

GetFloatOK returns the key's value as a float64, and TRUE if present and converted losslessly.

func (Any) GetInt

func (x Any) GetInt(key string) int

GetInt returns the value for the key coerced to int, or 0 if absent or not coercible.

func (Any) GetInt64

func (x Any) GetInt64(key string) int64

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

func (x Any) GetInt64OK(key string) (value int64, ok bool)

GetInt64OK returns the key's value as an int64, and TRUE if present and converted losslessly.

func (Any) GetIntOK added in v0.11.0

func (x Any) GetIntOK(key string) (value int, ok bool)

GetIntOK returns the key's value as an int, and TRUE if it was present and converted losslessly.

func (Any) GetMap added in v0.11.0

func (m Any) GetMap(name string) Any

GetMap returns a named property as a mapof.Any

func (Any) GetMapOfAny added in v0.25.26

func (m Any) GetMapOfAny(name string) Any

GetMapOfAny returns a named property as a mapof.Any

func (Any) GetMapOfString added in v0.25.26

func (m Any) GetMapOfString(name string) String

GetMapOfString returns a named property as a mapof.String

func (Any) GetPointer added in v0.14.0

func (x Any) GetPointer(key string) (any, bool)

GetPointer returns the raw value for the key (implements the schema PointerGetter interface).

func (Any) GetSliceOfAny added in v0.23.1

func (m Any) GetSliceOfAny(name string) []any

GetSliceOfAny returns a named property as a slice of any values

func (Any) GetSliceOfFloat added in v0.11.0

func (m Any) GetSliceOfFloat(name string) []float64

GetSliceOfFloat returns a named property as a slice of float64 values

func (Any) GetSliceOfInt added in v0.11.0

func (m Any) GetSliceOfInt(name string) []int

GetSliceOfInt returns a named property as a slice of int values

func (Any) GetSliceOfMap added in v0.11.0

func (m Any) GetSliceOfMap(name string) []Any

GetSliceOfMap returns a named property as a slice of mapof.Any objects.

func (Any) GetSliceOfPlainMap added in v0.23.2

func (m Any) GetSliceOfPlainMap(name string) []map[string]any

GetSliceOfPlainMap returns a named property as a slice of plain map[string]any objects.

func (Any) GetSliceOfString added in v0.11.0

func (m Any) GetSliceOfString(name string) []string

GetSliceOfString returns a named property as a slice of strings

func (Any) GetString

func (x Any) GetString(key string) string

GetString returns the value for the key coerced to string, or "" if absent or not coercible.

func (Any) GetStringOK added in v0.11.0

func (x Any) GetStringOK(key string) (value string, ok bool)

GetStringOK returns the key's value as a string, and TRUE if present and converted losslessly.

func (Any) GetTime added in v0.24.6

func (x Any) GetTime(key string) time.Time

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

func (x Any) GetTimeOK(key string) (value time.Time, ok bool)

GetTimeOK returns the value for the key coerced to time.Time, with TRUE if it was present and coercible.

func (Any) IsEmpty added in v0.16.3

func (x Any) IsEmpty() bool

IsEmpty returns TRUE if the map contains no elements.

func (Any) IsMap added in v0.29.0

func (x Any) IsMap() bool

IsMap returns TRUE, declaring this type a map for schema traversal. Implements schema.MapTyper.

func (Any) IsZeroValue added in v0.12.2

func (m Any) IsZeroValue(name string) bool

IsZeroValue returns TRUE if the named property is absent or holds a zero value.

func (Any) Keys added in v0.11.0

func (x Any) Keys() []string

Keys returns the map's keys in sorted order.

func (Any) Length added in v0.25.35

func (x Any) Length() int

Length returns the number of elements in the map

func (Any) MapOfAny added in v0.21.3

func (m Any) MapOfAny() map[string]any

MapOfAny implements the convert.MapOfAnyGetter interface. It returns this value as a map[string]any

func (Any) MapOfString added in v0.21.3

func (m Any) MapOfString() map[string]string

MapOfString returns this value as a map[string]string, converting each value to a string

func (Any) NotEmpty added in v0.16.3

func (x Any) NotEmpty() bool

NotEmpty returns TRUE if the map contains one or more elements.

func (Any) NotEqual added in v0.24.8

func (x Any) NotEqual(value map[string]any) bool

NotEqual returns TRUE if this map does not deeply equal the provided map.

func (*Any) Remove added in v0.11.0

func (x *Any) Remove(key string) bool

Remove deletes the key from the map.

func (*Any) SetAny

func (x *Any) SetAny(key string, value any) bool

SetAny stores a non-zero value at the key (deleting the key when the value is zero to keep the map sparse).

func (*Any) SetBool

func (x *Any) SetBool(key string, value bool) bool

SetBool stores a bool value at the key.

func (*Any) SetFloat

func (x *Any) SetFloat(key string, value float64) bool

SetFloat stores a non-zero float64 at the key (deleting the key when the value is zero).

func (*Any) SetInt

func (x *Any) SetInt(key string, value int) bool

SetInt stores a non-zero int at the key (deleting the key when the value is zero).

func (*Any) SetInt64

func (x *Any) SetInt64(key string, value int64) bool

SetInt64 stores a non-zero int64 at the key (deleting the key when the value is zero).

func (*Any) SetKey added in v0.44.0

func (x *Any) SetKey(key string, value any) error

SetKey stores the value under the key exactly as given, including a zero value (implements the schema KeySetter interface).

func (*Any) SetString

func (x *Any) SetString(key string, value string) bool

SetString stores a non-empty string at the key (deleting the key when the value is empty).

func (*Any) SetValue added in v0.22.0

func (x *Any) SetValue(value any) error

SetValue replaces the entire map with the provided value, if it can be converted to a mapof.Any.

type Bool

type Bool map[string]bool

Bool is a map of string keys to bool values with typed accessors.

func NewBool added in v0.11.0

func NewBool() Bool

NewBool returns a new, initialized Bool map.

func (Bool) Equal added in v0.13.0

func (x Bool) Equal(value Bool) bool

Equal returns TRUE if this map has the same keys and values as the provided map.

func (Bool) GetBool

func (x Bool) GetBool(key string) bool

GetBool returns the value for the key, or FALSE if the key is not present.

func (Bool) GetBoolOK added in v0.11.0

func (x Bool) GetBoolOK(key string) (bool, bool)

GetBoolOK returns the value for the key and TRUE if it is present, or (false, false) if not.

func (Bool) IsEmpty added in v0.16.3

func (x Bool) IsEmpty() bool

IsEmpty returns TRUE if the map contains no elements.

func (Bool) IsMap added in v0.29.0

func (x Bool) IsMap() bool

IsMap returns TRUE, declaring this type a map for schema traversal. Implements schema.MapTyper.

func (Bool) Keys added in v0.11.2

func (x Bool) Keys() []string

Keys returns the map's keys in sorted order.

func (Bool) Length added in v0.25.35

func (x Bool) Length() int

Length returns the number of elements in the map

func (Bool) NotEmpty added in v0.16.3

func (x Bool) NotEmpty() bool

NotEmpty returns TRUE if the map contains one or more elements.

func (Bool) NotEqual added in v0.24.8

func (x Bool) NotEqual(value Bool) bool

NotEqual returns TRUE if this map differs from the provided map.

func (*Bool) Remove added in v0.10.0

func (x *Bool) Remove(key string) bool

Remove deletes the key from the map.

func (*Bool) SetBool

func (x *Bool) SetBool(key string, value bool) bool

SetBool stores the value at the key, allocating the map first if it is nil.

type Float

type Float map[string]float64

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

func (x Float) Equal(value map[string]float64) bool

Equal returns TRUE if this map has the same keys and values as the provided map.

func (Float) GetFloat

func (x Float) GetFloat(key string) float64

GetFloat returns the value for the key, or 0 if the key is not present.

func (Float) GetFloatOK added in v0.10.0

func (x Float) GetFloatOK(key string) (float64, bool)

GetFloatOK returns the value for the key and TRUE if it is present, or (0, false) if not.

func (Float) IsEmpty added in v0.16.3

func (x Float) IsEmpty() bool

IsEmpty returns TRUE if the map contains no elements.

func (Float) IsMap added in v0.29.0

func (x Float) IsMap() bool

IsMap returns TRUE, declaring this type a map for schema traversal. Implements schema.MapTyper.

func (Float) Keys added in v0.11.2

func (x Float) Keys() []string

Keys returns the map's keys in sorted order.

func (Float) Length added in v0.25.35

func (x Float) Length() int

Length returns the number of elements in the map

func (Float) NotEmpty added in v0.16.3

func (x Float) NotEmpty() bool

NotEmpty returns TRUE if the map contains one or more elements.

func (Float) NotEqual added in v0.24.8

func (x Float) NotEqual(value map[string]float64) bool

NotEqual returns TRUE if this map differs from the provided map.

func (*Float) Remove added in v0.10.0

func (x *Float) Remove(key string) bool

Remove deletes the key from the map.

func (*Float) SetFloat

func (x *Float) SetFloat(key string, value float64) bool

SetFloat stores a non-zero value at the key (deleting the key when the value is zero to keep the map sparse), allocating the map first if it is nil.

type Int

type Int map[string]int

Int is a map of string keys to int values with typed accessors.

func NewInt added in v0.11.0

func NewInt() Int

NewInt returns a new, initialized Int map.

func (Int) Equal added in v0.13.0

func (x Int) Equal(value map[string]int) bool

Equal returns TRUE if this map has the same keys and values as the provided map.

func (Int) GetInt

func (x Int) GetInt(key string) int

GetInt returns the value for the key, or 0 if the key is not present.

func (Int) GetIntOK added in v0.11.0

func (x Int) GetIntOK(key string) (int, bool)

GetIntOK returns the value for the key and TRUE if it is present, or (0, false) if not.

func (Int) IsEmpty added in v0.16.3

func (x Int) IsEmpty() bool

IsEmpty returns TRUE if the map contains no elements.

func (Int) IsMap added in v0.29.0

func (x Int) IsMap() bool

IsMap returns TRUE, declaring this type a map for schema traversal. Implements schema.MapTyper.

func (Int) Keys added in v0.11.2

func (x Int) Keys() []string

Keys returns the map's keys in sorted order.

func (Int) Length added in v0.25.35

func (x Int) Length() int

Length returns the number of elements in the map

func (Int) NotEmpty added in v0.16.3

func (x Int) NotEmpty() bool

NotEmpty returns TRUE if the map contains one or more elements.

func (Int) NotEqual added in v0.24.8

func (x Int) NotEqual(value map[string]int) bool

NotEqual returns TRUE if this map differs from the provided map.

func (*Int) Remove added in v0.10.0

func (x *Int) Remove(key string) bool

Remove deletes the key from the map.

func (*Int) SetInt

func (x *Int) SetInt(key string, value int) bool

SetInt stores a non-zero value at the key (deleting the key when the value is zero to keep the map sparse), allocating the map first if it is nil.

type Int64

type Int64 map[string]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

func (x Int64) Equal(value map[string]int64) bool

Equal returns TRUE if this map has the same keys and values as the provided map.

func (Int64) GetInt64

func (x Int64) GetInt64(key string) int64

GetInt64 returns the value for the key, or 0 if the key is not present.

func (Int64) GetInt64OK added in v0.11.0

func (x Int64) GetInt64OK(key string) (int64, bool)

GetInt64OK returns the value for the key and TRUE if it is present, or (0, false) if not.

func (Int64) IsEmpty added in v0.16.3

func (x Int64) IsEmpty() bool

IsEmpty returns TRUE if the map contains no elements.

func (Int64) IsMap added in v0.29.0

func (x Int64) IsMap() bool

IsMap returns TRUE, declaring this type a map for schema traversal. Implements schema.MapTyper.

func (Int64) Keys added in v0.11.2

func (x Int64) Keys() []string

Keys returns the map's keys in sorted order.

func (Int64) Length added in v0.25.35

func (x Int64) Length() int

Length returns the number of elements in the map

func (Int64) NotEmpty added in v0.16.3

func (x Int64) NotEmpty() bool

NotEmpty returns TRUE if the map contains one or more elements.

func (Int64) NotEqual added in v0.24.8

func (x Int64) NotEqual(value map[string]int64) bool

NotEqual returns TRUE if this map differs from the provided map.

func (*Int64) Remove added in v0.10.0

func (x *Int64) Remove(key string) bool

Remove deletes the key from the map.

func (*Int64) SetInt64

func (x *Int64) SetInt64(key string, value int64) bool

SetInt64 stores a non-zero value at the key (deleting the key when the value is zero to keep the map sparse), allocating the map first if it is nil.

type Matchable added in v0.25.35

type Matchable[T Matcher] map[string]T

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

func NewMatchable[T Matcher]() Matchable[T]

NewMatchable returns a fully initialized Matchable object

func (Matchable[T]) Equal added in v0.25.35

func (m Matchable[T]) Equal(value map[string]any) bool

Equal returns TRUE if this map deeply equals the provided map.

func (Matchable[T]) GetPointer added in v0.25.35

func (m Matchable[T]) GetPointer(key string) (any, bool)

GetPointer returns the value for the key (implements the schema PointerGetter interface).

func (Matchable[T]) IsEmpty added in v0.25.35

func (m Matchable[T]) IsEmpty() bool

IsEmpty returns TRUE if the map contains no elements.

func (Matchable[T]) IsMap added in v0.29.0

func (m Matchable[T]) IsMap() bool

IsMap returns TRUE, declaring this type a map for schema traversal. Implements schema.MapTyper.

func (Matchable[T]) IsZeroValue added in v0.25.35

func (m Matchable[T]) IsZeroValue(name string) bool

IsZeroValue returns TRUE if the named property is absent or holds a zero value.

func (Matchable[T]) Keys added in v0.25.35

func (m Matchable[T]) Keys() []string

Keys returns the map's keys in sorted order.

func (Matchable[T]) Length added in v0.25.35

func (m Matchable[T]) Length() int

Length returns the number of elements in the map

func (Matchable[T]) MapOfAny added in v0.25.35

func (m Matchable[T]) MapOfAny() map[string]any

MapOfAny implements the convert.MapOfAnyGetter interface. It returns a copy of this value as a map[string]any

func (Matchable[T]) MapOfString added in v0.25.35

func (m Matchable[T]) MapOfString() map[string]string

MapOfString returns this value as a map[string]string, converting each value to a 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 an element that matches the given expression (an arbitrary one when several match), along with a boolean indicating if a match was found.

func (Matchable[T]) NotEmpty added in v0.25.35

func (m Matchable[T]) NotEmpty() bool

NotEmpty returns TRUE if the map contains one or more elements.

func (Matchable[T]) NotEqual added in v0.25.35

func (m Matchable[T]) NotEqual(value map[string]any) bool

NotEqual returns TRUE if this map does not deeply equal the provided map.

func (*Matchable[T]) Remove added in v0.25.35

func (m *Matchable[T]) Remove(key string) bool

Remove deletes the key from the map.

func (Matchable[T]) Values added in v0.25.35

func (m Matchable[T]) Values() []T

Values returns all of the map's values (in unspecified order).

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

type Object[T any] map[string]T

Object is a map of string keys to values of a single type T, with schema-traversal support.

func NewObject added in v0.10.0

func NewObject[T any]() Object[T]

NewObject returns a new, initialized Object map.

func (Object[T]) GetPointer added in v0.14.0

func (object Object[T]) GetPointer(name string) (any, bool)

GetPointer returns the value for the key (implements the schema PointerGetter interface).

func (Object[T]) IsEmpty added in v0.16.3

func (x Object[T]) IsEmpty() bool

IsEmpty returns TRUE if the map contains no elements.

func (Object[T]) IsMap added in v0.29.0

func (x Object[T]) IsMap() bool

IsMap returns TRUE, declaring this type a map for schema traversal. Implements schema.MapTyper.

func (Object[T]) IsZeroValue added in v0.12.2

func (object Object[T]) IsZeroValue(name string) bool

IsZeroValue returns TRUE if the named property is absent or holds a zero value.

func (Object[T]) Keys added in v0.11.2

func (x Object[T]) Keys() []string

Keys returns the map's keys in sorted order.

func (Object[T]) Length added in v0.25.35

func (x Object[T]) Length() int

Length returns the number of elements in the map

func (Object[T]) NotEmpty added in v0.16.3

func (x Object[T]) NotEmpty() bool

NotEmpty returns TRUE if the map contains one or more elements.

func (*Object[T]) Remove added in v0.10.0

func (object *Object[T]) Remove(key string) bool

Remove deletes the key from the map.

func (*Object[T]) SetKey added in v0.44.0

func (object *Object[T]) SetKey(key string, value any) error

SetKey stores the value under the key when it is a T, and returns an error otherwise (implements the schema KeySetter interface).

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.

func (*Slices[K, V]) Add added in v0.25.10

func (s *Slices[K, V]) Add(key K, value V)

Add appends a value to the slice stored at the key, creating the slice if necessary.

func (Slices[K, V]) Flatten added in v0.25.11

func (s Slices[K, V]) Flatten() []V

Flatten returns all values across every key as a single slice (in unspecified order).

type String

type String map[string]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

func (x String) Equal(value map[string]string) bool

Equal returns TRUE if this map has the same keys and values as the provided map.

func (String) GetString

func (x String) GetString(key string) string

GetString returns the value for the key, or "" if the key is not present.

func (String) GetStringOK added in v0.11.0

func (x String) GetStringOK(key string) (string, bool)

GetStringOK returns the value for the key and TRUE if it is present, or ("", false) if not.

func (String) IsEmpty added in v0.16.3

func (x String) IsEmpty() bool

IsEmpty returns TRUE if the map contains no elements.

func (String) IsMap added in v0.29.0

func (x String) IsMap() bool

IsMap returns TRUE, declaring this type a map for schema traversal. Implements schema.MapTyper.

func (String) Keys added in v0.11.2

func (x String) Keys() []string

Keys returns the map's keys in sorted order.

func (String) Length added in v0.25.35

func (x String) Length() int

Length returns the number of elements in the map

func (String) MapOfAny added in v0.21.3

func (x String) MapOfAny() map[string]any

MapOfAny returns the map's contents as a map[string]any.

func (String) MapOfString added in v0.21.3

func (x String) MapOfString() map[string]string

MapOfString returns the underlying map[string]string.

func (String) NotEmpty added in v0.16.3

func (x String) NotEmpty() bool

NotEmpty returns TRUE if the map contains one or more elements.

func (String) NotEqual added in v0.24.8

func (x String) NotEqual(value map[string]string) bool

NotEqual returns TRUE if this map differs from the provided map.

func (*String) Remove added in v0.10.0

func (x *String) Remove(key string) bool

Remove deletes the key from the map.

func (*String) SetString

func (x *String) SetString(key string, value string) bool

SetString stores a non-empty value at the key (deleting the key when the value is empty to keep the map sparse), allocating the map first if it is nil.

type Template added in v0.43.0

type Template map[string]any

Template is a map of string keys to arbitrary values, whose strings may be templates that its getters render against data. Read it only through its methods.

func NewTemplate added in v0.43.0

func NewTemplate() Template

NewTemplate returns a new, initialized Template map.

func ParseTemplate added in v0.43.0

func ParseTemplate(value map[string]any) Template

ParseTemplate copies a map into a Template, compiling every top-level string that holds a template.

func (*Template) Append added in v0.43.0

func (x *Template) Append(key string, value any)

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 original values, which are never templates.

func (Template) Clone added in v0.43.0

func (x Template) Clone() Template

Clone returns a deep copy of this map, so that a caller can change any map or slice within it without changing the original. Pointers, structs, arrays, and loose.Template values are shared.

func (Template) Equal added in v0.43.0

func (x Template) Equal(value map[string]any) bool

Equal returns TRUE if this map's original values deeply equal the provided map.

func (Template) Evaluate added in v0.43.0

func (x Template) Evaluate(key string, data any) (string, error)

Evaluate renders the value at the key against the provided data if it is a template, and otherwise returns it as a string. Unlike the getters, it reports a failed render.

func (Template) GetAny added in v0.43.0

func (x Template) GetAny(key string, data any) any

GetAny returns the value for the key, with a template rendered against the data, or nil if the key is not present.

func (Template) GetAnyOK added in v0.43.0

func (x Template) GetAnyOK(key string, data any) (any, bool)

GetAnyOK returns the value for the key, with a template rendered against the data, and TRUE if it is present, or (nil, false) if not.

func (Template) GetBool added in v0.43.0

func (x Template) GetBool(key string, data any) bool

GetBool returns the value for the key, rendered against the data and coerced to bool, or FALSE if absent or not coercible.

func (Template) GetBoolOK added in v0.43.0

func (x Template) GetBoolOK(key string, data any) (value bool, ok bool)

GetBoolOK returns the value for the key, rendered against the data and coerced to bool, with TRUE if it was present and converted losslessly.

func (Template) GetFloat added in v0.43.0

func (x Template) GetFloat(key string, data any) float64

GetFloat returns the value for the key, rendered against the data and coerced to float64, or 0 if absent or not coercible.

func (Template) GetFloatOK added in v0.43.0

func (x Template) GetFloatOK(key string, data any) (value float64, ok bool)

GetFloatOK returns the value for the key, rendered against the data and coerced to float64, with TRUE if it was present and converted losslessly.

func (Template) GetInt added in v0.43.0

func (x Template) GetInt(key string, data any) int

GetInt returns the value for the key, rendered against the data and coerced to int, or 0 if absent or not coercible.

func (Template) GetInt64 added in v0.43.0

func (x Template) GetInt64(key string, data any) int64

GetInt64 returns the value for the key, rendered against the data and coerced to int64, or 0 if absent or not coercible.

func (Template) GetInt64OK added in v0.43.0

func (x Template) GetInt64OK(key string, data any) (value int64, ok bool)

GetInt64OK returns the value for the key, rendered against the data and coerced to int64, with TRUE if it was present and converted losslessly.

func (Template) GetIntOK added in v0.43.0

func (x Template) GetIntOK(key string, data any) (value int, ok bool)

GetIntOK returns the value for the key, rendered against the data and coerced to int, with TRUE if it was present and converted losslessly.

func (Template) GetMap added in v0.43.0

func (x Template) GetMap(name string, data any) Any

GetMap returns a named property as a mapof.Any. Strings within it are not templates.

func (Template) GetMapOfAny added in v0.43.0

func (x Template) GetMapOfAny(name string, data any) Any

GetMapOfAny returns a named property as a mapof.Any. Strings within it are not templates.

func (Template) GetMapOfString added in v0.43.0

func (x Template) GetMapOfString(name string, data any) String

GetMapOfString returns a named property as a mapof.String. Strings within it are not templates.

func (Template) GetPointer added in v0.43.0

func (x Template) GetPointer(key string) (any, bool)

GetPointer returns the original value for the key (implements the schema PointerGetter interface).

func (Template) GetSliceOfAny added in v0.43.0

func (x Template) GetSliceOfAny(name string, data any) []any

GetSliceOfAny returns a named property, with a template rendered against the data, as a slice of any values

func (Template) GetSliceOfFloat added in v0.43.0

func (x Template) GetSliceOfFloat(name string, data any) []float64

GetSliceOfFloat returns a named property, with a template rendered against the data, as a slice of float64 values

func (Template) GetSliceOfInt added in v0.43.0

func (x Template) GetSliceOfInt(name string, data any) []int

GetSliceOfInt returns a named property, with a template rendered against the data, as a slice of int values

func (Template) GetSliceOfMap added in v0.43.0

func (x Template) GetSliceOfMap(name string, data any) []Any

GetSliceOfMap returns a named property as a slice of mapof.Any objects. Strings within them are not templates.

func (Template) GetSliceOfPlainMap added in v0.43.0

func (x Template) GetSliceOfPlainMap(name string, data any) []map[string]any

GetSliceOfPlainMap returns a named property as a slice of plain map[string]any objects. Strings within them are not templates.

func (Template) GetSliceOfString added in v0.43.0

func (x Template) GetSliceOfString(name string, data any) []string

GetSliceOfString returns a named property, with a template rendered against the data, as a slice of strings

func (Template) GetString added in v0.43.0

func (x Template) GetString(key string, data any) string

GetString returns the value for the key, rendered against the data and coerced to string, or "" if absent or not coercible.

func (Template) GetStringOK added in v0.43.0

func (x Template) GetStringOK(key string, data any) (value string, ok bool)

GetStringOK returns the value for the key, rendered against the data and coerced to string, with TRUE if it was present and converted losslessly.

func (Template) GetTime added in v0.43.0

func (x Template) GetTime(key string, data any) time.Time

GetTime returns the value for the key, rendered against the data and coerced to time.Time, or the zero time if absent or not coercible.

func (Template) GetTimeOK added in v0.43.0

func (x Template) GetTimeOK(key string, data any) (value time.Time, ok bool)

GetTimeOK returns the value for the key, rendered against the data and coerced to time.Time, with TRUE if it was present and coercible.

func (Template) IsEmpty added in v0.43.0

func (x Template) IsEmpty() bool

IsEmpty returns TRUE if the map contains no elements.

func (Template) IsMap added in v0.43.0

func (x Template) IsMap() bool

IsMap returns TRUE, declaring this type a map for schema traversal. Implements schema.MapTyper.

func (Template) IsZeroValue added in v0.43.0

func (x Template) IsZeroValue(name string) bool

IsZeroValue returns TRUE if the named property is absent or holds a zero value, without rendering it.

func (Template) Keys added in v0.43.0

func (x Template) Keys() []string

Keys returns the map's keys in sorted order.

func (Template) Length added in v0.43.0

func (x Template) Length() int

Length returns the number of elements in the map

func (Template) MapOfAny added in v0.43.0

func (x Template) MapOfAny() map[string]any

MapOfAny implements the convert.MapOfAnyGetter interface. It returns a copy of this map, with every loose.Template replaced by its source string

func (Template) MapOfString added in v0.43.0

func (x Template) MapOfString() map[string]string

MapOfString returns this map's original values as a map[string]string

func (Template) NotEmpty added in v0.43.0

func (x Template) NotEmpty() bool

NotEmpty returns TRUE if the map contains one or more elements.

func (Template) NotEqual added in v0.43.0

func (x Template) NotEqual(value map[string]any) bool

NotEqual returns TRUE if this map's original values do not deeply equal the provided map.

func (*Template) Remove added in v0.43.0

func (x *Template) Remove(key string) bool

Remove deletes the key from the map.

func (*Template) SetAny added in v0.43.0

func (x *Template) SetAny(key string, value any) bool

SetAny stores a non-zero value at the key (deleting it when zero), compiling a templated string.

func (*Template) SetBool added in v0.43.0

func (x *Template) SetBool(key string, value bool) bool

SetBool stores a bool value at the key.

func (*Template) SetFloat added in v0.43.0

func (x *Template) SetFloat(key string, value float64) bool

SetFloat stores a non-zero float64 at the key (deleting the key when the value is zero).

func (*Template) SetInt added in v0.43.0

func (x *Template) SetInt(key string, value int) bool

SetInt stores a non-zero int at the key (deleting the key when the value is zero).

func (*Template) SetInt64 added in v0.43.0

func (x *Template) SetInt64(key string, value int64) bool

SetInt64 stores a non-zero int64 at the key (deleting the key when the value is zero).

func (*Template) SetKey added in v0.44.0

func (x *Template) SetKey(key string, value any) error

SetKey stores the value under the key, including a zero value, compiling a string that holds a template (implements the schema KeySetter interface).

func (*Template) SetString added in v0.43.0

func (x *Template) SetString(key string, value string) bool

SetString stores a non-empty string at the key (deleting it when empty), compiling a template.

func (*Template) SetValue added in v0.43.0

func (x *Template) SetValue(value any) error

SetValue replaces the entire map with the provided value, if it can be converted to a map, compiling every top-level string that holds a template.

func (*Template) UnmarshalJSON added in v0.43.0

func (x *Template) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a JSON object, compiling every top-level string that holds a template.

Jump to

Keyboard shortcuts

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