Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfigTool ¶
Example (ReadValue) ¶
tmpDir, _ := os.MkdirTemp("", "nuv") defer os.RemoveAll(tmpDir) nuvRootPath := filepath.Join(tmpDir, "nuvroot.json") configPath := filepath.Join(tmpDir, "config.json") cm, _ := NewConfigMapBuilder().WithNuvRoot(nuvRootPath).WithConfigJson(configPath).Build() os.Args = []string{"config", "FOO=bar"} err := ConfigTool(cm) if err != nil { fmt.Println("error:", err) } os.Args = []string{"config", "FOO"} err = ConfigTool(cm) if err != nil { fmt.Println("error:", err) } // nested key os.Args = []string{"config", "NESTED_VAL=val"} err = ConfigTool(cm) if err != nil { fmt.Println("error:", err) } os.Args = []string{"config", "NESTED_VAL"} err = ConfigTool(cm) if err != nil { fmt.Println("error:", err) }
Output: bar val
func NewConfigMapBuilder ¶
func NewConfigMapBuilder() *configMapBuilder
Types ¶
type ConfigMap ¶
type ConfigMap struct {
// contains filtered or unexported fields
}
A ConfigMap is a map where the keys are in the form of: A_KEY_WITH_UNDERSCORES. The map splits the key by the underscores and creates a nested map that represents the key. For example, the key "A_KEY_WITH_UNDERSCORES" would be represented as:
{ "a": { "key": { "with": { "underscores": "value", }, }, }, }
To interact with the ConfigMap, use the Insert, Get, and Delete by passing keys in the form above. Only the config map is modified by these functions. The nuvRootConfig map is only used to read the config keys in nuvroot.json. The pluginNuvRootConfigs map is only used to read the config keys in plugins (from their nuvroot.json). It is a map that maps the plugin name to the config map for that plugin.
func (*ConfigMap) Insert ¶
Insert inserts a key and value into the ConfigMap. If the key already exists, the value is overwritten. The expected key format is A_KEY_WITH_UNDERSCORES.