-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconfig.go
49 lines (43 loc) · 1.15 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
package main
import (
"bytes"
"encoding/json"
"fmt"
"os"
)
type configuration struct {
Mailserver string `json:"mailserver"`
Mailport int `json:"mailport"`
MailUsername string `json:"mailusername"`
MailPassword string `json:"mailpassword"`
MailSkipTLS bool `json:"mailskiptls"`
Mailfrom string `json:"mailfrom"`
Mailonerror bool `json:"mailonerror"`
Mailtoerror string `json:"mailtoerror"`
Mailto string `json:"mailto"`
Mailsubject string `json:"mailsubject"`
Timeout string `json:"timeout"`
Keywords []keyword `json:"keywords"`
CIDRs []string `json:"cidrs"`
}
type keyword struct {
Keyword string `json:"keyword"`
Exceptions []string `json:"exceptions"`
}
func getConfig(f string) (*configuration, error) {
if f == "" {
return nil, fmt.Errorf("please provide a valid config file")
}
b, err := os.ReadFile(f) // nolint: gosec
if err != nil {
return nil, err
}
reader := bytes.NewReader(b)
decoder := json.NewDecoder(reader)
decoder.DisallowUnknownFields()
c := configuration{}
if err = decoder.Decode(&c); err != nil {
return nil, err
}
return &c, nil
}