Merge pull request #18 from mr-karan/kubernetes

feat: read config from env
This commit is contained in:
Kailash Nadh 2019-10-01 18:04:37 +05:30 committed by GitHub
commit ff4060102f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

10
main.go
View File

@ -15,6 +15,7 @@ import (
"github.com/knadh/koanf" "github.com/knadh/koanf"
"github.com/knadh/koanf/maps" "github.com/knadh/koanf/maps"
"github.com/knadh/koanf/parsers/toml" "github.com/knadh/koanf/parsers/toml"
"github.com/knadh/koanf/providers/env"
"github.com/knadh/koanf/providers/file" "github.com/knadh/koanf/providers/file"
"github.com/knadh/koanf/providers/posflag" "github.com/knadh/koanf/providers/posflag"
"github.com/knadh/listmonk/manager" "github.com/knadh/listmonk/manager"
@ -109,9 +110,16 @@ func init() {
if os.IsNotExist(err) { if os.IsNotExist(err) {
logger.Fatal("config file not found. If there isn't one yet, run --new-config to generate one.") 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) ko.Load(posflag.Provider(f, ".", ko), nil)
} }