-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
59 lines (45 loc) · 993 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package config
import (
"errors"
"fmt"
"os"
"strings"
)
type Option func(*merger) error
var (
ErrLoggerIsEmpty = fmt.Errorf("logger is empty")
ErrEmptyConfigPath = errors.New("empty config path")
ErrConfigPath = errors.New("config path error")
ErrStageIsEmpty = errors.New("stage data is empty")
)
func WithLogger(logger Logger) Option {
return func(mc *merger) error {
if logger == Logger(nil) {
return ErrLoggerIsEmpty
}
mc.logger = logger
return nil
}
}
func withStageName(stage Stageable) Option {
return func(mc *merger) error {
if stage == nil {
return ErrStageIsEmpty
}
mc.stage = stage
return nil
}
}
func WithConfigPath(cfgPath string) Option {
return func(mc *merger) error {
if cfgPath == "" {
return ErrEmptyConfigPath
}
cfgPath = strings.TrimRight(cfgPath, "/")
if _, err := os.Stat(cfgPath); os.IsNotExist(err) {
return fmt.Errorf("%w: %s", ErrConfigPath, err)
}
mc.cfgPath = cfgPath
return nil
}
}