errors from newPacket() now propogated

Send() and Close() methods now use pointer receivers.
This commit is contained in:
onyx-and-iris 2026-02-14 20:42:33 +00:00
parent 0d0dbedbcd
commit c6d03e87d7

View File

@ -8,7 +8,7 @@ import (
// VbanTxt is used to send VBAN-TXT requests to a distant Voicemeeter/Matrix. // VbanTxt is used to send VBAN-TXT requests to a distant Voicemeeter/Matrix.
type VbanTxt struct { type VbanTxt struct {
udpConn io.WriteCloser conn io.WriteCloser
packet packet packet packet
ratelimit time.Duration ratelimit time.Duration
} }
@ -16,14 +16,19 @@ type VbanTxt struct {
// New constructs a fully formed VbanTxt instance. This is the package's entry point. // New constructs a fully formed VbanTxt instance. This is the package's entry point.
// It sets default values for it's fields and then runs the option functions. // It sets default values for it's fields and then runs the option functions.
func New(host string, port int, streamname string, options ...Option) (*VbanTxt, error) { func New(host string, port int, streamname string, options ...Option) (*VbanTxt, error) {
udpConn, err := newUDPConn(host, port) conn, err := newUDPConn(host, port)
if err != nil { if err != nil {
return nil, fmt.Errorf("error creating UDP client for (%s:%d): %w", host, port, err) return nil, fmt.Errorf("error creating UDP client for (%s:%d): %w", host, port, err)
} }
packet, err := newPacket(streamname)
if err != nil {
return nil, fmt.Errorf("error creating packet: %w", err)
}
vt := &VbanTxt{ vt := &VbanTxt{
udpConn: udpConn, conn: conn,
packet: newPacket(streamname), packet: packet,
ratelimit: time.Duration(20) * time.Millisecond, ratelimit: time.Duration(20) * time.Millisecond,
} }
@ -34,10 +39,10 @@ func New(host string, port int, streamname string, options ...Option) (*VbanTxt,
return vt, nil return vt, nil
} }
// Send is resonsible for firing each VBAN-TXT request. // Send is responsible for firing each VBAN-TXT request.
// It waits for {vt.ratelimit} time before returning. // It waits for {vt.ratelimit} time before returning.
func (vt VbanTxt) Send(cmd string) error { func (vt *VbanTxt) Send(cmd string) error {
_, err := vt.udpConn.Write(append(vt.packet.header(), []byte(cmd)...)) _, err := vt.conn.Write(append(vt.packet.header(), cmd...))
if err != nil { if err != nil {
return fmt.Errorf("error sending command (%s): %w", cmd, err) return fmt.Errorf("error sending command (%s): %w", cmd, err)
} }
@ -50,8 +55,8 @@ func (vt VbanTxt) Send(cmd string) error {
} }
// Close is responsible for closing the UDP Client connection. // Close is responsible for closing the UDP Client connection.
func (vt VbanTxt) Close() error { func (vt *VbanTxt) Close() error {
err := vt.udpConn.Close() err := vt.conn.Close()
if err != nil { if err != nil {
return fmt.Errorf("error attempting to close UDP Client: %w", err) return fmt.Errorf("error attempting to close UDP Client: %w", err)
} }