From 07741b358ba75350e7be36ee76f45afa18b0461b Mon Sep 17 00:00:00 2001 From: xegineering Date: Wed, 2 Oct 2024 21:18:51 +0200 Subject: Rename Soundbox to Client Since the module name is `soundbox` naming the primary type of the module also `Soundbox` is redundant. Following similar code from the Go standard library this struct is renamed to `Client`. --- client.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 client.go (limited to 'client.go') diff --git a/client.go b/client.go new file mode 100644 index 0000000..27e5d54 --- /dev/null +++ b/client.go @@ -0,0 +1,31 @@ +package soundbox + +import ( + "fmt" + "net" +) + +// Port is the default network port a soundbox is listening to for incoming +// audio stream data. +const Port = 5316 + +type Client struct { + HardwareAddr net.HardwareAddr +} + +func NewClient(mac string) (Client, error) { + hardwareAddr, err := net.ParseMAC(mac) + if err != nil { + return Client{}, err + } + + return fromHardwareAddr(hardwareAddr) +} + +func fromHardwareAddr(addr net.HardwareAddr) (Client, error) { + if len(addr) != 6 { + return Client{}, fmt.Errorf("Only IEEE 802 MAC-48 addresses supported") + } + + return Client{HardwareAddr: addr}, nil +} -- cgit v1.2.3-70-g09d2