multilevel

command
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2021 License: MIT Imports: 4 Imported by: 0

README

Multi Level

go-conf supports multiple levels/ hierarchical configuration parameters. To do so one can just define a config structure that contains fields that are no primitive types but also structures.

Example

The goal is to set the value of the headers foreground color.

type ThemeConfig struct {
    Header FormattedTextBox `cfg:"{'name':'header'}"`
}

type FormattedTextBox struct {
    Font   Font   `cfg:"{'name':'font'}"`
}

type Font struct {
    ForegroundColor string `cfg:"{'name':'foreground-color'}"`
}

Hierarchy Separator

Config File

The hierarchy is represented using the structural elements provided by yaml.

To set the value for the headers foreground color one has to specify:

header:
  font:
    foreground-color: #FF0000
Environment Variable

The hierarchy in environment variables is represented by an underscore. But the underscore is also used as replacement for the dash. Hence the hierarchy can't be safely deduced from the name of the environment variable.

To set the value for the headers foreground color one has to specify:

# Assumption: MY_APP was the envPrefix for the provider
export MY_APP_HEADER_FONT_FOREGROUND_COLOR=#FF0000
Command Line Argument

The hierarchy for command line arguments is represented by a dot.

To set the value for the headers foreground color one has to specify:

go run . --header.font.foreground-color=#FF0000

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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