-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
41 lines (35 loc) · 886 Bytes
/
options.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
package dotenv
const (
defaultAnchorFile = "go.mod"
defaultEnvFilename = ".env"
)
// Config holds configuration for locating the .env file.
type Config struct {
AnchorFile string
EnvFilename string
}
// Option represents an option for configuring the dotenv loader.
type Option func(*Config)
// NewConfig creates a new dotenv configuration with provided options.
func NewConfig(options []Option) *Config {
conf := &Config{
AnchorFile: defaultAnchorFile,
EnvFilename: defaultEnvFilename,
}
for _, option := range options {
option(conf)
}
return conf
}
// WithAnchorFile specifies a custom anchor file.
func WithAnchorFile(filename string) Option {
return func(c *Config) {
c.AnchorFile = filename
}
}
// WithEnvFilename specifies a custom .env filename.
func WithEnvFilename(filename string) Option {
return func(c *Config) {
c.EnvFilename = filename
}
}