aboutsummaryrefslogtreecommitdiff
path: root/internal/config
diff options
context:
space:
mode:
Diffstat (limited to 'internal/config')
-rw-r--r--internal/config/config.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
new file mode 100644
index 0000000..94ff011
--- /dev/null
+++ b/internal/config/config.go
@@ -0,0 +1,46 @@
+package config
+
+import (
+ "encoding/json"
+ "os"
+)
+
+type Config struct {
+ Server Server `json:"server"`
+ Channels []Channel `json:"channels"`
+}
+
+type Server struct {
+ PrivateKey string `json:"private_key"`
+ Addr string `json:"addr"`
+ Name string `json:"name"`
+}
+
+type Channel struct {
+ Name string `json:"name"`
+}
+
+func Load(file string) (*Config, error) {
+ fp, err := os.Open(file)
+ if err != nil {
+ return nil, err
+ }
+ defer fp.Close()
+
+ cfg := new(Config)
+
+ return cfg, json.NewDecoder(fp).Decode(cfg)
+}
+
+func Save(file string, cfg *Config) error {
+ fp, err := os.Create(file)
+ if err != nil {
+ return err
+ }
+
+ enc := json.NewEncoder(fp)
+ enc.SetIndent("", " ")
+ enc.SetEscapeHTML(false)
+
+ return enc.Encode(cfg)
+}