package maps
import "github.com/gohugoio/hugo/common/maps"
Index ¶
- func GetNestedParam(keyStr, separator string, candidates ...Params) (any, error)
- func GetNestedParamFn(keyStr, separator string, lookupFn func(key string) any) (any, string, map[string]any, error)
- func LookupEqualFold[T any | string](m map[string]T, key string) (T, bool)
- func PrepareParams(m Params)
- func ToSliceStringMap(in any) ([]map[string]any, error)
- func ToStringMap(in any) map[string]any
- func ToStringMapBool(in any) map[string]bool
- func ToStringMapE(in any) (map[string]any, error)
- func ToStringMapString(in any) map[string]string
- func ToStringMapStringE(in any) (map[string]string, error)
- type KeyRenamer
- func NewKeyRenamer(patternKeys ...string) (KeyRenamer, error)
- func (r KeyRenamer) Rename(m map[string]any)
- type Params
- func MustToParamsAndPrepare(in any) Params
- func ToParamsAndPrepare(in any) (Params, bool)
- func (p Params) DeleteMergeStrategy() bool
- func (p Params) Get(indices ...string) any
- func (p Params) GetMergeStrategy() (ParamsMergeStrategy, bool)
- func (p Params) IsZero() bool
- func (p Params) Merge(pp Params)
- func (p Params) MergeRoot(pp Params)
- func (p Params) Set(pp Params)
- func (p Params) SetDefaultMergeStrategy(s ParamsMergeStrategy)
- type ParamsMergeStrategy
- type Scratch
- func NewScratch() *Scratch
- func (c *Scratch) Add(key string, newAddend any) (string, error)
- func (c *Scratch) Delete(key string) string
- func (c *Scratch) DeleteInMap(key string, mapKey string) string
- func (c *Scratch) Get(key string) any
- func (c *Scratch) GetSortedMapValues(key string) any
- func (c *Scratch) Set(key string, value any) string
- func (c *Scratch) SetInMap(key string, mapKey string, value any) string
- func (c *Scratch) Values() map[string]any
- type Scratcher
Functions ¶
func GetNestedParam ¶
GetNestedParam gets the first match of the keyStr in the candidates given. It will first try the exact match and then try to find it as a nested map value, using the given separator, e.g. "mymap.name". It assumes that all the maps given have lower cased keys.
func GetNestedParamFn ¶
func GetNestedParamFn(keyStr, separator string, lookupFn func(key string) any) (any, string, map[string]any, error)
func LookupEqualFold ¶
LookupEqualFold finds key in m with case insensitive equality checks.
func PrepareParams ¶
func PrepareParams(m Params)
PrepareParams * makes all the keys in the given map lower cased and will do so * This will modify the map given. * Any nested map[interface{}]interface{}, map[string]interface{},map[string]string will be converted to Params. * Any _merge value will be converted to proper type and value.
func ToSliceStringMap ¶
ToSliceStringMap converts in to []map[string]interface{}.
func ToStringMap ¶
ToStringMap converts in to map[string]interface{}.
func ToStringMapBool ¶
ToStringMapBool converts in to bool.
func ToStringMapE ¶
ToStringMapE converts in to map[string]interface{}.
func ToStringMapString ¶
ToStringMapString converts in to map[string]string.
func ToStringMapStringE ¶
ToStringMapStringE converts in to map[string]string.
Types ¶
type KeyRenamer ¶
type KeyRenamer struct {
// contains filtered or unexported fields
}
KeyRenamer supports renaming of keys in a map.
func NewKeyRenamer ¶
func NewKeyRenamer(patternKeys ...string) (KeyRenamer, error)
NewKeyRenamer creates a new KeyRenamer given a list of pattern and new key value pairs.
func (KeyRenamer) Rename ¶
func (r KeyRenamer) Rename(m map[string]any)
Rename renames the keys in the given map according to the patterns in the current KeyRenamer.
type Params ¶
Params is a map where all keys are lower case.
func MustToParamsAndPrepare ¶
MustToParamsAndPrepare calls ToParamsAndPrepare and panics if it fails.
func ToParamsAndPrepare ¶
ToParamsAndPrepare converts in to Params and prepares it for use. If in is nil, an empty map is returned. See PrepareParams.
func (Params) DeleteMergeStrategy ¶
func (Params) Get ¶
Get does a lower case and nested search in this map. It will return nil if none found.
func (Params) GetMergeStrategy ¶
func (p Params) GetMergeStrategy() (ParamsMergeStrategy, bool)
func (Params) IsZero ¶
IsZero returns true if p is considered empty.
func (Params) Merge ¶
Merge transfers values from pp to p for new keys. This is done recursively.
func (Params) MergeRoot ¶
MergeRoot transfers values from pp to p for new keys where p is the root of the tree. This is done recursively.
func (Params) Set ¶
Set overwrites values in p with values in pp for common or new keys. This is done recursively.
func (Params) SetDefaultMergeStrategy ¶
func (p Params) SetDefaultMergeStrategy(s ParamsMergeStrategy)
type ParamsMergeStrategy ¶
type ParamsMergeStrategy string
ParamsMergeStrategy tells what strategy to use in Params.Merge.
const ( // Do not merge. ParamsMergeStrategyNone ParamsMergeStrategy = "none" // Only add new keys. ParamsMergeStrategyShallow ParamsMergeStrategy = "shallow" // Add new keys, merge existing. ParamsMergeStrategyDeep ParamsMergeStrategy = "deep" )
type Scratch ¶
type Scratch struct {
// contains filtered or unexported fields
}
Scratch is a writable context used for stateful operations in Page/Node rendering.
func NewScratch ¶
func NewScratch() *Scratch
NewScratch returns a new instance of Scratch.
func (*Scratch) Add ¶
Add will, for single values, add (using the + operator) the addend to the existing addend (if found). Supports numeric values and strings.
If the first add for a key is an array or slice, then the next value(s) will be appended.
func (*Scratch) Delete ¶
Delete deletes the given key.
func (*Scratch) DeleteInMap ¶
DeleteInMap deletes a value to a map with the given key in the Node context.
func (*Scratch) Get ¶
Get returns a value previously set by Add or Set.
func (*Scratch) GetSortedMapValues ¶
GetSortedMapValues returns a sorted map previously filled with SetInMap.
func (*Scratch) Set ¶
Set stores a value with the given key in the Node context. This value can later be retrieved with Get.
func (*Scratch) SetInMap ¶
SetInMap stores a value to a map with the given key in the Node context. This map can later be retrieved with GetSortedMapValues.
func (*Scratch) Values ¶
Values returns the raw backing map. Note that you should just use this method on the locally scoped Scratch instances you obtain via newScratch, not .Page.Scratch etc., as that will lead to concurrency issues.
type Scratcher ¶
type Scratcher interface { // Scratch returns a "scratch pad" that can be used to store state. Scratch() *Scratch }
Scratcher provides a scratching service.
func NewScratcher ¶
func NewScratcher() Scratcher
NewScratcher creates a new Scratcher.
Source Files ¶
- Version
- v0.111.1
- Published
- Mar 2, 2023
- Platform
- linux/amd64
- Imports
- 10 packages
- Last checked
- 3 hours ago –
Tools for package owners.