Skip to content

Commit

Permalink
feat: support env vars configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
krau committed Jan 20, 2025
1 parent 2a9c615 commit a778b0f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion config/viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package config
import (
"fmt"
"os"
"strings"

"github.com/spf13/viper"
)

type Config struct {
Workers int `toml:"workers" mapstructure:"workers"`
Retry int `toml:"retry" mapstructure:"retry"` // Retry times for failed tasks
Retry int `toml:"retry" mapstructure:"retry"`

Temp tempConfig `toml:"temp" mapstructure:"temp"`
Log logConfig `toml:"log" mapstructure:"log"`
Expand Down Expand Up @@ -79,7 +80,12 @@ var Cfg *Config
func Init() {
viper.SetConfigName("config")
viper.AddConfigPath(".")
viper.AddConfigPath("/etc/saveany/")
viper.SetConfigType("toml")
viper.SetEnvPrefix("SAVEANY")
viper.AutomaticEnv()
replacer := strings.NewReplacer(".", "_")
viper.SetEnvKeyReplacer(replacer)

viper.SetDefault("workers", 3)
viper.SetDefault("retry", 3)
Expand Down

0 comments on commit a778b0f

Please sign in to comment.