-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyaml_config_parser.go
More file actions
52 lines (41 loc) · 1.53 KB
/
yaml_config_parser.go
File metadata and controls
52 lines (41 loc) · 1.53 KB
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
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
"gopkg.in/yaml.v3"
)
var AppConfig Config
type Config struct {
DataMonitorLogLevel string `yaml:"datamonitor_log_level"`
DataMonitorLogFile string `yaml:"datamonitor_log_file"`
DataMonitorHookedFunctions string `yaml:"datamonitor_hooked_functions"`
DataMonitorRedactedTextClipboard bool `yaml:"datamonitor_redacted_text_clipboard"`
DataMonitorHTTPForwardEvents HttpForwardEvents `yaml:"datamonitor_http_forward_events"`
}
type HttpForwardEvents struct {
Enabled bool `yaml:"enabled"`
DataBatchSendInterval int `yaml:"data_batch_send_interval"`
URL string `yaml:"url"`
Headers *map[string]string `yaml:"headers"`
}
func LoadConfig(configPath string) error {
absConfigPath, err := filepath.Abs(configPath)
if err != nil {
return fmt.Errorf("failed to get absolute path for config file '%s': %w", configPath, err)
}
configData, err := os.ReadFile(absConfigPath)
if err != nil {
return fmt.Errorf("failed to read config file '%s': %w", absConfigPath, err)
}
err = yaml.Unmarshal(configData, &AppConfig)
if err != nil {
return fmt.Errorf("failed to unmarshal config data from '%s': %w", absConfigPath, err)
}
if AppConfig.DataMonitorLogLevel == "" {
AppConfig.DataMonitorLogLevel = "LOGLEVEL_INFO"
}
AppConfig.DataMonitorLogLevel = strings.ToUpper(AppConfig.DataMonitorLogLevel)
return nil
}