MCPcopy Index your code
hub / github.com/coder/coder / loadEnvFile

Function loadEnvFile

scripts/develop/main.go:487–503  ·  view source on GitHub ↗

loadEnvFile reads the file at path using godotenv and sets any variables not already present in the process environment. It returns the number of variables set.

(path string)

Source from the content-addressed store, hash-verified

485// not already present in the process environment. It returns the number of
486// variables set.
487func loadEnvFile(path string) (int, error) {
488 vars, err := godotenv.Read(path)
489 if err != nil {
490 return 0, err
491 }
492 var n int
493 for key, val := range vars {
494 if _, exists := os.LookupEnv(key); exists {
495 continue
496 }
497 if err := os.Setenv(key, val); err != nil {
498 return n, err
499 }
500 n++
501 }
502 return n, nil
503}
504
505// filterEnv returns env with any variables whose key matches exclude removed.
506func filterEnv(env []string, exclude ...string) []string {

Callers 2

TestLoadEnvFileFunction · 0.85
mainFunction · 0.85

Calls 2

SetenvMethod · 0.80
ReadMethod · 0.65

Tested by 1

TestLoadEnvFileFunction · 0.68