From 6a21cc263964f80050fc4aab3c7a3ac2525c6c1b Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Wed, 4 Mar 2026 12:35:15 -0600 Subject: [PATCH] make method to get data out of a module --- internal/module/http-client.go | 4 ++++ internal/module/http-server.go | 4 ++++ internal/module/midi-input.go | 9 +++++++++ internal/module/midi-output.go | 9 +++++++++ internal/module/module.go | 1 + internal/module/mqtt-client.go | 4 ++++ internal/module/nats-client.go | 4 ++++ internal/module/nats-server.go | 4 ++++ internal/module/psn-client.go | 11 +++++++++++ internal/module/serial-client.go | 9 +++++++++ internal/module/sip-call-server.go | 4 ++++ internal/module/sip-dtmf-server.go | 4 ++++ internal/module/tcp-client.go | 17 +++++++++++++++++ internal/module/tcp-server.go | 11 +++++++++++ internal/module/test/module_test.go | 4 ++++ internal/module/time-interval.go | 9 +++++++++ internal/module/time-timer.go | 9 +++++++++ internal/module/udp-client.go | 17 +++++++++++++++++ internal/module/udp-multicast.go | 11 +++++++++++ internal/module/udp-server.go | 11 +++++++++++ router_test.go | 7 +++++++ 21 files changed, 163 insertions(+) diff --git a/internal/module/http-client.go b/internal/module/http-client.go index 39f696c..7e44a80 100644 --- a/internal/module/http-client.go +++ b/internal/module/http-client.go @@ -89,3 +89,7 @@ func (hc *HTTPClient) Output(ctx context.Context, payload any) error { func (hc *HTTPClient) Stop() { hc.cancel() } + +func (hc *HTTPClient) Get(key string) (any, error) { + return nil, errors.New("http.client does not support Get") +} diff --git a/internal/module/http-server.go b/internal/module/http-server.go index e436d52..5b9c13a 100644 --- a/internal/module/http-server.go +++ b/internal/module/http-server.go @@ -201,3 +201,7 @@ func (hs *HTTPServer) Output(ctx context.Context, payload any) error { func (hs *HTTPServer) Stop() { hs.cancel() } + +func (hs *HTTPServer) Get(key string) (any, error) { + return nil, errors.New("http.server does not support Get") +} diff --git a/internal/module/midi-input.go b/internal/module/midi-input.go index a34ee68..8ee314b 100644 --- a/internal/module/midi-input.go +++ b/internal/module/midi-input.go @@ -90,3 +90,12 @@ func (mi *MIDIInput) Output(ctx context.Context, payload any) error { func (mi *MIDIInput) Stop() { mi.cancel() } + +func (mi *MIDIInput) Get(key string) (any, error) { + switch key { + case "port": + return mi.Port, nil + default: + return nil, errors.New("midi.input key not found") + } +} diff --git a/internal/module/midi-output.go b/internal/module/midi-output.go index 958ed47..caf07d5 100644 --- a/internal/module/midi-output.go +++ b/internal/module/midi-output.go @@ -98,3 +98,12 @@ func (mo *MIDIOutput) Output(ctx context.Context, payload any) error { func (mo *MIDIOutput) Stop() { mo.cancel() } + +func (mo *MIDIOutput) Get(key string) (any, error) { + switch key { + case "port": + return mo.Port, nil + default: + return nil, errors.New("midi.output key not found") + } +} diff --git a/internal/module/module.go b/internal/module/module.go index a2a2709..4a82f59 100644 --- a/internal/module/module.go +++ b/internal/module/module.go @@ -21,6 +21,7 @@ type Module interface { Start(context.Context) error Stop() Output(context.Context, any) error + Get(key string) (any, error) } type ModuleRegistration struct { diff --git a/internal/module/mqtt-client.go b/internal/module/mqtt-client.go index 223b3ce..ad0e9bf 100644 --- a/internal/module/mqtt-client.go +++ b/internal/module/mqtt-client.go @@ -127,3 +127,7 @@ func (mc *MQTTClient) Output(ctx context.Context, payload any) error { func (mc *MQTTClient) Stop() { mc.cancel() } + +func (mc *MQTTClient) Get(key string) (any, error) { + return nil, errors.New("mqtt.client does not support Get") +} diff --git a/internal/module/nats-client.go b/internal/module/nats-client.go index fde35b1..5316caa 100644 --- a/internal/module/nats-client.go +++ b/internal/module/nats-client.go @@ -117,3 +117,7 @@ func (nc *NATSClient) Output(ctx context.Context, payload any) error { func (nc *NATSClient) Stop() { nc.cancel() } + +func (nc *NATSClient) Get(key string) (any, error) { + return nil, errors.New("nats.client does not support Get") +} diff --git a/internal/module/nats-server.go b/internal/module/nats-server.go index 4f45bbf..9fb3376 100644 --- a/internal/module/nats-server.go +++ b/internal/module/nats-server.go @@ -113,3 +113,7 @@ func (ns *NATSServer) Stop() { ns.server.Shutdown() } } + +func (ns *NATSServer) Get(key string) (any, error) { + return nil, errors.New("nats.server does not support Get") +} diff --git a/internal/module/psn-client.go b/internal/module/psn-client.go index 4cca068..b3fc9ca 100644 --- a/internal/module/psn-client.go +++ b/internal/module/psn-client.go @@ -113,3 +113,14 @@ func (pc *PSNClient) Output(ctx context.Context, payload any) error { func (pc *PSNClient) Stop() { pc.cancel() } + +func (pc *PSNClient) Get(key string) (any, error) { + switch key { + case "trackers": + return pc.decoder.Trackers, nil + case "name": + return pc.decoder.SystemName, nil + default: + return nil, errors.New("psn.client key not found") + } +} diff --git a/internal/module/serial-client.go b/internal/module/serial-client.go index 8c757d0..fd139cb 100644 --- a/internal/module/serial-client.go +++ b/internal/module/serial-client.go @@ -171,3 +171,12 @@ func (sc *SerialClient) Output(ctx context.Context, payload any) error { func (sc *SerialClient) Stop() { sc.cancel() } + +func (sc *SerialClient) Get(key string) (any, error) { + switch key { + case "port": + return sc.Port, nil + default: + return nil, errors.New("serial.client key not found") + } +} diff --git a/internal/module/sip-call-server.go b/internal/module/sip-call-server.go index ac555aa..249858d 100644 --- a/internal/module/sip-call-server.go +++ b/internal/module/sip-call-server.go @@ -222,3 +222,7 @@ func (scs *SIPCallServer) Output(ctx context.Context, payload any) error { func (scs *SIPCallServer) Stop() { scs.cancel() } + +func (scs *SIPCallServer) Get(key string) (any, error) { + return nil, errors.New("sip.call.server does not support Get") +} diff --git a/internal/module/sip-dtmf-server.go b/internal/module/sip-dtmf-server.go index 69ed547..b92cc9a 100644 --- a/internal/module/sip-dtmf-server.go +++ b/internal/module/sip-dtmf-server.go @@ -250,3 +250,7 @@ func (sds *SIPDTMFServer) Output(ctx context.Context, payload any) error { func (sds *SIPDTMFServer) Stop() { sds.cancel() } + +func (sds *SIPDTMFServer) Get(key string) (any, error) { + return nil, errors.New("sip.dtmf.server does not support Get") +} diff --git a/internal/module/tcp-client.go b/internal/module/tcp-client.go index e6cba7b..11c3622 100644 --- a/internal/module/tcp-client.go +++ b/internal/module/tcp-client.go @@ -165,3 +165,20 @@ func (tc *TCPClient) Output(ctx context.Context, payload any) error { func (tc *TCPClient) Stop() { tc.cancel() } + +func (tc *TCPClient) Get(key string) (any, error) { + switch key { + case "host": + host, err := tc.config.Params.GetString("host") + if err != nil { + return nil, fmt.Errorf("net.tcp.client host error: %w", err) + } + return host, nil + case "ip": + return tc.Addr.IP.String(), nil + case "port": + return tc.Addr.Port, nil + default: + return nil, errors.New("net.tcp.client key not found") + } +} diff --git a/internal/module/tcp-server.go b/internal/module/tcp-server.go index 4358438..757c0b2 100644 --- a/internal/module/tcp-server.go +++ b/internal/module/tcp-server.go @@ -228,3 +228,14 @@ func (ts *TCPServer) Stop() { ts.cancel() ts.wg.Wait() } + +func (ts *TCPServer) Get(key string) (any, error) { + switch key { + case "ip": + return ts.Addr.IP.String(), nil + case "port": + return ts.Addr.Port, nil + default: + return nil, errors.New("net.tcp.server key not found") + } +} diff --git a/internal/module/test/module_test.go b/internal/module/test/module_test.go index 3889399..de1b70e 100644 --- a/internal/module/test/module_test.go +++ b/internal/module/test/module_test.go @@ -30,6 +30,10 @@ func (m *TestModule) Id() string { return "test" } +func (m *TestModule) Get(key string) (any, error) { + return nil, nil +} + func TestModuleBadRegistrationNoType(t *testing.T) { defer func() { if r := recover(); r == nil { diff --git a/internal/module/time-interval.go b/internal/module/time-interval.go index 78065d0..40684a1 100644 --- a/internal/module/time-interval.go +++ b/internal/module/time-interval.go @@ -83,3 +83,12 @@ func (i *TimeInterval) Output(ctx context.Context, payload any) error { func (i *TimeInterval) Stop() { i.cancel() } + +func (i *TimeInterval) Get(key string) (any, error) { + switch key { + case "duration": + return i.Duration, nil + default: + return nil, errors.New("time.interval key not found") + } +} diff --git a/internal/module/time-timer.go b/internal/module/time-timer.go index 1c00a76..51a839b 100644 --- a/internal/module/time-timer.go +++ b/internal/module/time-timer.go @@ -82,3 +82,12 @@ func (t *TimeTimer) Output(ctx context.Context, payload any) error { func (t *TimeTimer) Stop() { t.cancel() } + +func (t *TimeTimer) Get(key string) (any, error) { + switch key { + case "duration": + return t.Duration, nil + default: + return nil, errors.New("time.timer key not found") + } +} diff --git a/internal/module/udp-client.go b/internal/module/udp-client.go index 74edaeb..06f718f 100644 --- a/internal/module/udp-client.go +++ b/internal/module/udp-client.go @@ -108,3 +108,20 @@ func (uc *UDPClient) Output(ctx context.Context, payload any) error { func (uc *UDPClient) Stop() { uc.cancel() } + +func (uc *UDPClient) Get(key string) (any, error) { + switch key { + case "host": + host, err := uc.config.Params.GetString("host") + if err != nil { + return nil, fmt.Errorf("net.udp.client host error: %w", err) + } + return host, nil + case "ip": + return uc.Addr.IP.String(), nil + case "port": + return uc.Addr.Port, nil + default: + return nil, errors.New("net.udp.client key not found") + } +} diff --git a/internal/module/udp-multicast.go b/internal/module/udp-multicast.go index e311f8e..9684feb 100644 --- a/internal/module/udp-multicast.go +++ b/internal/module/udp-multicast.go @@ -126,3 +126,14 @@ func (um *UDPMulticast) Output(ctx context.Context, payload any) error { func (um *UDPMulticast) Stop() { um.cancel() } + +func (um *UDPMulticast) Get(key string) (any, error) { + switch key { + case "ip": + return um.Addr.IP.String(), nil + case "port": + return um.Addr.Port, nil + default: + return nil, errors.New("net.udp.multicast key not found") + } +} diff --git a/internal/module/udp-server.go b/internal/module/udp-server.go index d8ad7d0..3aae487 100644 --- a/internal/module/udp-server.go +++ b/internal/module/udp-server.go @@ -123,3 +123,14 @@ func (us *UDPServer) Output(ctx context.Context, payload any) error { func (us *UDPServer) Stop() { us.cancel() } + +func (us *UDPServer) Get(key string) (any, error) { + switch key { + case "ip": + return us.Addr.IP.String(), nil + case "port": + return us.Addr.Port, nil + default: + return nil, errors.New("net.udp.server key not found") + } +} diff --git a/router_test.go b/router_test.go index 981d0ad..81f52fb 100644 --- a/router_test.go +++ b/router_test.go @@ -47,6 +47,13 @@ func (mcm *MockCounterModule) Start(ctx context.Context) error { return nil } +func (mcm *MockCounterModule) Get(key string) (any, error) { + if key == "count" { + return mcm.outputCount, nil + } + return nil, fmt.Errorf("mock.counter key not found") +} + func (mcm *MockCounterModule) Type() string { return mcm.config.Type }