| 1 |
--- |
| 2 |
# Do not remove front matter. |
| 3 |
--- |
| 4 |
|
| 5 |
## Methods |
| 6 |
|
| 7 |
Use these methods on the data structure. |
| 8 |
|
| 9 |
`Set` |
| 10 |
: Sets the value of the given key. |
| 11 |
|
| 12 |
```go-html-template |
| 13 |
{{ .Store.Set "greeting" "Hello" }} |
| 14 |
``` |
| 15 |
|
| 16 |
`Get` |
| 17 |
: (`any`) Gets the value of the given key. |
| 18 |
|
| 19 |
```go-html-template |
| 20 |
{{ .Store.Set "greeting" "Hello" }} |
| 21 |
{{ .Store.Get "greeting" }} → Hello |
| 22 |
``` |
| 23 |
|
| 24 |
`Add` |
| 25 |
: Adds the given value to the existing value(s) of the given key. |
| 26 |
|
| 27 |
For single values, `Add` accepts values that support Go's `+` operator. If the first `Add` for a key is an array or slice, the following adds will be appended to that list. |
| 28 |
|
| 29 |
```go-html-template |
| 30 |
{{ .Store.Set "greeting" "Hello" }} |
| 31 |
{{ .Store.Add "greeting" "Welcome" }} |
| 32 |
{{ .Store.Get "greeting" }} → HelloWelcome |
| 33 |
``` |
| 34 |
|
| 35 |
```go-html-template |
| 36 |
{{ .Store.Set "total" 3 }} |
| 37 |
{{ .Store.Add "total" 7 }} |
| 38 |
{{ .Store.Get "total" }} → 10 |
| 39 |
``` |
| 40 |
|
| 41 |
```go-html-template |
| 42 |
{{ .Store.Set "greetings" (slice "Hello") }} |
| 43 |
{{ .Store.Add "greetings" (slice "Welcome" "Cheers") }} |
| 44 |
{{ .Store.Get "greetings" }} → [Hello Welcome Cheers] |
| 45 |
``` |
| 46 |
|
| 47 |
`SetInMap` |
| 48 |
: Takes a `key`, `mapKey` and `value` and adds a map of `mapKey` and `value` to the given `key`. |
| 49 |
|
| 50 |
```go-html-template |
| 51 |
{{ .Store.SetInMap "greetings" "english" "Hello" }} |
| 52 |
{{ .Store.SetInMap "greetings" "french" "Bonjour" }} |
| 53 |
{{ .Store.Get "greetings" }} → map[english:Hello french:Bonjour] |
| 54 |
``` |
| 55 |
|
| 56 |
`DeleteInMap` |
| 57 |
: Takes a `key` and `mapKey` and removes the map of `mapKey` from the given `key`. |
| 58 |
|
| 59 |
```go-html-template |
| 60 |
{{ .Store.SetInMap "greetings" "english" "Hello" }} |
| 61 |
{{ .Store.SetInMap "greetings" "french" "Bonjour" }} |
| 62 |
{{ .Store.DeleteInMap "greetings" "english" }} |
| 63 |
{{ .Store.Get "greetings" }} → map[french:Bonjour] |
| 64 |
``` |
| 65 |
|
| 66 |
`GetSortedMapValues` |
| 67 |
: (`[]any`) Returns an array of values from `key` sorted by `mapKey`. |
| 68 |
|
| 69 |
```go-html-template |
| 70 |
{{ .Store.SetInMap "greetings" "english" "Hello" }} |
| 71 |
{{ .Store.SetInMap "greetings" "french" "Bonjour" }} |
| 72 |
{{ .Store.GetSortedMapValues "greetings" }} → [Hello Bonjour] |
| 73 |
``` |
| 74 |
|
| 75 |
`Delete` |
| 76 |
: Removes the given key. |
| 77 |
|
| 78 |
```go-html-template |
| 79 |
{{ .Store.Set "greeting" "Hello" }} |
| 80 |
{{ .Store.Delete "greeting" }} |
| 81 |
``` |