Documentation ¶
Overview ¶
env package is a goschtalt decoder package for processing environment variables.
See the example for how to use this extension package.
Example ¶
package main import ( "fmt" "os" "strings" "github.com/schmidtw/goschtalt" "github.com/schmidtw/goschtalt/extensions/decoders/env" ) func main() { _ = os.Setenv("EXAMexample_version", "1") _ = os.Setenv("EXAMexample_colors_0", "red") _ = os.Setenv("EXAMexample_colors_1", "green") _ = os.Setenv("EXAMexample_colors_2", "blue") g, err := goschtalt.New(env.EnvVarConfig("OrderFilename", "EXAM", "_")...) if err != nil { panic(err) } err = g.Compile() if err != nil { panic(err) } var cfg struct { Example struct { Version int Colors []string } } err = g.Unmarshal("", &cfg) if err != nil { panic(err) } fmt.Println("example") fmt.Printf(" version = %d\n", cfg.Example.Version) fmt.Printf(" colors = [ %s ]\n", strings.Join(cfg.Example.Colors, ", ")) }
Output: example version = 1 colors = [ red, green, blue ]
Index ¶
Examples ¶
Constants ¶
const Extension = `environ`
The extension this decoder uses since the decode itself isn't public.
Variables ¶
This section is empty.
Functions ¶
func EnvVarConfig ¶
EnvVarConfig provides a way to collect configuration values from environment variables passed into the program. The filename is used to sort prior to the merge step, allowing the order of operations to be specified. The prefix is the environment variable name prefix to look for when collecting them. The delimiter is the string used to split the tree structure on.
For some environment variable environments like bash the allowable characters in the names is limited to: `[a-zA-Z_][a-zA-Z0-9_]*`
If you need multiple prefix values, this option is safe to use multiple times.
Types ¶
This section is empty.