From b03cf32bef7e34c4886a3b7300ffc0132b310a5b Mon Sep 17 00:00:00 2001 From: xengineering Date: Mon, 7 Oct 2024 21:53:38 +0200 Subject: Parse config at startup --- config.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'config.go') diff --git a/config.go b/config.go index a4f2805..e187827 100644 --- a/config.go +++ b/config.go @@ -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 { -- cgit v1.2.3-70-g09d2