-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc_test.go
55 lines (45 loc) · 1.24 KB
/
doc_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package dotenv_test
import (
"log"
"os"
dotenv "github.com/dsh2dsh/expx-dotenv"
)
func Example() {
if err := dotenv.New().Load(); err != nil {
log.Fatalf("error loading .env files: %v", err)
}
}
func Example_chainedCalls() {
if err := dotenv.New().WithDepth(1).WithEnvSuffix("test").Load(); err != nil {
log.Fatalf("error loading .env files: %v", err)
}
}
// func Example_withParse() {
// cfg := struct {
// SomeOpt string `env:"ENV_VAR1"`
// }{
// SomeOpt: "some default value, because we don't have .env file(s)",
// }
// err := dotenv.New().Load(func() error {
// return env.Parse(&cfg) //nolint:wrapcheck
// })
// if err != nil {
// log.Fatalf("error loading .env files: %v", err)
// }
// fmt.Println(cfg.SomeOpt)
// // Output: some default value, because we don't have .env file(s)
// }
func ExampleLoader_WithRootDir() {
// "ENV_ROOT" environment variable contains name of current environment.
dotenv.New().WithRootDir(os.Getenv("ENV_ROOT"))
}
func ExampleLoader_WithRootFiles() {
// stop at dir, which contains ".git"
dotenv.New().WithRootFiles(".git")
}
func ExampleLoader_WithRootCallback() {
env := dotenv.New()
env.WithRootCallback(func(path string) (bool, error) {
return env.FileExistsInDir(path, ".git")
})
}