-
Notifications
You must be signed in to change notification settings - Fork 88
/
options.go
44 lines (36 loc) · 987 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
42
43
44
package config
import (
"os"
"github.com/bacalhau-project/bacalhau/pkg/config/types"
"github.com/spf13/viper"
)
type Option func(options *Params)
func WithFileName(name string) Option {
return func(options *Params) {
options.FileName = name
}
}
func WithDefaultConfig(cfg types.BacalhauConfig) Option {
return func(options *Params) {
options.DefaultConfig = cfg
}
}
func WithFileHandler(handler func(name string) error) Option {
return func(options *Params) {
options.FileHandler = handler
}
}
func NoopConfigHandler(filename string) error {
return nil
}
func ReadConfigHandler(fileName string) error {
if _, err := os.Stat(fileName); os.IsNotExist(err) {
// if the config file doesn't exist that's fine, we will just use default configuration values
// dictated by the environment
return nil
} else if err != nil {
return err
}
// else we will read values set from the config, and accept those over the default values.
return viper.ReadInConfig()
}