Universal configuration library by tags
0.8:
1.0:
For Run configuration by smart variant autostart analysing of using tags. Library will start configuring your structure by pipeline with all founded tags.
type Test struct {
MyValue1 string `cf_default:"turur" cf_hocon:"mySourceValue1"`
MySlice1 []bool `cf_default:"true,false,false,true" cf_env:"MY_SIGNALS"`
}
// in this example do use 3 tags: cf_default (using default values which setup inline tag)
// cf_env - using environment variable
// cf_hocon - using hocon source file
//....
func myConfigurator() {
os.Setenv(tags.HoconFile, , "testhocon.hocon")
myStruct, errConfiguring := gostructir.ConfigureSmart(&Test{})
// check errConfiguring for any errors
if errConfiguring != nil {
/// action for error
}
// cast interface{} into Test structure
myValues := myStruct.(*Test)
// now, u structure already filled
}
You can also setting configuring pipeline like this:
type Test struct {
MyValue1 string `cf_default:"turur" cf_hocon:"mySourceValue1"`
MySlice1 []bool `cf_default:"true,false,false,true" cf_env:"MY_SIGNALS"`
}
func myConfigurator() {
os.Setenv(tags.HoconFile, , "testhocon.hocon")
myStruct, errConfiguring := gostructir.ConfigureSetup(&Test{}, []infra.FuncType{
infra.FunctionSetupEnvironment,
})// you should setup only by order configure
// check errConfiguring for any errors
if errConfiguring != nil {
/// action for error
}
// cast interface{} into Test structure
myValues := myStruct.(*Test)
// now, u structure already filled
}
For fetching secrets you should add 2 environment variables: VAULT_ADDRESS, VAULT_TOKEN. After all, you can add cf_vault tag into your structure tags.
Now vault configure support all basic types and also complex type: slice
For Example:
type Test struct {
MySecretKey string `cf_vault:"my-secret-service/stage/tururu#my-key"`
MyCustomIntKey int16 `cf_vault:"my-secret-service/stage/tururur#my-key2"`
TestSda []int32 `cf_vault:"my-secret-service/stage/tururu#my-key3"`
}
By the way u can configuring files by environment variables:
For the best way to automatic publish versions of patch added github workflow for publish in master changes