Documentation ¶
Index ¶
- Constants
- func NormalizeKey(key string, configures ...func(*Options)) string
- func ProcessKeyFormat(nested map[string]interface{}, ...) (map[string]interface{}, error)
- func UnFlatten(flat map[string]interface{}, configures ...func(*UfOptions)) (nested map[string]interface{}, err error)
- func UnFlattenKey(k string, configures ...func(*Options)) []string
- func VisitEach(nested map[string]interface{}, apply func(string, interface{}) error, ...) error
- type ApplicationConfig
- func (c *ApplicationConfig) Bind(target interface{}, prefix string) error
- func (c *ApplicationConfig) Each(apply func(string, interface{}) error) error
- func (c *ApplicationConfig) HasProfile(profile string) bool
- func (c *ApplicationConfig) Load(ctx context.Context, force bool) (err error)
- func (c *ApplicationConfig) Profiles() []string
- func (c *ApplicationConfig) ProviderGroups() []ProviderGroup
- func (c *ApplicationConfig) Providers() []Provider
- func (c *ApplicationConfig) Value(key string) interface{}
- type BootstrapConfig
- func (c *BootstrapConfig) Bind(target interface{}, prefix string) error
- func (c *BootstrapConfig) Each(apply func(string, interface{}) error) error
- func (c *BootstrapConfig) HasProfile(profile string) bool
- func (c *BootstrapConfig) Load(ctx context.Context, force bool) (err error)
- func (c *BootstrapConfig) Profiles() []string
- func (c *BootstrapConfig) ProviderGroups() []ProviderGroup
- func (c *BootstrapConfig) Providers() []Provider
- func (c *BootstrapConfig) Value(key string) interface{}
- type ConfigAccessor
- type DynamicProviderGroup
- type Options
- type ProfileBasedProviderGroup
- type Provider
- type ProviderGroup
- type ProviderMeta
- type ProviderReorderer
- type StaticProviderGroup
- type UfOptions
Constants ¶
const ( PropertyKeyActiveProfiles = "application.profiles.active" PropertyKeyAdditionalProfiles = "application.profiles.additional" PropertyKeyConfigFileSearchPath = "config.file.search-path" PropertyKeyApplicationName = bootstrap.PropertyKeyApplicationName PropertyKeyBuildInfo = "application.build" )
Variables ¶
This section is empty.
Functions ¶
func NormalizeKey ¶
NormalizeKey convert camelCase key to snake-case
func ProcessKeyFormat ¶
func ProcessKeyFormat(nested map[string]interface{}, processor func(string, ...func(*Options)) string) (map[string]interface{}, error)
ProcessKeyFormat traverse given map in DFS fashion and apply given processor to each KV pair
func UnFlatten ¶
func UnFlatten(flat map[string]interface{}, configures ...func(*UfOptions)) (nested map[string]interface{}, err error)
UnFlatten supports un-flattening keys with index like the following
my-example.url[0]=https://example.com
The indexed entries are treated like an unsorted list. The result will be a list but the order is not guaranteed to reflect the index order. A key with multiple index (a.b[0].c[0) is not supported
func UnFlattenKey ¶
Types ¶
type ApplicationConfig ¶
type ApplicationConfig struct {
// contains filtered or unexported fields
}
func NewApplicationConfig ¶
func NewApplicationConfig(groups ...ProviderGroup) *ApplicationConfig
func (*ApplicationConfig) Each ¶
Each go through all properties and apply given function. It stops at the first error
func (*ApplicationConfig) HasProfile ¶
func (*ApplicationConfig) Load ¶
Load will fail if place holder cannot be resolved due to circular dependency
func (*ApplicationConfig) ProviderGroups ¶
func (c *ApplicationConfig) ProviderGroups() []ProviderGroup
type BootstrapConfig ¶
type BootstrapConfig struct {
// contains filtered or unexported fields
}
func NewBootstrapConfig ¶
func NewBootstrapConfig(groups ...ProviderGroup) *BootstrapConfig
func (*BootstrapConfig) Each ¶
Each go through all properties and apply given function. It stops at the first error
func (*BootstrapConfig) HasProfile ¶
func (*BootstrapConfig) Load ¶
Load will fail if place holder cannot be resolved due to circular dependency
func (*BootstrapConfig) ProviderGroups ¶
func (c *BootstrapConfig) ProviderGroups() []ProviderGroup
type ConfigAccessor ¶
type DynamicProviderGroup ¶
type DynamicProviderGroup struct { Precedence int ProviderKeys []string // Provider should be sorted all time based on their provider's ordering ProviderLookup map[string]Provider ResolvedProviders []Provider ProcessFunc func(context.Context, []Provider) []Provider // ProcessFunc is invoked before setting ResolvedProviders. Last chance to change }
DynamicProviderGroup implements ProviderGroup, and holds a sorted list of keys and their corresponding Provider. This type is typically used as embedded struct
func NewDynamicProviderGroup ¶
func NewDynamicProviderGroup(order int) *DynamicProviderGroup
func (*DynamicProviderGroup) Order ¶
func (g *DynamicProviderGroup) Order() int
func (*DynamicProviderGroup) Providers ¶
func (g *DynamicProviderGroup) Providers(ctx context.Context, _ bootstrap.ApplicationConfig) (providers []Provider)
func (*DynamicProviderGroup) Reset ¶
func (g *DynamicProviderGroup) Reset()
type Options ¶
type Options struct {
Delimiter string
}
Options the flatten options. By default: Delimiter = "."
type ProfileBasedProviderGroup ¶
type ProfileBasedProviderGroup struct { DynamicProviderGroup KeyFunc func(profile string) (key string) CreateFunc func(name string, order int, conf bootstrap.ApplicationConfig) Provider }
ProfileBasedProviderGroup extends DynamicProviderGroup and implements ProviderGroup it provide base methods to determine Providers based on PropertyKeyActiveProfiles
func NewProfileBasedProviderGroup ¶
func NewProfileBasedProviderGroup(order int) *ProfileBasedProviderGroup
func (*ProfileBasedProviderGroup) Providers ¶
func (g *ProfileBasedProviderGroup) Providers(ctx context.Context, conf bootstrap.ApplicationConfig) (providers []Provider)
type Provider ¶
type Provider interface { order.Ordered // Name is unique name of given provider, it also used as primary key in any mapping Name() string // Load load settings and should be idempotent. e.g. calling it multiple times should not affect loaded settings Load(ctx context.Context) error // GetSettings returns loaded settings. might be nil if not IsLoaded returns true // The returned map should be un-flattened. i.e. flat.key=value should be stored as {"flat":{"key":"value"}} GetSettings() map[string]interface{} // IsLoaded should return true if Load is invoked at least once IsLoaded() bool // Reset delete loaded settings and reset IsLoaded flag Reset() }
type ProviderGroup ¶
type ProviderGroup interface { order.Ordered // Providers returns providers based on given config. // This method should be idempotent. e.g. calling it multiple times with same config always returns identical slice Providers(ctx context.Context, config bootstrap.ApplicationConfig) []Provider // Reset should mark all providers unloaded Reset() }
ProviderGroup determines Providers based on given bootstrap.ApplicationConfig
type ProviderMeta ¶
type ProviderMeta struct { Loaded bool //invalid if not loaded or during load Settings map[string]interface{} //storage for the settings loaded by the auth Precedence int //the precedence for which the settings will take effect. }
ProviderMeta implements ProviderReorderer and partial ProviderMeta
func (ProviderMeta) GetSettings ¶
func (m ProviderMeta) GetSettings() map[string]interface{}
func (ProviderMeta) IsLoaded ¶
func (m ProviderMeta) IsLoaded() bool
func (ProviderMeta) Order ¶
func (m ProviderMeta) Order() int
func (*ProviderMeta) Reorder ¶
func (m *ProviderMeta) Reorder(order int)
func (*ProviderMeta) Reset ¶
func (m *ProviderMeta) Reset()
type ProviderReorderer ¶
type ProviderReorderer interface { // Reorder set order Reorder(int) }
type StaticProviderGroup ¶
StaticProviderGroup implements ProviderGroup, and holds fixed provider list
func NewStaticProviderGroup ¶
func NewStaticProviderGroup(order int, providers ...Provider) *StaticProviderGroup
func (StaticProviderGroup) Order ¶
func (g StaticProviderGroup) Order() int
func (StaticProviderGroup) Providers ¶
func (g StaticProviderGroup) Providers(_ context.Context, _ bootstrap.ApplicationConfig) []Provider
func (*StaticProviderGroup) Reset ¶
func (g *StaticProviderGroup) Reset()