This repository was archived by the owner on Jul 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic.go
More file actions
42 lines (34 loc) · 1.32 KB
/
Copy pathbasic.go
File metadata and controls
42 lines (34 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// nolint
package main
import (
"fmt"
"log"
"github.com/unrolled/mapstore"
)
const (
configMapName = "my-custom-config-map-name" // This will be the name of the ConfigMap saved to k8s.
configMapNamespace = "config-map-namespace" // This will be the namespace of the ConfigMap.
myKey = "my-key" // This is the key used when writing the key-value pair to the ConfigMap.
)
func basic() {
// By allowing the config map to be stored internally, we reduce the amount of lookups required.
// But you need to be aware of the limitations (see the main README.md for documentation)!
cacheConfigMapInternally := true
// Create a new mapstore manager.
mapStore, err := mapstore.New(configMapNamespace, configMapName, cacheConfigMapInternally)
if err != nil {
// If you receive this error, you likely need to give the appropriate RBAC permissions to your pod.
log.Fatalf("error creating mapstore (possible rbac issue?): %v", err)
}
// Setting a value. The underlying ConfigMap data has to be a byte slice.
err = mapStore.Set(myKey, []byte("my value lives here"))
if err != nil {
log.Fatalf("error setting value: %v", err)
}
// Getting a value.
val, err := mapStore.Get(myKey)
if err != nil {
log.Fatalf("error getting value: %v", err)
}
fmt.Printf("Value from ConfigMap: %#v\n", val)
}