/
provider.go
33 lines (30 loc) · 960 Bytes
/
provider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package config
import (
"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
)
type Provider interface {
GetString(key string) string
GetInt(key string) int
GetBool(key string) bool
GetStringMap(key string) map[string]interface{}
GetStringMapString(key string) map[string]string
GetStringSlice(key string) []string
Get(key string) interface{}
Set(key string, value interface{})
IsSet(key string) bool
WatchConfig()
OnConfigChange(run func(in fsnotify.Event))
Unmarshal(rawVal interface{}, opts ...viper.DecoderConfigOption) error
UnmarshalKey(key string, rawVal interface{}, opts ...viper.DecoderConfigOption) error
}
// FromConfigString creates a config from the given YAML, JSON or TOML config. This is useful in tests.
func FromConfigString(path, configType string) (Provider, error) {
v := viper.New()
v.SetConfigType(configType)
v.SetConfigFile(path)
if err := v.ReadInConfig(); err != nil {
return nil, err
}
return v, nil
}