mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-26 21:05:30 +00:00
make an OutputModule interface and remove output from modules that don't implement it
This commit is contained in:
@@ -10,6 +10,9 @@ type Module interface {
|
|||||||
Type() string
|
Type() string
|
||||||
Start(context.Context) error
|
Start(context.Context) error
|
||||||
Stop()
|
Stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
type OutputModule interface {
|
||||||
Output(context.Context, any) error
|
Output(context.Context, any) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,10 +82,6 @@ func (mi *MIDIInput) Start(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mi *MIDIInput) Output(ctx context.Context, payload any) error {
|
|
||||||
return errors.New("midi.input output is not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mi *MIDIInput) Stop() {
|
func (mi *MIDIInput) Stop() {
|
||||||
mi.cancel()
|
mi.cancel()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,10 +102,6 @@ func (ns *NATSServer) Start(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ns *NATSServer) Output(ctx context.Context, payload any) error {
|
|
||||||
return errors.New("nats.server does not support output")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ns *NATSServer) Stop() {
|
func (ns *NATSServer) Stop() {
|
||||||
ns.cancel()
|
ns.cancel()
|
||||||
if ns.server != nil {
|
if ns.server != nil {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package module
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
@@ -105,10 +104,6 @@ func (pc *PSNClient) Start(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *PSNClient) Output(ctx context.Context, payload any) error {
|
|
||||||
return fmt.Errorf("psn.client output is not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pc *PSNClient) Stop() {
|
func (pc *PSNClient) Stop() {
|
||||||
pc.cancel()
|
pc.cancel()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,10 +12,6 @@ import (
|
|||||||
type TestModule struct {
|
type TestModule struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *TestModule) Output(ctx context.Context, payload any) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *TestModule) Start(ctx context.Context) error {
|
func (m *TestModule) Start(ctx context.Context) error {
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -74,11 +74,6 @@ func (i *TimeInterval) Start(ctx context.Context) error {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *TimeInterval) Output(ctx context.Context, payload any) error {
|
|
||||||
i.ticker.Reset(time.Millisecond * time.Duration(i.Duration))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *TimeInterval) Stop() {
|
func (i *TimeInterval) Stop() {
|
||||||
i.cancel()
|
i.cancel()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,11 +73,6 @@ func (t *TimeTimer) Start(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TimeTimer) Output(ctx context.Context, payload any) error {
|
|
||||||
t.timer.Reset(time.Millisecond * time.Duration(t.Duration))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *TimeTimer) Stop() {
|
func (t *TimeTimer) Stop() {
|
||||||
t.cancel()
|
t.cancel()
|
||||||
}
|
}
|
||||||
|
|||||||
13
router.go
13
router.go
@@ -269,9 +269,20 @@ func (r *Router) HandleOutput(ctx context.Context, destinationId string, payload
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
outputModule, ok := destinationModule.(common.OutputModule)
|
||||||
|
if !ok {
|
||||||
|
err := errors.New("module does not support output")
|
||||||
|
span.SetStatus(codes.Error, err.Error())
|
||||||
|
span.RecordError(err)
|
||||||
|
r.logger.Error("module does not support output", "destinationId", destinationId)
|
||||||
|
outputEvent.Error = err.Error()
|
||||||
|
r.broadcastEvent(outputEvent)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
moduleOutputCtx, moduleOutputSpan := otel.Tracer("module").Start(spanCtx, "output", trace.WithAttributes(attribute.String("module.id", destinationModule.Id()), attribute.String("module.type", destinationModule.Type())))
|
moduleOutputCtx, moduleOutputSpan := otel.Tracer("module").Start(spanCtx, "output", trace.WithAttributes(attribute.String("module.id", destinationModule.Id()), attribute.String("module.type", destinationModule.Type())))
|
||||||
defer moduleOutputSpan.End()
|
defer moduleOutputSpan.End()
|
||||||
err := destinationModule.Output(moduleOutputCtx, payload)
|
err := outputModule.Output(moduleOutputCtx, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
moduleOutputSpan.SetStatus(codes.Error, err.Error())
|
moduleOutputSpan.SetStatus(codes.Error, err.Error())
|
||||||
moduleOutputSpan.RecordError(err)
|
moduleOutputSpan.RecordError(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user