diff --git a/internal/module/http-client.go b/internal/module/http-client.go index 805bc25..4e006f4 100644 --- a/internal/module/http-client.go +++ b/internal/module/http-client.go @@ -20,7 +20,7 @@ type HTTPClient struct { func init() { RegisterModule(ModuleRegistration{ - Type: "net.http.client", + Type: "http.client", New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) { return &HTTPClient{config: config, ctx: ctx, router: router}, nil @@ -52,11 +52,11 @@ func (hc *HTTPClient) Output(payload any) error { payloadRequest, ok := payload.(*http.Request) if !ok { - return fmt.Errorf("net.http.client is only able to output an http.Request") + return fmt.Errorf("http.client is only able to output an http.Request") } if hc.client == nil { - return fmt.Errorf("net.http.client client is nil") + return fmt.Errorf("http.client client is nil") } response, err := hc.client.Do(payloadRequest) diff --git a/internal/module/http-server.go b/internal/module/http-server.go index c72f2da..7906d74 100644 --- a/internal/module/http-server.go +++ b/internal/module/http-server.go @@ -25,18 +25,18 @@ type ResponseData struct { func init() { RegisterModule(ModuleRegistration{ - Type: "net.http.server", + Type: "http.server", New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) { params := config.Params port, ok := params["port"] if !ok { - return nil, fmt.Errorf("net.http.server requires a port parameter") + return nil, fmt.Errorf("http.server requires a port parameter") } portNum, ok := port.(float64) if !ok { - return nil, fmt.Errorf("net.http.server port must be uint16") + return nil, fmt.Errorf("http.server port must be uint16") } return &HTTPServer{Port: uint16(portNum), config: config, ctx: ctx, router: router}, nil @@ -94,7 +94,7 @@ func (hs *HTTPServer) Run() error { }() err := httpServer.ListenAndServe() - slog.Debug("net.http.server closed", "id", hs.Id()) + slog.Debug("http.server closed", "id", hs.Id()) // TODO(jwetzell): handle server closed error differently if err != nil { return err @@ -105,5 +105,5 @@ func (hs *HTTPServer) Run() error { } func (hs *HTTPServer) Output(payload any) error { - return fmt.Errorf("net.http.server output is not implemented") + return fmt.Errorf("http.server output is not implemented") } diff --git a/internal/module/midi-client.go b/internal/module/midi-client.go index 1012b32..8a49d0c 100644 --- a/internal/module/midi-client.go +++ b/internal/module/midi-client.go @@ -25,31 +25,31 @@ type MIDIClient struct { func init() { RegisterModule(ModuleRegistration{ //TODO(jwetzell): find a better namespace than "misc" - Type: "misc.midi.client", + Type: "midi.client", New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) { params := config.Params input, ok := params["input"] if !ok { - return nil, fmt.Errorf("misc.midi.client requires a input parameter") + return nil, fmt.Errorf("midi.client requires a input parameter") } inputString, ok := input.(string) if !ok { - return nil, fmt.Errorf("misc.midi.client input must be a string") + return nil, fmt.Errorf("midi.client input must be a string") } output, ok := params["output"] if !ok { - return nil, fmt.Errorf("misc.midi.client requires a output parameter") + return nil, fmt.Errorf("midi.client requires a output parameter") } outputString, ok := output.(string) if !ok { - return nil, fmt.Errorf("misc.midi.client output must be a string") + return nil, fmt.Errorf("midi.client output must be a string") } return &MIDIClient{config: config, InputPort: inputString, OutputPort: outputString, ctx: ctx, router: router}, nil @@ -70,7 +70,7 @@ func (mc *MIDIClient) Run() error { in, err := midi.FindInPort(mc.InputPort) if err != nil { - return fmt.Errorf("misc.midi.client can't find input port: %s", mc.InputPort) + return fmt.Errorf("midi.client can't find input port: %s", mc.InputPort) } stop, err := midi.ListenTo(in, func(msg midi.Message, timestampms int32) { @@ -89,7 +89,7 @@ func (mc *MIDIClient) Run() error { out, err := midi.FindOutPort(mc.OutputPort) if err != nil { - return fmt.Errorf("misc.midi.client can't find output port: %s", mc.OutputPort) + return fmt.Errorf("midi.client can't find output port: %s", mc.OutputPort) } send, err := midi.SendTo(out) @@ -106,13 +106,13 @@ func (mc *MIDIClient) Run() error { func (mc *MIDIClient) Output(payload any) error { if mc.SendFunc == nil { - return fmt.Errorf("misc.midi.client output is not setup") + return fmt.Errorf("midi.client output is not setup") } payloadMessage, ok := payload.(midi.Message) if !ok { - return fmt.Errorf("misc.midi.client can only ouptut midi.Message") + return fmt.Errorf("midi.client can only ouptut midi.Message") } return mc.SendFunc(payloadMessage) diff --git a/internal/module/mqtt-client.go b/internal/module/mqtt-client.go index c71cff1..5bb8154 100644 --- a/internal/module/mqtt-client.go +++ b/internal/module/mqtt-client.go @@ -22,43 +22,43 @@ type MQTTClient struct { func init() { RegisterModule(ModuleRegistration{ - Type: "net.mqtt.client", + Type: "mqtt.client", New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) { params := config.Params broker, ok := params["broker"] if !ok { - return nil, fmt.Errorf("net.mqtt.client requires a broker parameter") + return nil, fmt.Errorf("mqtt.client requires a broker parameter") } brokerString, ok := broker.(string) if !ok { - return nil, fmt.Errorf("net.mqtt.client broker must be string") + return nil, fmt.Errorf("mqtt.client broker must be string") } topic, ok := params["topic"] if !ok { - return nil, fmt.Errorf("net.mqtt.client requires a topic parameter") + return nil, fmt.Errorf("mqtt.client requires a topic parameter") } topicString, ok := topic.(string) if !ok { - return nil, fmt.Errorf("net.mqtt.client topic must be string") + return nil, fmt.Errorf("mqtt.client topic must be string") } clientId, ok := params["clientId"] if !ok { - return nil, fmt.Errorf("net.mqtt.client requires a clientId parameter") + return nil, fmt.Errorf("mqtt.client requires a clientId parameter") } clientIdString, ok := clientId.(string) if !ok { - return nil, fmt.Errorf("net.mqtt.client clientId must be string") + return nil, fmt.Errorf("mqtt.client clientId must be string") } return &MQTTClient{config: config, Broker: brokerString, Topic: topicString, ClientID: clientIdString, ctx: ctx, router: router}, nil @@ -109,15 +109,15 @@ func (mc *MQTTClient) Output(payload any) error { fmt.Printf("payload type: %T\n", payload) if !ok { - return fmt.Errorf("net.mqtt.client is only able to output a MQTTMessage") + return fmt.Errorf("mqtt.client is only able to output a MQTTMessage") } if mc.client == nil { - return fmt.Errorf("net.mqtt.client client is not setup") + return fmt.Errorf("mqtt.client client is not setup") } if !mc.client.IsConnected() { - return fmt.Errorf("net.mqtt.client is not connected") + return fmt.Errorf("mqtt.client is not connected") } token := mc.client.Publish(payloadMessage.Topic(), payloadMessage.Qos(), payloadMessage.Retained(), payloadMessage.Payload()) diff --git a/internal/module/nats-client.go b/internal/module/nats-client.go index 9f2e5e4..4390a34 100644 --- a/internal/module/nats-client.go +++ b/internal/module/nats-client.go @@ -22,31 +22,31 @@ type NATSClient struct { func init() { RegisterModule(ModuleRegistration{ - Type: "net.nats.client", + Type: "nats.client", New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) { params := config.Params url, ok := params["url"] if !ok { - return nil, fmt.Errorf("net.nats.client requires a url parameter") + return nil, fmt.Errorf("nats.client requires a url parameter") } urlString, ok := url.(string) if !ok { - return nil, fmt.Errorf("net.nats.client url must be string") + return nil, fmt.Errorf("nats.client url must be string") } subject, ok := params["subject"] if !ok { - return nil, fmt.Errorf("net.nats.client requires a subject parameter") + return nil, fmt.Errorf("nats.client requires a subject parameter") } subjectString, ok := subject.(string) if !ok { - return nil, fmt.Errorf("net.nats.client subject must be string") + return nil, fmt.Errorf("nats.client subject must be string") } return &NATSClient{config: config, URL: urlString, Subject: subjectString, ctx: ctx, router: router}, nil @@ -96,15 +96,15 @@ func (nc *NATSClient) Output(payload any) error { payloadMessage, ok := payload.(processor.NATSMessage) if !ok { - return fmt.Errorf("net.nats.client is only able to output NATSMessage") + return fmt.Errorf("nats.client is only able to output NATSMessage") } if nc.client == nil { - return fmt.Errorf("net.nats.client client is not setup") + return fmt.Errorf("nats.client client is not setup") } if !nc.client.IsConnected() { - return fmt.Errorf("net.nats.client is not connected") + return fmt.Errorf("nats.client is not connected") } err := nc.client.Publish(payloadMessage.Subject, payloadMessage.Payload) diff --git a/internal/module/psn-client.go b/internal/module/psn-client.go index e860894..85d2775 100644 --- a/internal/module/psn-client.go +++ b/internal/module/psn-client.go @@ -22,7 +22,7 @@ type PSNClient struct { func init() { RegisterModule(ModuleRegistration{ - Type: "net.psn.client", + Type: "psn.client", New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) { return &PSNClient{config: config, decoder: psn.NewDecoder(), ctx: ctx, router: router}, nil @@ -76,7 +76,7 @@ func (pc *PSNClient) Run() error { message := buffer[:numBytes] err := pc.decoder.Decode(message) if err != nil { - slog.Error("net.psn.client problem decoding psn traffic", "id", pc.Id(), "error", err) + slog.Error("psn.client problem decoding psn traffic", "id", pc.Id(), "error", err) } if pc.router != nil { @@ -84,7 +84,7 @@ func (pc *PSNClient) Run() error { pc.router.HandleInput(pc.Id(), tracker) } } else { - slog.Error("net.psn.client has no router", "id", pc.Id()) + slog.Error("psn.client has no router", "id", pc.Id()) } } } @@ -92,5 +92,5 @@ func (pc *PSNClient) Run() error { } func (pc *PSNClient) Output(payload any) error { - return fmt.Errorf("net.psn.client output is not implemented") + return fmt.Errorf("psn.client output is not implemented") } diff --git a/internal/module/serial-client.go b/internal/module/serial-client.go index 06aaa21..c08b538 100644 --- a/internal/module/serial-client.go +++ b/internal/module/serial-client.go @@ -27,19 +27,19 @@ type SerialClient struct { func init() { RegisterModule(ModuleRegistration{ //TODO(jwetzell): find a better namespace than "misc" - Type: "misc.serial.client", + Type: "serial.client", New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) { params := config.Params port, ok := params["port"] if !ok { - return nil, fmt.Errorf("misc.serial.client requires a port parameter") + return nil, fmt.Errorf("serial.client requires a port parameter") } portString, ok := port.(string) if !ok { - return nil, fmt.Errorf("misc.serial.client port must be a string") + return nil, fmt.Errorf("serial.client port must be a string") } framingMethod := "RAW" @@ -50,7 +50,7 @@ func init() { framingMethodString, ok := framingMethodRaw.(string) if !ok { - return nil, fmt.Errorf("misc.serial.client framing method must be a string") + return nil, fmt.Errorf("serial.client framing method must be a string") } framingMethod = framingMethodString } @@ -63,12 +63,12 @@ func init() { buadRate, ok := params["baudRate"] if !ok { - return nil, fmt.Errorf("misc.serial.client requires a baudRate parameter") + return nil, fmt.Errorf("serial.client requires a baudRate parameter") } baudRateNum, ok := buadRate.(float64) if !ok { - return nil, fmt.Errorf("misc.serial.client baudRate must be a number") + return nil, fmt.Errorf("serial.client baudRate must be a number") } mode := serial.Mode{ @@ -92,7 +92,7 @@ func (mc *SerialClient) SetupPort() error { port, err := serial.Open(mc.Port, mc.Mode) if err != nil { - return fmt.Errorf("misc.serial.client can't open input port: %s", mc.Port) + return fmt.Errorf("serial.client can't open input port: %s", mc.Port) } mc.port = port @@ -118,7 +118,7 @@ func (mc *SerialClient) Run() error { slog.Debug("router context done in module", "id", mc.Id()) return nil } - slog.Error("misc.serial.client", "id", mc.Id(), "error", err.Error()) + slog.Error("serial.client", "id", mc.Id(), "error", err.Error()) time.Sleep(time.Second * 2) continue } @@ -150,7 +150,7 @@ func (mc *SerialClient) Run() error { if mc.router != nil { mc.router.HandleInput(mc.Id(), message) } else { - slog.Error("misc.serial.client has no router", "id", mc.Id()) + slog.Error("serial.client has no router", "id", mc.Id()) } } } @@ -166,7 +166,7 @@ func (mc *SerialClient) Output(payload any) error { payloadBytes, ok := payload.([]byte) if !ok { - return fmt.Errorf("misc.serial.client can only ouptut bytes") + return fmt.Errorf("serial.client can only ouptut bytes") } _, err := mc.port.Write(mc.Framer.Encode(payloadBytes))