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
|
package config
import (
"encoding/json"
"os"
"time"
)
type ConfigStruct struct {
SSL bool `json:"ssl"`
Debug bool `json:"debug"`
ExcludedPaths []string `json:"excludedPaths"`
Port string `json:"port"`
SSLPort string `json:"sslPort"`
SSLDomain string `json:"sslDomain"`
SSLCertDays int `json:"sslCertDays"`
SSLMail string `json:"sslMail"`
Cors bool `json:"cors"`
RateLimiter bool `json:"rateLimiter"`
Bann bool `json:"bann"`
Metrics bool `json:"metric"`
Prefix string `json:"prefix"`
PemCrt string `json:"pemCrt"`
PemKey string `json:"pemKey"`
SystemWhitelist []string `json:"systemWhitelist"`
SystemWhitelistDNS []string `json:"systemWhitelistDNS"`
Bannlist []string `json:"bannlist"`
Rate Rates `json:"rate"`
RateWhitelist []string `json:"rateWhitelist"`
CorsAllowOrigins []string `json:"corsAllowOrigins"`
CorsAllowMethods []string `json:"corsAllowMethods"`
CorsAllowHeaders []string `json:"corsAllowHeaders"`
CorsAdvanced bool `json:"corsAdvanced"`
ExportLog bool `json:"exportLog"`
ExportLogPath string `json:"exportLogPath"`
Hostnamecheck bool `json:"hostnamecheck"`
Hostname string `json:"hostname"`
Name string `json:"name"`
DNSResolver string `json:"dnsResolver"`
}
type Rates struct {
Rate int `json:"rate"`
Window time.Duration `json:"window"`
}
// LoadConfig lädt die Konfiguration aus einer JSON-Datei.
func LoadConfig(path string) (*ConfigStruct, error) {
var config ConfigStruct
data, err := os.ReadFile(path)
if err != nil {
return nil, err
}
err = json.Unmarshal(data, &config)
if err != nil {
return nil, err
}
return &config, nil
}
//chek if the config exists, else create a new one
func MarshalConfig(config ConfigStruct) ([]byte, error) {
return json.MarshalIndent(config, "", " ")
}
|