summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorKeuin <[email protected]>2024-03-09 20:19:35 +0800
committerKeuin <[email protected]>2024-03-09 20:20:20 +0800
commitb933083d20b3db4a3d6a8134efe312eb6ff3d8e2 (patch)
tree2a86151c77b1eed1596b5f50ce824659e3c1fc22 /config
initial versionHEADmaster
Diffstat (limited to 'config')
-rw-r--r--config/client.go43
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
+}