diff options
Diffstat (limited to 'config')
-rw-r--r-- | config/client.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/config/client.go b/config/client.go new file mode 100644 index 0000000..a2d1500 --- /dev/null +++ b/config/client.go @@ -0,0 +1,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 +} |