Documentation ¶
Index ¶
- Variables
- func Interpolate(conf map[string]interface{}, reloadChan chan string) error
- func InterpolateAndWatchYAMLFile(yamlFileName string, out interface{}) error
- func InterpolateFromYAMLFile(yamlFileName string, out interface{}) error
- type Interpolators
- func (i *Interpolators) ConsulInterpolator(interpolatorConf string, value string, reloadChan chan string) string
- func (i *Interpolators) EnvInterpolator(interpolatorConf string, value string, reloadChan chan string) string
- func (i *Interpolators) HashivaultInterpolator(interpolatorConf string, value string, reloadChan chan string) string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( LeftSeparator = "{{" RightSeparator = "}}" InterpolatorSeparator = "::" InterpolatorConfigurationSeparator = ":" // When using watch, specify interval between reloads ReloadInterval = 30 * time.Second )
Functions ¶
func Interpolate ¶
Interpolate interpolate values in a map[string]interface{}
func InterpolateAndWatchYAMLFile ¶ added in v0.4.0
InterpolateFromYAMLFile interpolate YAML file content and write interpolated content to out interface{}. If the data is updated in any external sources, it will be updated int he out interface InterpolateFromYAMLFile does not end unless an error occured which will be returned
Example ¶
package main import ( "fmt" "os" "time" "github.com/bbayszczak/cfginterpolator" ) func main() { type Config struct { Key1 string Key2 map[string]string Key3 []map[string]string } os.Setenv("ENV_VAR_1", "var1_0") os.Setenv("ENV_VAR_2", "var2") os.Setenv("ENV_VAR_3", "var3") var conf Config cfginterpolator.ReloadInterval = time.Second go func() { time.Sleep(500 * time.Millisecond) if err := cfginterpolator.InterpolateAndWatchYAMLFile("example_files/config.yml", &conf); err != nil { fmt.Println(err) } }() for i := 1; i <= 3; i++ { time.Sleep(time.Second) os.Setenv("ENV_VAR_1", fmt.Sprintf("var1_%d", i)) fmt.Printf("%d: %s\n", i, conf) } }
Output: 1: {var1_0 map[subkey1:var2] [map[listkey1:var3]]} 2: {var1_1 map[subkey1:var2] [map[listkey1:var3]]} 3: {var1_2 map[subkey1:var2] [map[listkey1:var3]]}
func InterpolateFromYAMLFile ¶ added in v0.1.0
InterpolateFromYAMLFile interpolate YAML file content and write interpolated content to out interface{}
Example ¶
package main import ( "fmt" "os" "github.com/bbayszczak/cfginterpolator" ) func main() { type Config struct { Key1 string Key2 map[string]string Key3 []map[string]string } os.Setenv("ENV_VAR_1", "secret_value_1_kv_V1") os.Setenv("ENV_VAR_2", "secret_value_2_kv_V1") os.Setenv("ENV_VAR_3", "secret_value_3_kv_V1") var conf Config if err := cfginterpolator.InterpolateFromYAMLFile("example_files/config.yml", &conf); err != nil { panic(err) } fmt.Println(conf) }
Output: {secret_value_1_kv_V1 map[subkey1:secret_value_2_kv_V1] [map[listkey1:secret_value_3_kv_V1]]}
Types ¶
type Interpolators ¶
type Interpolators struct{}
func (*Interpolators) ConsulInterpolator ¶ added in v0.3.0
func (i *Interpolators) ConsulInterpolator(interpolatorConf string, value string, reloadChan chan string) string
func (*Interpolators) EnvInterpolator ¶
func (i *Interpolators) EnvInterpolator(interpolatorConf string, value string, reloadChan chan string) string
func (*Interpolators) HashivaultInterpolator ¶ added in v0.0.2
func (i *Interpolators) HashivaultInterpolator(interpolatorConf string, value string, reloadChan chan string) string
Click to show internal directories.
Click to hide internal directories.