-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
48 lines (39 loc) · 784 Bytes
/
config.go
File metadata and controls
48 lines (39 loc) · 784 Bytes
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
package main
import (
"encoding/json"
"os"
)
type Config struct {
Host string `json:"host"`
Port uint16 `json:"port"`
User string `json:"username"`
Pass string `json:"password"`
From string `json:"from"`
To []string `json:"to"`
Subject string `json:"subject"`
}
var (
defaultFile = "smtp-cli.json"
defaultConfig = &Config{
Port: 465,
Subject: "Neue Anmeldung auf dem Server",
}
)
func LoadConfig(file *string) (*Config, error) {
var (
fileToOpen = file
result = defaultConfig
)
if fileToOpen == nil {
fileToOpen = &defaultFile
}
contents, err := os.ReadFile(*fileToOpen)
if err != nil {
return nil, err
}
err = json.Unmarshal(contents, result)
if err != nil {
return nil, err
}
return result, nil
}