Load loads environment variables that are being used across the whole app. Loading from file(s), i.e .env or dev.env Example of a 'dev.env': PORT=8080 DSN=mongodb://localhost:27017 After `Load` the callers can get an environment variable via `os.Getenv`.
(envFileName string)
| 36 | // |
| 37 | // After `Load` the callers can get an environment variable via `os.Getenv`. |
| 38 | func Load(envFileName string) { |
| 39 | if args := os.Args; len(args) > 1 && args[1] == "help" { |
| 40 | fmt.Fprintln(os.Stderr, "https://github.com/kataras/iris/blob/main/_examples/database/mongodb/README.md") |
| 41 | os.Exit(-1) |
| 42 | } |
| 43 | |
| 44 | // If more than one filename passed with comma separated then load from all |
| 45 | // of these, a env file can be a partial too. |
| 46 | envFiles := strings.Split(envFileName, ",") |
| 47 | for _, envFile := range envFiles { |
| 48 | if filepath.Ext(envFile) == "" { |
| 49 | envFile += ".env" |
| 50 | } |
| 51 | |
| 52 | if fileExists(envFile) { |
| 53 | log.Printf("Loading environment variables from file: %s\n", envFile) |
| 54 | |
| 55 | if err := godotenv.Load(envFile); err != nil { |
| 56 | panic(fmt.Sprintf("error loading environment variables from [%s]: %v", envFile, err)) |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | // envMap, _ := godotenv.Read(envFiles...) |
| 62 | // for k, v := range envMap { |
| 63 | // log.Printf("◽ %s=%s\n", k, v) |
| 64 | // } |
| 65 | |
| 66 | parse() |
| 67 | } |
| 68 | |
| 69 | func getDefault(key string, def string) string { |
| 70 | value := os.Getenv(key) |
nothing calls this directly
no test coverage detected
searching dependent graphs…