-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_config.go
48 lines (39 loc) · 1.12 KB
/
json_config.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
package input
import (
"errors"
"github.com/rodb-io/rodb/pkg/parser"
"github.com/sirupsen/logrus"
"os"
)
type JsonConfig struct {
Name string `yaml:"name"`
Type string `yaml:"type"`
Path string `yaml:"path"`
DieOnInputChange *bool `yaml:"dieOnInputChange"`
Logger *logrus.Entry
}
func (config *JsonConfig) GetName() string {
return config.Name
}
func (config *JsonConfig) ShouldDieOnInputChange() bool {
return config.DieOnInputChange == nil || *config.DieOnInputChange
}
func (config *JsonConfig) Validate(parsers map[string]parser.Config, log *logrus.Entry) error {
config.Logger = log
if config.Name == "" {
return errors.New("json.name is required")
}
if config.DieOnInputChange == nil {
defaultValue := true
log.Debugf("json.dieOnInputChange is not set. Assuming 'true'.\n")
config.DieOnInputChange = &defaultValue
}
fileInfo, err := os.Stat(config.Path)
if os.IsNotExist(err) {
return errors.New("The json file '" + config.Path + "' does not exist")
}
if fileInfo.IsDir() {
return errors.New("The path '" + config.Path + "' is not a file")
}
return nil
}