summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxegineering <me@xegineering.eu>2024-10-02 18:46:50 +0200
committerxegineering <me@xegineering.eu>2024-10-02 18:47:34 +0200
commit516fa4b31da2f2a004e1c7f309c1e34803d18555 (patch)
tree3f9874e4abd596e6596a62a097ea4e5d10f060fd
parentda21e83c58b3bbc389d8919e9ca5e865e45f2751 (diff)
downloadsoundbox-go-516fa4b31da2f2a004e1c7f309c1e34803d18555.tar
soundbox-go-516fa4b31da2f2a004e1c7f309c1e34803d18555.tar.zst
soundbox-go-516fa4b31da2f2a004e1c7f309c1e34803d18555.zip
Add soundbox.fromHardwareAddr()
This splits the soundbox.NewSoundbox() function into two smaller functions.
-rw-r--r--soundbox.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/soundbox.go b/soundbox.go
index 389d1da..d6a0a34 100644
--- a/soundbox.go
+++ b/soundbox.go
@@ -18,12 +18,14 @@ func NewSoundbox(mac string) (Soundbox, error) {
if err != nil {
return Soundbox{}, err
}
-
- if len(hardwareAddr) != 6 {
+
+ return fromHardwareAddr(hardwareAddr)
+}
+
+func fromHardwareAddr(addr net.HardwareAddr) (Soundbox, error) {
+ if len(addr) != 6 {
return Soundbox{}, fmt.Errorf("Only IEEE 802 MAC-48 addresses supported")
}
- return Soundbox{
- HardwareAddr: hardwareAddr,
- }, nil
+ return Soundbox{HardwareAddr: addr}, nil
}