✨ Allow MYLOG_CONFIG_PATH to override the config path
This commit is contained in:
parent
b7eaf941fb
commit
edf10de879
4 changed files with 18 additions and 20 deletions
|
|
@ -32,7 +32,7 @@ func AddToContext(ctx context.Context, v *viper.Viper) context.Context {
|
|||
return context.WithValue(ctx, viperKey, v)
|
||||
}
|
||||
|
||||
func New(ctx context.Context) (context.Context, *viper.Viper, error) {
|
||||
func New(ctx context.Context, path string) (context.Context, *viper.Viper, error) {
|
||||
v := viper.New()
|
||||
v.SetConfigType("toml")
|
||||
|
||||
|
|
@ -40,12 +40,16 @@ func New(ctx context.Context) (context.Context, *viper.Viper, error) {
|
|||
return ctx, nil, err
|
||||
}
|
||||
|
||||
v.SetConfigFile(DefaultPath())
|
||||
if path == "" {
|
||||
path = DefaultPath()
|
||||
}
|
||||
|
||||
v.SetConfigFile(path)
|
||||
v.SetEnvPrefix("MYLOG")
|
||||
v.AutomaticEnv()
|
||||
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_"))
|
||||
|
||||
if err := v.ReadInConfig(); err != nil {
|
||||
if err := v.MergeInConfig(); err != nil {
|
||||
return ctx, nil, err
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue