-
Notifications
You must be signed in to change notification settings - Fork 0
/
conf.go
38 lines (32 loc) · 785 Bytes
/
conf.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
package informant
import (
"fmt"
"os"
"gopkg.in/yaml.v3"
)
type conf struct {
Bind string `yaml:"bind"`
Homeserver string `yaml:"homeserver"`
Username string `yaml:"username"`
Password string `yaml:"password"`
Display string `yaml:"display"`
Avatar string `yaml:"avatar"`
Database struct {
Path string `yaml:"path"`
Key string `yaml:"key"`
} `yaml:"database"`
Debug bool `yaml:"debug"`
PSK string `yaml:"psk"`
}
func ReadConfig(path string) (*conf, error) {
buf, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("error: failed to read yaml config: %w", err)
}
c := conf{}
err = yaml.Unmarshal(buf, &c)
if err != nil {
return nil, fmt.Errorf("error: failed to unmarshal yaml config: %w", err)
}
return &c, nil
}