Skip to content
This repository has been archived by the owner on Dec 26, 2024. It is now read-only.

Commit

Permalink
feat: allow env variables inside config (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
buroa authored Dec 12, 2024
1 parent 1f0dbcb commit 37d21ed
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions internal/domain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/knadh/koanf"
"github.com/knadh/koanf/parsers/yaml"
"github.com/knadh/koanf/providers/file"
"github.com/knadh/koanf/providers/rawbytes"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
)
Expand Down Expand Up @@ -123,7 +123,20 @@ func NewConfig(configPath string) *Config {
}
}

if err := k.Load(file.Provider(configPath), yaml.Parser()); err != nil {
content, err := os.ReadFile(configPath)
if err != nil {
log.Fatal().
Err(err).
Str("service", "config").
Msgf("failed reading %q", configPath)
}

// expand env vars
expandedContent := os.ExpandEnv(string(content))
provider := rawbytes.Provider([]byte(expandedContent))

// load
if err := k.Load(provider, yaml.Parser()); err != nil {
log.Fatal().
Err(err).
Str("service", "config").
Expand Down

0 comments on commit 37d21ed

Please sign in to comment.