Documentation
¶
Index ¶
- type MapsRegistry
- func (mr *MapsRegistry) Dict(values ...any) map[string]any
- func (mr *MapsRegistry) Dig(args ...any) (any, error)
- func (mr *MapsRegistry) Get(args ...any) (any, error)
- func (mr *MapsRegistry) HasKey(args ...any) (bool, error)
- func (mr *MapsRegistry) Keys(dicts ...map[string]any) []string
- func (mr *MapsRegistry) LinkHandler(fh sprout.Handler) error
- func (mr *MapsRegistry) Merge(dest map[string]any, srcs ...map[string]any) (any, error)
- func (mr *MapsRegistry) MergeOverwrite(dest map[string]any, srcs ...map[string]any) (any, error)
- func (mr *MapsRegistry) Omit(args ...any) (map[string]any, error)
- func (mr *MapsRegistry) Pick(args ...any) (map[string]any, error)
- func (mr *MapsRegistry) Pluck(key string, dicts ...map[string]any) []any
- func (mr *MapsRegistry) RegisterAliases(aliasesMap sprout.FunctionAliasMap) error
- func (mr *MapsRegistry) RegisterFunctions(funcsMap sprout.FunctionMap) error
- func (mr *MapsRegistry) RegisterNotices(notices *[]sprout.FunctionNotice) error
- func (mr *MapsRegistry) Set(args ...any) (map[string]any, error)
- func (mr *MapsRegistry) UID() string
- func (mr *MapsRegistry) Unset(args ...any) (map[string]any, error)
- func (mr *MapsRegistry) Values(dicts ...map[string]any) []any
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MapsRegistry ¶
type MapsRegistry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func NewRegistry() *MapsRegistry
NewRegistry creates a new instance of maps registry.
func (*MapsRegistry) Dict ¶
func (mr *MapsRegistry) Dict(values ...any) map[string]any
Dict creates a dictionary from a list of keys and values.
Parameters:
values ...any - alternating keys and values.
Returns:
map[string]any - the created dictionary.
For an example of this function in a Go template, refer to Sprout Documentation: dict.
func (*MapsRegistry) Dig ¶
func (mr *MapsRegistry) Dig(args ...any) (any, error)
Dig navigates through a nested dictionary structure using a sequence of keys and returns the value found at the specified path.
Parameters:
args ...any - a sequence of keys followed by a dictionary as the last argument.
Returns:
any - the value found at the nested key path or nil if any key in the path is not found. error - an error if there are fewer than three arguments, if the last argument is not a dictionary, or if any key is not a string.
For an example of this function in a Go template, refer to Sprout Documentation: dig.
func (*MapsRegistry) Get ¶
func (mr *MapsRegistry) Get(args ...any) (any, error)
Get retrieves the value associated with the specified key from the dictionary.
Parameters:
key string - the key to look up. dict map[string]any - the dictionary.
Returns:
any - the value associated with the key, or an empty string if the key does not exist. error - protect against undesired behavior due to migration to new signature.
For an example of this function in a Go template, refer to Sprout Documentation: get.
func (*MapsRegistry) HasKey ¶
func (mr *MapsRegistry) HasKey(args ...any) (bool, error)
HasKey checks if the specified key exists in the dictionary.
Parameters:
key string - the key to look for. dict map[string]any - the dictionary to check.
Returns:
bool - true if the key exists, otherwise false. error - protect against undesired behavior due to migration to new signature.
For an example of this function in a Go template, refer to Sprout Documentation: hasKey.
func (*MapsRegistry) Keys ¶
func (mr *MapsRegistry) Keys(dicts ...map[string]any) []string
Keys retrieves all keys from one or more dictionaries.
Parameters:
dicts ...map[string]any - one or more dictionaries.
Returns:
[]string - a list of all keys from the dictionaries.
For an example of this function in a Go template, refer to Sprout Documentation: keys.
func (*MapsRegistry) LinkHandler ¶
func (mr *MapsRegistry) LinkHandler(fh sprout.Handler) error
LinkHandler links the handler to the registry at runtime.
func (*MapsRegistry) Merge ¶
Merge merges multiple source maps into a destination map without overwriting existing keys in the destination. If an error occurs during merging, it returns nil and the error.
Parameters:
dest map[string]any - the destination map to which all source map key-values are added. srcs ...map[string]any - one or more source maps whose key-values are added to the destination.
Returns:
any - the merged destination map. error - error if the merge fails.
For an example of this function in a Go template, refer to Sprout Documentation: merge.
func (*MapsRegistry) MergeOverwrite ¶
MergeOverwrite merges multiple source maps into a destination map, overwriting existing keys in the destination. If an error occurs during merging, it returns nil and the error.
Parameters:
dest map[string]any - the destination map to which all source map key-values are added. srcs ...map[string]any - one or more source maps whose key-values are added to the destination, potentially overwriting existing keys.
Returns:
any - the merged destination map with overwritten values where applicable. error - error if the merge fails.
For an example of this function in a Go template, refer to Sprout Documentation: mergeOverwrite.
func (*MapsRegistry) Omit ¶
func (mr *MapsRegistry) Omit(args ...any) (map[string]any, error)
Omit creates a new dictionary by excluding specified keys from the original dictionary.
Parameters:
dict map[string]any - the source dictionary. keys ...string - the keys to exclude from the new dictionary.
Returns:
map[string]any - a dictionary without the omitted keys. error - protect against undesired behavior due to migration to new signature.
For an example of this function in a Go template, refer to Sprout Documentation: omit.
func (*MapsRegistry) Pick ¶
func (mr *MapsRegistry) Pick(args ...any) (map[string]any, error)
Pick creates a new dictionary containing only the specified keys from the original dictionary.
Parameters:
keys ...string - the keys to include in the new dictionary. dict map[string]any - the source dictionary.
Returns:
map[string]any - a dictionary containing only the picked keys and their values. error - protect against undesired behavior due to migration to new signature.
For an example of this function in a Go template, refer to Sprout Documentation: pick.
func (*MapsRegistry) Pluck ¶
func (mr *MapsRegistry) Pluck(key string, dicts ...map[string]any) []any
Pluck extracts values associated with a specified key from a list of dictionaries.
Parameters:
key string - the key to pluck values for. dicts ...map[string]any - one or more dictionaries.
Returns:
[]any - a list of values associated with the key from each dictionary.
For an example of this function in a Go template, refer to Sprout Documentation: pluck.
func (*MapsRegistry) RegisterAliases ¶ added in v0.6.0
func (mr *MapsRegistry) RegisterAliases(aliasesMap sprout.FunctionAliasMap) error
func (*MapsRegistry) RegisterFunctions ¶
func (mr *MapsRegistry) RegisterFunctions(funcsMap sprout.FunctionMap) error
RegisterFunctions registers all functions of the registry.
func (*MapsRegistry) RegisterNotices ¶ added in v0.6.0
func (mr *MapsRegistry) RegisterNotices(notices *[]sprout.FunctionNotice) error
func (*MapsRegistry) Set ¶
func (mr *MapsRegistry) Set(args ...any) (map[string]any, error)
Set adds or updates a key with a specified value in the dictionary.
Parameters:
key string - the key to set. value any - the value to associate with the key. dict map[string]any - the dictionary.
Returns:
map[string]any - the updated dictionary. error - protect against undesired behavior due to migration to new signature.
For an example of this function in a Go template, refer to Sprout Documentation: set.
func (*MapsRegistry) UID ¶ added in v1.0.0
func (mr *MapsRegistry) UID() string
UID returns the unique identifier of the registry.
func (*MapsRegistry) Unset ¶
func (mr *MapsRegistry) Unset(args ...any) (map[string]any, error)
Unset removes a key from the dictionary.
Parameters:
key string - the key to remove. dict map[string]any - the dictionary.
Returns:
map[string]any - the dictionary after removing the key. error - protect against undesired behavior due to migration to new signature.
For an example of this function in a Go template, refer to Sprout Documentation: unset.
func (*MapsRegistry) Values ¶
func (mr *MapsRegistry) Values(dicts ...map[string]any) []any
Values retrieves all values from one or more dictionaries.
Parameters:
dict map[string]any - the dictionary.
Returns:
[]any - a list of all values from the dictionary.
For an example of this function in a Go template, refer to Sprout Documentation: values.