-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfiguration.go
75 lines (64 loc) · 1.75 KB
/
configuration.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"fmt"
"log"
"os"
"gopkg.in/yaml.v3"
)
// configuration structures
// ========================
type ApplicationConfig struct {
DateLayout string `yaml:"DateLayout"`
OutputFolder string `yaml:"OutputFolder"`
DefaultFile2analyze string `yaml:"DefaultLog2analyze"`
LogType string `yaml:"LogType"`
Logcfg LogConfig `yaml:"LogConfig"`
}
type LogConfig struct {
LogLevel string `yaml:"LogLevel"`
LogFolder string `yaml:"LogFolder"`
}
func (config *ApplicationConfig) Initialize(configPath *string) {
// 1. set defaults
config.setDefaults()
// 2. read config and run with defaults if not found
file := GetCleanPath(*configPath)
yamlFile, err := os.ReadFile(file)
if err != nil {
fmt.Println("could not read config from " + file + ", will run with defaults.")
} else {
if err = yaml.Unmarshal(yamlFile, &config); err != nil {
log.Fatalln("ERROR parsing config", fmt.Sprint(err))
}
}
config.CheckConfig()
}
func (config *ApplicationConfig) setDefaults() {
*config = ApplicationConfig{
DateLayout: "02/Jan/2006:15:04:05 -0700",
OutputFolder: "./output/",
LogType: "apache_atmire",
Logcfg: LogConfig{
LogLevel: "INFO",
LogFolder: "./logs/",
},
}
}
func (c *ApplicationConfig) CheckConfig() {
// TODO: hier könnte noch ein DateLayoutCheck rein
checknaddtrailingslash(&c.Logcfg.LogFolder)
// check if the log folder exists
if !CheckIfDir(c.Logcfg.LogFolder) {
ToBeCreated(c.Logcfg.LogFolder)
}
checknaddtrailingslash(&c.OutputFolder)
// check if the output folder exists
if !CheckIfDir(c.OutputFolder) {
ToBeCreated(c.OutputFolder)
}
}
// further stuctures and functions
// ================================
type File2Parse struct {
FileName string
}