package config import ( "github.com/joho/godotenv" "github.com/mitchellh/mapstructure" ) type Config struct { AppPortListen string `mapstructure:"APP_PORT"` JwtKey []byte } func LoadConfig(filename ...string) (*Config, error) { var myenv map[string]string var err error var c Config if len(filename) == 0 { myenv, err = godotenv.Read() } else { myenv, err = godotenv.Read(filename[0]) } if err != nil { return nil, err } mapstructure.Decode(myenv, &c) c.JwtKey = []byte(c.StringKey) return &c, nil }