-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
40 lines (31 loc) · 743 Bytes
/
types.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
package main
import "fmt"
type (
EnvVarNotFoundError struct {
envVar string
}
EnvVarOptions struct {
Required bool
DefaultValue string
}
EnvVarOption func(*EnvVarOptions)
)
func (e EnvVarNotFoundError) Error() string {
return fmt.Sprintf("environment variable not found: %s", e.envVar)
}
func (e EnvVarNotFoundError) Is(template error) bool {
if template, ok := template.(EnvVarNotFoundError); ok {
return e.envVar == "" || e.envVar == template.envVar
}
return false
}
func WithIsRequired(required bool) EnvVarOption {
return func(opt *EnvVarOptions) {
opt.Required = required
}
}
func WithDefaultValue(defaultVal string) EnvVarOption {
return func(opt *EnvVarOptions) {
opt.DefaultValue = defaultVal
}
}