MCPcopy Create free account
hub / github.com/kataras/iris / Load

Function Load

_examples/database/mongodb/env/env.go:38–67  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

36//
37// After `Load` the callers can get an environment variable via `os.Getenv`.
38func 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
69func getDefault(key string, def string) string {
70 value := os.Getenv(key)

Callers

nothing calls this directly

Calls 4

parseFunction · 0.85
fileExistsFunction · 0.70
ExtMethod · 0.65
LoadMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…