diff options
author | xengineering <me@xengineering.eu> | 2024-10-07 21:53:38 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-10-07 21:55:50 +0200 |
commit | b03cf32bef7e34c4886a3b7300ffc0132b310a5b (patch) | |
tree | 33191d1c5bccb324d6b3e5b37f15296bbffb4031 /config.go | |
parent | 293965c55615bb072843500cc3af44c0e266dfcd (diff) | |
download | soundbox-app-b03cf32bef7e34c4886a3b7300ffc0132b310a5b.tar soundbox-app-b03cf32bef7e34c4886a3b7300ffc0132b310a5b.tar.zst soundbox-app-b03cf32bef7e34c4886a3b7300ffc0132b310a5b.zip |
Parse config at startup
Diffstat (limited to 'config.go')
-rw-r--r-- | config.go | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -3,15 +3,34 @@ package main import ( "encoding/json" "io" + "net" "os" "path/filepath" ) const configPathRelative = `.config/soundbox/config.json` +type MacAddress net.HardwareAddr + +func (m *MacAddress) UnmarshalJSON(data []byte) error { + var macStr string + err := json.Unmarshal(data, &macStr) + if err != nil { + return err + } + + hwAddr, err := net.ParseMAC(macStr) + if err != nil { + return err + } + + *m = MacAddress(hwAddr) + return nil +} + type SoundboxConfig struct { - Name string `json:"name"` - Mac string `json:"mac"` + Name string `json:"name"` + Mac MacAddress `json:"mac"` } type URLConfig struct { |