mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-26 12:55:29 +00:00
make method to get data out of a module
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user