LoadEnv loads env values from the supplied file
(file string)
| 20 | |
| 21 | // LoadEnv loads env values from the supplied file |
| 22 | func LoadEnv(file string) { |
| 23 | if file == "" { |
| 24 | log.Warn("Missing configuration file. Using defaults.") |
| 25 | return |
| 26 | } |
| 27 | |
| 28 | absFile, _ := filepath.Abs(file) |
| 29 | _, err := os.Stat(absFile) |
| 30 | fileNotExists := os.IsNotExist(err) |
| 31 | |
| 32 | if fileNotExists { |
| 33 | log.Warnf("Error reading configuration. File `%s` does not exist.", file) |
| 34 | return |
| 35 | } |
| 36 | |
| 37 | log.Printf("Configuration file: %s", absFile) |
| 38 | |
| 39 | // read file into env values |
| 40 | err = godotenv.Load(absFile) |
| 41 | if err != nil { |
| 42 | log.Fatalf("Error parsing configuration file: %s", err) |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | // Parse environment into a Config struct |
| 47 | func Parse() *Config { |
no outgoing calls