-
Notifications
You must be signed in to change notification settings - Fork 10
/
config.go
47 lines (38 loc) · 1012 Bytes
/
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
package main
import (
"fmt"
"os"
"github.com/cloudfoundry/pcap-release/src/pcap"
"github.com/go-playground/validator/v10"
"gopkg.in/yaml.v3"
)
var DefaultConfig = Config{
pcap.NodeConfig{
Listen: pcap.Listen{Port: 9494}, //nolint:gomnd // default value used for testing
Buffer: pcap.BufferConf{
Size: 1000, //nolint:gomnd // default value used for testing
UpperLimit: 995, //nolint:gomnd // default value used for testing
LowerLimit: 900, //nolint:gomnd // default value used for testing
},
LogLevel: "debug",
ID: "test-agent",
},
}
type Config struct {
pcap.NodeConfig `yaml:"-,inline"`
}
func (c Config) validate() error {
return validator.New().Struct(c)
}
func parseConfig(path string) (Config, error) {
f, err := os.Open(path)
if err != nil {
return DefaultConfig, fmt.Errorf("parse config: %w", err)
}
var c Config
err = yaml.NewDecoder(f).Decode(&c)
if err != nil {
return DefaultConfig, fmt.Errorf("parse config: %w", err)
}
return c, nil
}