diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-05-29 18:50:12 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-05-29 19:51:49 +0200 |
commit | 2919a6a503f7b369154d6eb787023a1fe58a9ad4 (patch) | |
tree | d2d1a4a73d67471a5ae62b394f6055aa5288f601 /common/maps/scratch.go | |
parent | 432885c499849efb29d3e50196f377fe0e908333 (diff) |
common/maps: Add Scratch.Values
Fixes #7335
Diffstat (limited to 'common/maps/scratch.go')
-rw-r--r-- | common/maps/scratch.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/common/maps/scratch.go b/common/maps/scratch.go index 4acd10c6c..7a3cd3748 100644 --- a/common/maps/scratch.go +++ b/common/maps/scratch.go @@ -107,6 +107,15 @@ func (c *Scratch) Get(key string) interface{} { return val } +// 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. +func (c *Scratch) Values() map[string]interface{} { + c.mu.RLock() + defer c.mu.RUnlock() + return c.values +} + // SetInMap stores a value to a map with the given key in the Node context. // This map can later be retrieved with GetSortedMapValues. func (c *Scratch) SetInMap(key string, mapKey string, value interface{}) string { @@ -147,7 +156,7 @@ func (c *Scratch) GetSortedMapValues(key string) interface{} { return sortedArray } -// NewScratch returns a new instance Scratch. +// NewScratch returns a new instance of Scratch. func NewScratch() *Scratch { return &Scratch{values: make(map[string]interface{})} } |