-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathexamples_test.go
More file actions
77 lines (63 loc) · 1.48 KB
/
examples_test.go
File metadata and controls
77 lines (63 loc) · 1.48 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package goconfig
import "time"
func ExampleLoad() {
type Server struct {
Host string `usage:"Server host"`
Port int `usage:"Server port"`
}
type Config struct {
Timeout time.Duration `usage:"Request timeout"`
Server Server
}
cfg := Config{
Timeout: 5 * time.Second,
Server: Server{
Host: "127.0.0.1",
Port: 8080,
},
}
_ = Load(&cfg,
WithArgs([]string{"-server.port", "9090"}),
WithoutImplicitConfigFile(),
WithEnvLookup(func(string) (string, bool) { return "", false }),
)
}
func ExampleLoad_apiService() {
type Config struct {
HTTPPort int `usage:"HTTP port"`
Timeout time.Duration `usage:"Request timeout"`
DB struct {
Host string `usage:"Database host"`
Port int `usage:"Database port"`
}
}
cfg := Config{
HTTPPort: 8080,
Timeout: 3 * time.Second,
}
_ = Load(&cfg)
}
func ExampleLoad_workerService() {
type Config struct {
Concurrency int `usage:"Worker concurrency"`
PollEvery time.Duration `usage:"Polling interval"`
Queues []string `usage:"Enabled queues"`
}
cfg := Config{
Concurrency: 4,
PollEvery: 2 * time.Second,
Queues: []string{"emails", "billing"},
}
_ = Load(&cfg)
}
func ExampleLoad_cliTool() {
type Config struct {
ConfigPath string `usage:"Path to config file"`
Verbose bool `usage:"Enable verbose output"`
}
cfg := Config{}
_ = Load(&cfg,
WithArgs([]string{"-verbose", "-configpath", "./dev.json"}),
WithoutImplicitConfigFile(),
)
}