Skip to content

Commit

Permalink
feat: allow configuration overrides from environment
Browse files Browse the repository at this point in the history
  • Loading branch information
noodnik2 committed Feb 16, 2024
1 parent 9b17d5f commit e116c5a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import (
"strings"

"github.com/noodnik2/gochat/internal/adapter/chatter"
"github.com/noodnik2/gochat/internal/adapter/scriber"
"github.com/spf13/viper"
Expand Down Expand Up @@ -40,9 +42,15 @@ type Config struct {
}

func Load() (Config, error) {
viper.SetEnvPrefix("gochat")
viper.SetConfigName("config-local")
viper.AddConfigPath("config")

// the following enables you to override configuration values with environment variables
// prefixed with "GOCHAT_"; e.g., "make run-chat GOCHAT_CHATTER_ADAPTER=Gemini"
viper.AutomaticEnv()
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))

var cfg Config

errParse := viper.ReadInConfig()
Expand Down

0 comments on commit e116c5a

Please sign in to comment.