Universal configuration library by tags
- hocon values
- default values
- environment variables
- vault configs
- json values
- yaml values
- ini values
- toml values
- int, int8, int16, int32, int64
- uint, uint8, uint16, uint32, uint64
- float32, float64
- string
- bool
- map[string\int]string\int\float32\float64
- slices of any types from (int32, int64, int, string, bool, float32, float64)
0.8:
- Adding support file store fetching 0.9:
- adding support key\value store backends (with callback)
- adding support config server fetching content like Spring Cloud Config Server
1.0:
- adding support uint types (done 0.6.6)
- change transition dependencies like go-yaml, lfjson by native map[string]interface{}\string
- Live watching for contract by git (maybe mechanism for watching changes like do it spring)
- CodeGen plugin for protoc for generating models with predefined tags
- cf_hocon - setup value for this field from hocon
- cf_default - setup default value for this field
- cf_env - setup value from env variable by name in this tag
- cf_yaml - setup value for this field from yaml
- cf_json - setup value for this field from json
- cf_ini - setup value for this field from ini
- cf_toml - setup value for this field from toml
- cf_vault - setup secret for this field from hashi corp vault
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 hocon files - GOSTRUCTOR_HOCON
- For json files - GOSTRUCTOR_JSON
- For yaml files - GOSTRUCTOR_YAML
- For ini files - GOSTRUCTOR_INI
- For toml files - GOSTRUCTOR_TOML
For the best way to automatic publish versions of patch added github workflow for publish in master changes
- Chose pool needed sources, and writed them into target field tag.
- Configuring environment.
- Needed setting up env variable