-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathconfig.go
54 lines (44 loc) · 1.25 KB
/
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
49
50
51
52
53
54
package blackbox
import (
"os"
"code.cloudfoundry.org/blackbox/syslog"
"gopkg.in/yaml.v3"
)
type SyslogConfig struct {
Destination syslog.Drain `yaml:"destination"`
SourceDir string `yaml:"source_dir"`
ExcludeFilePattern string `yaml:"exclude_file_pattern"`
LogFilename bool `yaml:"log_filename"`
}
type Config struct {
Hostname string `yaml:"hostname"`
StructuredDataID string `yaml:"structured_data_id"`
StructuredDataMap map[string]string `yaml:"structured_data_map"`
Syslog SyslogConfig `yaml:"syslog"`
UseRFC3339 bool `yaml:"use_rfc3339"`
MaxMessageSize int `yaml:"max_message_size"`
}
func LoadConfig(path string) (*Config, error) {
configFile, err := os.ReadFile(path)
if err != nil {
return nil, err
}
var config Config
if err := yaml.Unmarshal(configFile, &config); err != nil {
return nil, err
}
if config.Hostname == "" {
hostname, err := os.Hostname()
if err != nil {
return nil, err
}
config.Hostname = hostname
}
if config.MaxMessageSize == 0 {
config.MaxMessageSize = 99990
}
if config.Syslog.Destination.Transport == "udp" {
config.MaxMessageSize = 1024
}
return &config, nil
}