Skip to content

Commit

Permalink
feat: read config from env
Browse files Browse the repository at this point in the history
  • Loading branch information
Karan Sharma authored and mr-karan committed Oct 1, 2019
1 parent d8d7f88 commit 65ef23b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/knadh/koanf"
"github.com/knadh/koanf/maps"
"github.com/knadh/koanf/parsers/toml"
"github.com/knadh/koanf/providers/env"
"github.com/knadh/koanf/providers/file"
"github.com/knadh/koanf/providers/posflag"
"github.com/knadh/listmonk/manager"
Expand Down Expand Up @@ -109,9 +110,16 @@ func init() {
if os.IsNotExist(err) {
logger.Fatal("config file not found. If there isn't one yet, run --new-config to generate one.")
}
logger.Fatalf("error loadng config: %v.", err)
logger.Fatalf("error loadng config from file: %v.", err)
}
}
// Load environment variables and merge into the loaded config.
if err := ko.Load(env.Provider("LISTMONK_", ".", func(s string) string {
return strings.Replace(strings.ToLower(
strings.TrimPrefix(s, "LISTMONK_")), "__", ".", -1)
}), nil); err != nil {
logger.Fatalf("error loading config from env: %v", err)
}
ko.Load(posflag.Provider(f, ".", ko), nil)
}

Expand Down

0 comments on commit 65ef23b

Please sign in to comment.