-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathoption.go
53 lines (45 loc) · 1.15 KB
/
option.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
package config
import (
"os"
"path"
)
// Options are options for the [ConfigFactory] implementations.
type Options struct {
FileName string
FilePaths []string
}
// DefaultConfigOptions are the default options used in the [DefaultConfigFactory].
func DefaultConfigOptions() Options {
opts := Options{
FileName: "config",
FilePaths: []string{
".",
"./config",
"./configs",
},
}
// KO embeddings, see https://ko.build/features/static-assets/
if val, ok := os.LookupEnv("KO_DATA_PATH"); ok {
opts.FilePaths = append(
opts.FilePaths,
val,
path.Join(val, "config"),
path.Join(val, "configs"),
)
}
return opts
}
// ConfigOption are functional options for the [ConfigFactory] implementations.
type ConfigOption func(o *Options)
// WithFileName is used to specify the file base name (without extension) of the config file to load.
func WithFileName(n string) ConfigOption {
return func(o *Options) {
o.FileName = n
}
}
// WithFilePaths is used to specify the list of file paths to lookup config files to load.
func WithFilePaths(p ...string) ConfigOption {
return func(o *Options) {
o.FilePaths = append(o.FilePaths, p...)
}
}