I am trying to move all my configs for my web server to env vars, Problem is viper is not reading them. I get an error about Config File "config" Not Found in "[]"
Is there any way for me to read all my env vars which are present in .env files, without actually adding viper.SetConfigFile(".env") As the file will not be present in my containerised environments. Here is my config loader code
package server
import (
"fmt"
"os"
"strings"
"github.com/spf13/viper"
)
type Config struct {
Environment string `mapstructure:"ENVIRONMENT"`
BindAddress string `mapstructure:"BIND_ADDR"`
}
func LoadConfig() (config Config, err error) {
viper.SetEnvPrefix("MAILER_")
viper.AutomaticEnv()
err = viper.ReadInConfig()
if err != nil {
// Added a panic for debug purpose
panic("Error occurred while loading env vars")
}
viper.Unmarshal(&config)
return
}