config

package
v1.3.0-snapshot.240723... Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigTool

func ConfigTool(configMap ConfigMap) error
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) Delete

func (c *ConfigMap) Delete(key string) error

func (*ConfigMap) Flatten

func (c *ConfigMap) Flatten() map[string]string

func (*ConfigMap) Get

func (c *ConfigMap) Get(key string) (string, error)

func (*ConfigMap) Insert

func (c *ConfigMap) Insert(key string, value string) error

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.

func (*ConfigMap) SaveConfig

func (c *ConfigMap) SaveConfig() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL