summaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'config.go')
-rw-r--r--config.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/config.go b/config.go
new file mode 100644
index 0000000..5bdd48c
--- /dev/null
+++ b/config.go
@@ -0,0 +1,47 @@
+package main
+
+import (
+ "encoding/json"
+ "io"
+ "os"
+ "path/filepath"
+)
+
+const configPathRelative = `.config/soundbox/config.json`
+
+type SoundboxConfig struct {
+ Name string `json:"name"`
+ Mac string `json:"mac"`
+}
+
+type GlobalConfig struct {
+ Soundboxes []SoundboxConfig `json:"soundboxes"`
+}
+
+func loadConfig() (GlobalConfig, error) {
+ home, err := os.UserHomeDir()
+ if err != nil {
+ return GlobalConfig{}, err
+ }
+
+ path := filepath.Join(home, configPathRelative)
+
+ file, err := os.Open(path)
+ if err != nil {
+ return GlobalConfig{}, err
+ }
+ defer file.Close()
+
+ bytes, err := io.ReadAll(file)
+ if err != nil {
+ return GlobalConfig{}, err
+ }
+
+ var config GlobalConfig
+ err = json.Unmarshal(bytes, &config)
+ if err != nil {
+ return GlobalConfig{}, err
+ }
+
+ return config, nil
+}