blob: a2d1500d70ea30b62c6a353f10ac6f171e49497e (
plain)
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
|
package config
import (
"fmt"
"github.com/pelletier/go-toml/v2"
"os"
)
type Server struct {
Listen string `toml:"listen"`
HandshakeTimeout int `toml:"handshake_timeout"`
Token string `toml:"token"`
Targets []Target `toml:"targets"`
}
type Client struct {
ObserverID string `toml:"observer_id"`
ReportServer string `toml:"report_server"`
CheckInterval int `toml:"check_interval"`
SendBuffer int `toml:"send_buffer"`
ReconnectInterval int `toml:"reconnect_interval"`
ReportConnectTimeout int `toml:"report_connect_timeout"`
Token string `toml:"token"`
}
type Target struct {
Host string `toml:"host"`
Port int `toml:"port"`
}
func Read[T any](path string) (ret *T, err error) {
f, err := os.Open(path)
if err != nil {
return nil, fmt.Errorf("open: %w", err)
}
defer func() {
_ = f.Close()
}()
dec := toml.NewDecoder(f)
ret = new(T)
err = dec.Decode(ret)
return ret, err
}
|