summaryrefslogtreecommitdiff
path: root/plugins/config
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-10-19 14:01:59 +0300
committerValery Piashchynski <[email protected]>2020-10-19 14:01:59 +0300
commit77670fb7af0c892c9b3a589fd424534fad288e7a (patch)
tree3adcaa85db664a355abe2b28f1d7e4a3fc45689f /plugins/config
parent16fbf3104c3c34bd9355593052b686acd26a8efe (diff)
Update according activity worker
Diffstat (limited to 'plugins/config')
-rw-r--r--plugins/config/provider.go4
-rw-r--r--plugins/config/tests/plugin1.go9
-rw-r--r--plugins/config/viper.go9
3 files changed, 17 insertions, 5 deletions
diff --git a/plugins/config/provider.go b/plugins/config/provider.go
index bec417e9..580231fd 100644
--- a/plugins/config/provider.go
+++ b/plugins/config/provider.go
@@ -10,6 +10,10 @@ type Provider interface {
// }
// }
UnmarshalKey(name string, out interface{}) error
+
// Get used to get config section
Get(name string) interface{}
+
+ // Has checks if config section exists.
+ Has(name string) bool
}
diff --git a/plugins/config/tests/plugin1.go b/plugins/config/tests/plugin1.go
index 7573dc82..7c5f2afd 100644
--- a/plugins/config/tests/plugin1.go
+++ b/plugins/config/tests/plugin1.go
@@ -15,18 +15,17 @@ type ReloadConfig struct {
}
type ServiceConfig struct {
- Enabled bool
+ Enabled bool
Recursive bool
- Patterns []string
- Dirs []string
- Ignore []string
+ Patterns []string
+ Dirs []string
+ Ignore []string
}
type Foo struct {
configProvider config.Provider
}
-
// Depends on S2 and DB (S3 in the current case)
func (f *Foo) Init(p config.Provider) error {
f.configProvider = p
diff --git a/plugins/config/viper.go b/plugins/config/viper.go
index 0362e79b..b276dbe2 100644
--- a/plugins/config/viper.go
+++ b/plugins/config/viper.go
@@ -17,17 +17,21 @@ type ViperProvider struct {
//////// ENDURE //////////
func (v *ViperProvider) Init() error {
v.viper = viper.New()
+
// read in environment variables that match
v.viper.AutomaticEnv()
if v.Prefix == "" {
return errors.New("prefix should be set")
}
+
v.viper.SetEnvPrefix(v.Prefix)
if v.Path == "" {
return errors.New("path should be set")
}
+
v.viper.SetConfigFile(v.Path)
v.viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
+
return v.viper.ReadInConfig()
}
@@ -62,6 +66,11 @@ func (v *ViperProvider) Get(name string) interface{} {
return v.viper.Get(name)
}
+// Has checks if config section exists.
+func (v *ViperProvider) Has(name string) bool {
+ return v.viper.IsSet(name)
+}
+
/////////// PRIVATE //////////////
func parseFlag(flag string) (string, string, error) {