generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mode_dotenv_test.go
130 lines (111 loc) · 3.16 KB
/
mode_dotenv_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package ferrite_test
import (
"os"
"time"
"github.com/dogmatiq/ferrite"
)
func ExampleInit_exportDotEnvFile() {
defer example()()
os.Setenv("FERRITE_BINARY", "PHZhbHVlPg==")
ferrite.
Binary("FERRITE_BINARY", "example binary").
Required()
os.Setenv("FERRITE_BINARY_SENSITIVE", "aHVudGVyMg==")
ferrite.
Binary("FERRITE_BINARY_SENSITIVE", "example sensitive binary").
WithDefault([]byte("password")).
WithSensitiveContent().
Required()
os.Setenv("FERRITE_BOOL", "true")
ferrite.
Bool("FERRITE_BOOL", "example bool").
Required()
os.Setenv("FERRITE_DURATION", "620s")
ferrite.
Duration("FERRITE_DURATION", "example duration").
WithDefault(1 * time.Hour).
Required()
ferrite.
Enum("FERRITE_ENUM", "example enum").
WithMembers("foo", "bar", "baz").
WithDefault("bar").
Required()
os.Setenv("FERRITE_NETWORK_PORT", "8080")
ferrite.
NetworkPort("FERRITE_NETWORK_PORT", "example network port").
Optional()
ferrite.
Float[float32]("FERRITE_NUM_FLOAT", "example floating-point").
Required()
ferrite.
Signed[int16]("FERRITE_NUM_SIGNED", "example signed integer").
Required()
ferrite.
Unsigned[uint16]("FERRITE_NUM_UNSIGNED", "example unsigned integer").
Required()
os.Setenv("FERRITE_STRING", "hello, world!")
ferrite.
String("FERRITE_STRING", "example string").
Required()
os.Setenv("FERRITE_STRING_SENSITIVE", "hunter2")
ferrite.
String("FERRITE_STRING_SENSITIVE", "example sensitive string").
WithDefault("password").
WithSensitiveContent().
Required()
os.Setenv("FERRITE_SVC_SERVICE_HOST", "host.example.org")
os.Setenv("FERRITE_SVC_SERVICE_PORT", "443")
ferrite.
KubernetesService("ferrite-svc").
Deprecated()
os.Setenv("FERRITE_URL", "https//example.org")
ferrite.
URL("FERRITE_URL", "example URL").
Required()
// Tell ferrite to export an env file containing the environment variables.
os.Setenv("FERRITE_MODE", "export/dotenv")
ferrite.Init()
// Output:
// # example binary (required)
// export FERRITE_BINARY=PHZhbHVlPg==
//
// # example sensitive binary (default: {12 bytes}, sensitive)
// export FERRITE_BINARY_SENSITIVE=aHVudGVyMg==
//
// # example bool (required)
// export FERRITE_BOOL=true
//
// # example duration (default: 1h)
// export FERRITE_DURATION=620s # equivalent to 10m20s
//
// # example enum (default: bar)
// export FERRITE_ENUM=
//
// # example network port (optional)
// export FERRITE_NETWORK_PORT=8080
//
// # example floating-point (required)
// export FERRITE_NUM_FLOAT=
//
// # example signed integer (required)
// export FERRITE_NUM_SIGNED=
//
// # example unsigned integer (required)
// export FERRITE_NUM_UNSIGNED=
//
// # example string (required)
// export FERRITE_STRING='hello, world!'
//
// # example sensitive string (default: ********, sensitive)
// export FERRITE_STRING_SENSITIVE=hunter2
//
// # kubernetes "ferrite-svc" service host (deprecated)
// export FERRITE_SVC_SERVICE_HOST=host.example.org
//
// # kubernetes "ferrite-svc" service port (deprecated)
// export FERRITE_SVC_SERVICE_PORT=443
//
// # example URL (required)
// export FERRITE_URL= # https//example.org is invalid: URL must have a scheme
// <process exited successfully>
}