mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-28 05:45:30 +00:00
use errors.New when not formatting
This commit is contained in:
@@ -2,7 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
@@ -42,7 +42,7 @@ func main() {
|
|||||||
Action: func(ctx context.Context, c *cli.Command) error {
|
Action: func(ctx context.Context, c *cli.Command) error {
|
||||||
configPath := c.String("config")
|
configPath := c.String("config")
|
||||||
if configPath == "" {
|
if configPath == "" {
|
||||||
return fmt.Errorf("config value cannot be empty")
|
return errors.New("config value cannot be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
config, err := readConfig(configPath)
|
config, err := readConfig(configPath)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package module
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
@@ -53,11 +53,11 @@ func (hc *HTTPClient) Output(payload any) error {
|
|||||||
payloadRequest, ok := payload.(*http.Request)
|
payloadRequest, ok := payload.(*http.Request)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("http.client is only able to output an http.Request")
|
return errors.New("http.client is only able to output an http.Request")
|
||||||
}
|
}
|
||||||
|
|
||||||
if hc.client == nil {
|
if hc.client == nil {
|
||||||
return fmt.Errorf("http.client client is nil")
|
return errors.New("http.client client is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := hc.client.Do(payloadRequest)
|
response, err := hc.client.Do(payloadRequest)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package module
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -31,13 +32,13 @@ func init() {
|
|||||||
params := config.Params
|
params := config.Params
|
||||||
port, ok := params["port"]
|
port, ok := params["port"]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("http.server requires a port parameter")
|
return nil, errors.New("http.server requires a port parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
portNum, ok := port.(float64)
|
portNum, ok := port.(float64)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("http.server port must be uint16")
|
return nil, errors.New("http.server port must be uint16")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &HTTPServer{Port: uint16(portNum), config: config, ctx: ctx, router: router, logger: slog.Default().With("component", "module", "id", config.Id)}, nil
|
return &HTTPServer{Port: uint16(portNum), config: config, ctx: ctx, router: router, logger: slog.Default().With("component", "module", "id", config.Id)}, nil
|
||||||
@@ -105,5 +106,5 @@ func (hs *HTTPServer) Run() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (hs *HTTPServer) Output(payload any) error {
|
func (hs *HTTPServer) Output(payload any) error {
|
||||||
return fmt.Errorf("http.server output is not implemented")
|
return errors.New("http.server output is not implemented")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package module
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -27,13 +27,13 @@ func init() {
|
|||||||
|
|
||||||
duration, ok := params["duration"]
|
duration, ok := params["duration"]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("gen.interval requires a duration parameter")
|
return nil, errors.New("gen.interval requires a duration parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
durationNum, ok := duration.(float64)
|
durationNum, ok := duration.(float64)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("gen.interval duration must be number")
|
return nil, errors.New("gen.interval duration must be number")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Interval{Duration: uint32(durationNum), config: config, ctx: ctx, router: router, logger: slog.Default().With("component", "module", "id", config.Id)}, nil
|
return &Interval{Duration: uint32(durationNum), config: config, ctx: ctx, router: router, logger: slog.Default().With("component", "module", "id", config.Id)}, nil
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package module
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
@@ -30,13 +31,13 @@ func init() {
|
|||||||
port, ok := params["port"]
|
port, ok := params["port"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.input requires a port parameter")
|
return nil, errors.New("midi.input requires a port parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
portString, ok := port.(string)
|
portString, ok := port.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.input port must be a string")
|
return nil, errors.New("midi.input port must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &MIDIInput{config: config, Port: portString, ctx: ctx, router: router, logger: slog.Default().With("component", "module", "id", config.Id)}, nil
|
return &MIDIInput{config: config, Port: portString, ctx: ctx, router: router, logger: slog.Default().With("component", "module", "id", config.Id)}, nil
|
||||||
@@ -78,5 +79,5 @@ func (mi *MIDIInput) Run() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (mi *MIDIInput) Output(payload any) error {
|
func (mi *MIDIInput) Output(payload any) error {
|
||||||
return fmt.Errorf("midi.input output is not implemented")
|
return errors.New("midi.input output is not implemented")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package module
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
@@ -31,13 +32,13 @@ func init() {
|
|||||||
port, ok := params["port"]
|
port, ok := params["port"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.output requires a port parameter")
|
return nil, errors.New("midi.output requires a port parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
portString, ok := port.(string)
|
portString, ok := port.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.output port must be a string")
|
return nil, errors.New("midi.output port must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &MIDIOutput{config: config, Port: portString, ctx: ctx, router: router, logger: slog.Default().With("component", "module", "id", config.Id)}, nil
|
return &MIDIOutput{config: config, Port: portString, ctx: ctx, router: router, logger: slog.Default().With("component", "module", "id", config.Id)}, nil
|
||||||
@@ -76,13 +77,13 @@ func (mo *MIDIOutput) Run() error {
|
|||||||
|
|
||||||
func (mo *MIDIOutput) Output(payload any) error {
|
func (mo *MIDIOutput) Output(payload any) error {
|
||||||
if mo.SendFunc == nil {
|
if mo.SendFunc == nil {
|
||||||
return fmt.Errorf("midi.output output is not setup")
|
return errors.New("midi.output output is not setup")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadMessage, ok := payload.(midi.Message)
|
payloadMessage, ok := payload.(midi.Message)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("midi.output can only ouptut midi.Message")
|
return errors.New("midi.output can only ouptut midi.Message")
|
||||||
}
|
}
|
||||||
|
|
||||||
return mo.SendFunc(payloadMessage)
|
return mo.SendFunc(payloadMessage)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package module
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
@@ -29,37 +30,37 @@ func init() {
|
|||||||
broker, ok := params["broker"]
|
broker, ok := params["broker"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("mqtt.client requires a broker parameter")
|
return nil, errors.New("mqtt.client requires a broker parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
brokerString, ok := broker.(string)
|
brokerString, ok := broker.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("mqtt.client broker must be string")
|
return nil, errors.New("mqtt.client broker must be string")
|
||||||
}
|
}
|
||||||
|
|
||||||
topic, ok := params["topic"]
|
topic, ok := params["topic"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("mqtt.client requires a topic parameter")
|
return nil, errors.New("mqtt.client requires a topic parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
topicString, ok := topic.(string)
|
topicString, ok := topic.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("mqtt.client topic must be string")
|
return nil, errors.New("mqtt.client topic must be string")
|
||||||
}
|
}
|
||||||
|
|
||||||
clientId, ok := params["clientId"]
|
clientId, ok := params["clientId"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("mqtt.client requires a clientId parameter")
|
return nil, errors.New("mqtt.client requires a clientId parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
clientIdString, ok := clientId.(string)
|
clientIdString, ok := clientId.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("mqtt.client clientId must be string")
|
return nil, errors.New("mqtt.client clientId must be string")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &MQTTClient{config: config, Broker: brokerString, Topic: topicString, ClientID: clientIdString, ctx: ctx, router: router, logger: slog.Default().With("component", "module", "id", config.Id)}, nil
|
return &MQTTClient{config: config, Broker: brokerString, Topic: topicString, ClientID: clientIdString, ctx: ctx, router: router, logger: slog.Default().With("component", "module", "id", config.Id)}, nil
|
||||||
@@ -110,15 +111,15 @@ func (mc *MQTTClient) Output(payload any) error {
|
|||||||
fmt.Printf("payload type: %T\n", payload)
|
fmt.Printf("payload type: %T\n", payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("mqtt.client is only able to output a MQTTMessage")
|
return errors.New("mqtt.client is only able to output a MQTTMessage")
|
||||||
}
|
}
|
||||||
|
|
||||||
if mc.client == nil {
|
if mc.client == nil {
|
||||||
return fmt.Errorf("mqtt.client client is not setup")
|
return errors.New("mqtt.client client is not setup")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !mc.client.IsConnected() {
|
if !mc.client.IsConnected() {
|
||||||
return fmt.Errorf("mqtt.client is not connected")
|
return errors.New("mqtt.client is not connected")
|
||||||
}
|
}
|
||||||
|
|
||||||
token := mc.client.Publish(payloadMessage.Topic(), payloadMessage.Qos(), payloadMessage.Retained(), payloadMessage.Payload())
|
token := mc.client.Publish(payloadMessage.Topic(), payloadMessage.Qos(), payloadMessage.Retained(), payloadMessage.Payload())
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package module
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
@@ -29,25 +29,25 @@ func init() {
|
|||||||
url, ok := params["url"]
|
url, ok := params["url"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("nats.client requires a url parameter")
|
return nil, errors.New("nats.client requires a url parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
urlString, ok := url.(string)
|
urlString, ok := url.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("nats.client url must be string")
|
return nil, errors.New("nats.client url must be string")
|
||||||
}
|
}
|
||||||
|
|
||||||
subject, ok := params["subject"]
|
subject, ok := params["subject"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("nats.client requires a subject parameter")
|
return nil, errors.New("nats.client requires a subject parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
subjectString, ok := subject.(string)
|
subjectString, ok := subject.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("nats.client subject must be string")
|
return nil, errors.New("nats.client subject must be string")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &NATSClient{config: config, URL: urlString, Subject: subjectString, ctx: ctx, router: router, logger: slog.Default().With("component", "module", "id", config.Id)}, nil
|
return &NATSClient{config: config, URL: urlString, Subject: subjectString, ctx: ctx, router: router, logger: slog.Default().With("component", "module", "id", config.Id)}, nil
|
||||||
@@ -97,15 +97,15 @@ func (nc *NATSClient) Output(payload any) error {
|
|||||||
payloadMessage, ok := payload.(processor.NATSMessage)
|
payloadMessage, ok := payload.(processor.NATSMessage)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("nats.client is only able to output NATSMessage")
|
return errors.New("nats.client is only able to output NATSMessage")
|
||||||
}
|
}
|
||||||
|
|
||||||
if nc.client == nil {
|
if nc.client == nil {
|
||||||
return fmt.Errorf("nats.client client is not setup")
|
return errors.New("nats.client client is not setup")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !nc.client.IsConnected() {
|
if !nc.client.IsConnected() {
|
||||||
return fmt.Errorf("nats.client is not connected")
|
return errors.New("nats.client is not connected")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := nc.client.Publish(payloadMessage.Subject, payloadMessage.Payload)
|
err := nc.client.Publish(payloadMessage.Subject, payloadMessage.Payload)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package module
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"time"
|
"time"
|
||||||
@@ -33,13 +34,13 @@ func init() {
|
|||||||
port, ok := params["port"]
|
port, ok := params["port"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("serial.client requires a port parameter")
|
return nil, errors.New("serial.client requires a port parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
portString, ok := port.(string)
|
portString, ok := port.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("serial.client port must be a string")
|
return nil, errors.New("serial.client port must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
framingMethod := "RAW"
|
framingMethod := "RAW"
|
||||||
@@ -50,7 +51,7 @@ func init() {
|
|||||||
framingMethodString, ok := framingMethodRaw.(string)
|
framingMethodString, ok := framingMethodRaw.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("serial.client framing method must be a string")
|
return nil, errors.New("serial.client framing method must be a string")
|
||||||
}
|
}
|
||||||
framingMethod = framingMethodString
|
framingMethod = framingMethodString
|
||||||
}
|
}
|
||||||
@@ -63,12 +64,12 @@ func init() {
|
|||||||
|
|
||||||
buadRate, ok := params["baudRate"]
|
buadRate, ok := params["baudRate"]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("serial.client requires a baudRate parameter")
|
return nil, errors.New("serial.client requires a baudRate parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
baudRateNum, ok := buadRate.(float64)
|
baudRateNum, ok := buadRate.(float64)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("serial.client baudRate must be a number")
|
return nil, errors.New("serial.client baudRate must be a number")
|
||||||
}
|
}
|
||||||
|
|
||||||
mode := serial.Mode{
|
mode := serial.Mode{
|
||||||
@@ -166,7 +167,7 @@ func (sc *SerialClient) Output(payload any) error {
|
|||||||
payloadBytes, ok := payload.([]byte)
|
payloadBytes, ok := payload.([]byte)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("serial.client can only ouptut bytes")
|
return errors.New("serial.client can only ouptut bytes")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := sc.port.Write(sc.Framer.Encode(payloadBytes))
|
_, err := sc.port.Write(sc.Framer.Encode(payloadBytes))
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package module
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
@@ -43,7 +44,7 @@ func init() {
|
|||||||
specificPortNum, ok := port.(float64)
|
specificPortNum, ok := port.(float64)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("sip.call.server port must be a number")
|
return nil, errors.New("sip.call.server port must be a number")
|
||||||
}
|
}
|
||||||
portNum = int(specificPortNum)
|
portNum = int(specificPortNum)
|
||||||
}
|
}
|
||||||
@@ -56,7 +57,7 @@ func init() {
|
|||||||
specificIpString, ok := ip.(string)
|
specificIpString, ok := ip.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("sip.call.server ip must be a string")
|
return nil, errors.New("sip.call.server ip must be a string")
|
||||||
}
|
}
|
||||||
ipString = specificIpString
|
ipString = specificIpString
|
||||||
}
|
}
|
||||||
@@ -69,7 +70,7 @@ func init() {
|
|||||||
specificTransportString, ok := transport.(string)
|
specificTransportString, ok := transport.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("sip.call.server transport must be a string")
|
return nil, errors.New("sip.call.server transport must be a string")
|
||||||
}
|
}
|
||||||
transportString = specificTransportString
|
transportString = specificTransportString
|
||||||
}
|
}
|
||||||
@@ -82,7 +83,7 @@ func init() {
|
|||||||
specificTransportString, ok := userAgent.(string)
|
specificTransportString, ok := userAgent.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("sip.call.server userAgent must be a string")
|
return nil, errors.New("sip.call.server userAgent must be a string")
|
||||||
}
|
}
|
||||||
userAgentString = specificTransportString
|
userAgentString = specificTransportString
|
||||||
}
|
}
|
||||||
@@ -146,41 +147,41 @@ func (scs *SIPCallServer) Output(payload any) error {
|
|||||||
|
|
||||||
payloadMsg, ok := payload.(string)
|
payloadMsg, ok := payload.(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("sip.call.server output payload must be of type string")
|
return errors.New("sip.call.server output payload must be of type string")
|
||||||
}
|
}
|
||||||
|
|
||||||
if scs.dg == nil {
|
if scs.dg == nil {
|
||||||
return fmt.Errorf("sip.call.server diago is not initialized")
|
return errors.New("sip.call.server diago is not initialized")
|
||||||
}
|
}
|
||||||
|
|
||||||
var uri sip.Uri
|
var uri sip.Uri
|
||||||
err := sip.ParseUri(payloadMsg, &uri)
|
err := sip.ParseUri(payloadMsg, &uri)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("sip.call.server output payload is not a valid SIP URI: %v", err)
|
return fmt.Errorf("sip.call.server output payload is not a valid SIP URI: %s", err)
|
||||||
}
|
}
|
||||||
outDialog, err := scs.dg.NewDialog(uri, diago.NewDialogOptions{
|
outDialog, err := scs.dg.NewDialog(uri, diago.NewDialogOptions{
|
||||||
Transport: scs.Transport,
|
Transport: scs.Transport,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("sip.call.server failed to create new dialog: %v", err)
|
return fmt.Errorf("sip.call.server failed to create new dialog: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = outDialog.Invite(scs.ctx, diago.InviteClientOptions{})
|
err = outDialog.Invite(scs.ctx, diago.InviteClientOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("sip.call.server failed to send invite: %v", err)
|
return fmt.Errorf("sip.call.server failed to send invite: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = outDialog.Ack(scs.ctx)
|
err = outDialog.Ack(scs.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("sip.call.server failed to send ack: %v", err)
|
return fmt.Errorf("sip.call.server failed to send ack: %s", err)
|
||||||
}
|
}
|
||||||
// TODO(jwetzell): make this configurable
|
// TODO(jwetzell): make this configurable
|
||||||
// NOTE(jwetzell): wait 5 seconds before hanging up the call
|
// NOTE(jwetzell): wait 5 seconds before hanging up the call
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
err = outDialog.Hangup(scs.ctx)
|
err = outDialog.Hangup(scs.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("sip.call.server failed to hangup call: %v", err)
|
return fmt.Errorf("sip.call.server failed to hangup call: %s", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package module
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -44,7 +44,7 @@ func init() {
|
|||||||
specificPortNum, ok := port.(float64)
|
specificPortNum, ok := port.(float64)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("sip.dtmf.server port must be a number")
|
return nil, errors.New("sip.dtmf.server port must be a number")
|
||||||
}
|
}
|
||||||
portNum = int(specificPortNum)
|
portNum = int(specificPortNum)
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,7 @@ func init() {
|
|||||||
specificIpString, ok := ip.(string)
|
specificIpString, ok := ip.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("sip.dtmf.server ip must be a string")
|
return nil, errors.New("sip.dtmf.server ip must be a string")
|
||||||
}
|
}
|
||||||
ipString = specificIpString
|
ipString = specificIpString
|
||||||
}
|
}
|
||||||
@@ -70,26 +70,26 @@ func init() {
|
|||||||
specificTransportString, ok := transport.(string)
|
specificTransportString, ok := transport.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("sip.dtmf.server transport must be a string")
|
return nil, errors.New("sip.dtmf.server transport must be a string")
|
||||||
}
|
}
|
||||||
transportString = specificTransportString
|
transportString = specificTransportString
|
||||||
}
|
}
|
||||||
|
|
||||||
separator, ok := params["separator"]
|
separator, ok := params["separator"]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("sip.dtmf.server requires a separator parameter")
|
return nil, errors.New("sip.dtmf.server requires a separator parameter")
|
||||||
}
|
}
|
||||||
separatorString, ok := separator.(string)
|
separatorString, ok := separator.(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("sip.dtmf.server separator must be a string")
|
return nil, errors.New("sip.dtmf.server separator must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(separatorString) != 1 {
|
if len(separatorString) != 1 {
|
||||||
return nil, fmt.Errorf("sip.dtmf.server separator must be a single character")
|
return nil, errors.New("sip.dtmf.server separator must be a single character")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.ContainsRune("0123456789*#ABCD", rune(separatorString[0])) {
|
if !strings.ContainsRune("0123456789*#ABCD", rune(separatorString[0])) {
|
||||||
return nil, fmt.Errorf("sip.dtmf.server separator must be a valid DTMF character")
|
return nil, errors.New("sip.dtmf.server separator must be a valid DTMF character")
|
||||||
}
|
}
|
||||||
return &SIPDTMFServer{config: config, ctx: ctx, router: router, IP: ipString, Port: int(portNum), Transport: transportString, Separator: separatorString, logger: slog.Default().With("component", "module", "id", config.Id)}, nil
|
return &SIPDTMFServer{config: config, ctx: ctx, router: router, IP: ipString, Port: int(portNum), Transport: transportString, Separator: separatorString, logger: slog.Default().With("component", "module", "id", config.Id)}, nil
|
||||||
},
|
},
|
||||||
@@ -160,5 +160,5 @@ func (sds *SIPDTMFServer) HandleCall(inDialog *diago.DialogServerSession) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sds *SIPDTMFServer) Output(payload any) error {
|
func (sds *SIPDTMFServer) Output(payload any) error {
|
||||||
return fmt.Errorf("sip.dtmf.server output is not implemented")
|
return errors.New("sip.dtmf.server output is not implemented")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package module
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net"
|
"net"
|
||||||
@@ -30,24 +31,24 @@ func init() {
|
|||||||
host, ok := params["host"]
|
host, ok := params["host"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.tcp.client requires a host parameter")
|
return nil, errors.New("net.tcp.client requires a host parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
hostString, ok := host.(string)
|
hostString, ok := host.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.tcp.client host must be string")
|
return nil, errors.New("net.tcp.client host must be string")
|
||||||
}
|
}
|
||||||
|
|
||||||
port, ok := params["port"]
|
port, ok := params["port"]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.tcp.client requires a port parameter")
|
return nil, errors.New("net.tcp.client requires a port parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
portNum, ok := port.(float64)
|
portNum, ok := port.(float64)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.tcp.client port must be a number")
|
return nil, errors.New("net.tcp.client port must be a number")
|
||||||
}
|
}
|
||||||
|
|
||||||
addr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", hostString, uint16(portNum)))
|
addr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", hostString, uint16(portNum)))
|
||||||
@@ -63,7 +64,7 @@ func init() {
|
|||||||
framingMethodString, ok := framingMethodRaw.(string)
|
framingMethodString, ok := framingMethodRaw.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("misc.serial.client framing method must be a string")
|
return nil, errors.New("misc.serial.client framing method must be a string")
|
||||||
}
|
}
|
||||||
framingMethod = framingMethodString
|
framingMethod = framingMethodString
|
||||||
}
|
}
|
||||||
@@ -164,7 +165,7 @@ func (tc *TCPClient) Output(payload any) error {
|
|||||||
}
|
}
|
||||||
payloadBytes, ok := payload.([]byte)
|
payloadBytes, ok := payload.([]byte)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("net.tcp.client is only able to output bytes")
|
return errors.New("net.tcp.client is only able to output bytes")
|
||||||
}
|
}
|
||||||
_, err := tc.conn.Write(tc.framer.Encode(payloadBytes))
|
_, err := tc.conn.Write(tc.framer.Encode(payloadBytes))
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -36,13 +36,13 @@ func init() {
|
|||||||
params := config.Params
|
params := config.Params
|
||||||
port, ok := params["port"]
|
port, ok := params["port"]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.tcp.server requires a port parameter")
|
return nil, errors.New("net.tcp.server requires a port parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
portNum, ok := port.(float64)
|
portNum, ok := port.(float64)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.tcp.server port must be a number")
|
return nil, errors.New("net.tcp.server port must be a number")
|
||||||
}
|
}
|
||||||
|
|
||||||
framingMethod := "RAW"
|
framingMethod := "RAW"
|
||||||
@@ -53,7 +53,7 @@ func init() {
|
|||||||
framingMethodString, ok := framingMethodRaw.(string)
|
framingMethodString, ok := framingMethodRaw.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("misc.serial.client framing method must be a string")
|
return nil, errors.New("misc.serial.client framing method must be a string")
|
||||||
}
|
}
|
||||||
framingMethod = framingMethodString
|
framingMethod = framingMethodString
|
||||||
}
|
}
|
||||||
@@ -72,7 +72,7 @@ func init() {
|
|||||||
specificIpString, ok := ip.(string)
|
specificIpString, ok := ip.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.tcp.server ip must be a string")
|
return nil, errors.New("net.tcp.server ip must be a string")
|
||||||
}
|
}
|
||||||
ipString = specificIpString
|
ipString = specificIpString
|
||||||
}
|
}
|
||||||
@@ -201,7 +201,7 @@ func (ts *TCPServer) Output(payload any) error {
|
|||||||
payloadBytes, ok := payload.([]byte)
|
payloadBytes, ok := payload.([]byte)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("net.tcp.server is only able to output bytes")
|
return errors.New("net.tcp.server is only able to output bytes")
|
||||||
}
|
}
|
||||||
ts.connectionsMu.Lock()
|
ts.connectionsMu.Lock()
|
||||||
errorString := ""
|
errorString := ""
|
||||||
@@ -217,5 +217,5 @@ func (ts *TCPServer) Output(payload any) error {
|
|||||||
if errorString == "" {
|
if errorString == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("%s", errorString)
|
return fmt.Errorf("net.tcp.server error during output: %s", errorString)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package module
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -27,13 +27,13 @@ func init() {
|
|||||||
|
|
||||||
duration, ok := params["duration"]
|
duration, ok := params["duration"]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("gen.timer requires a duration parameter")
|
return nil, errors.New("gen.timer requires a duration parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
durationNum, ok := duration.(float64)
|
durationNum, ok := duration.(float64)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("gen.timer duration must be a number")
|
return nil, errors.New("gen.timer duration must be a number")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Timer{Duration: uint32(durationNum), config: config, ctx: ctx, router: router, logger: slog.Default().With("component", "module", "id", config.Id)}, nil
|
return &Timer{Duration: uint32(durationNum), config: config, ctx: ctx, router: router, logger: slog.Default().With("component", "module", "id", config.Id)}, nil
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package module
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net"
|
"net"
|
||||||
@@ -28,24 +29,24 @@ func init() {
|
|||||||
host, ok := params["host"]
|
host, ok := params["host"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.udp.client requires a host parameter")
|
return nil, errors.New("net.udp.client requires a host parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
hostString, ok := host.(string)
|
hostString, ok := host.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.udp.client host must be a string")
|
return nil, errors.New("net.udp.client host must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
port, ok := params["port"]
|
port, ok := params["port"]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.udp.client requires a port parameter")
|
return nil, errors.New("net.udp.client requires a port parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
portNum, ok := port.(float64)
|
portNum, ok := port.(float64)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.udp.client port must be a number")
|
return nil, errors.New("net.udp.client port must be a number")
|
||||||
}
|
}
|
||||||
|
|
||||||
addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", hostString, uint16(portNum)))
|
addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", hostString, uint16(portNum)))
|
||||||
@@ -91,7 +92,7 @@ func (uc *UDPClient) Output(payload any) error {
|
|||||||
|
|
||||||
payloadBytes, ok := payload.([]byte)
|
payloadBytes, ok := payload.([]byte)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("net.udp.client is only able to output bytes")
|
return errors.New("net.udp.client is only able to output bytes")
|
||||||
}
|
}
|
||||||
if uc.conn != nil {
|
if uc.conn != nil {
|
||||||
_, err := uc.conn.Write(payloadBytes)
|
_, err := uc.conn.Write(payloadBytes)
|
||||||
@@ -100,7 +101,7 @@ func (uc *UDPClient) Output(payload any) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("net.udp.client client is not setup")
|
return errors.New("net.udp.client client is not setup")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package module
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net"
|
"net"
|
||||||
@@ -28,24 +29,24 @@ func init() {
|
|||||||
ip, ok := params["ip"]
|
ip, ok := params["ip"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.udp.multicast requires an ip parameter")
|
return nil, errors.New("net.udp.multicast requires an ip parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
ipString, ok := ip.(string)
|
ipString, ok := ip.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.udp.multicast ip must be a string")
|
return nil, errors.New("net.udp.multicast ip must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
port, ok := params["port"]
|
port, ok := params["port"]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.udp.multicast requires a port parameter")
|
return nil, errors.New("net.udp.multicast requires a port parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
portNum, ok := port.(float64)
|
portNum, ok := port.(float64)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.udp.multicast port must be a number")
|
return nil, errors.New("net.udp.multicast port must be a number")
|
||||||
}
|
}
|
||||||
|
|
||||||
addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", ipString, uint16(portNum)))
|
addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", ipString, uint16(portNum)))
|
||||||
@@ -111,11 +112,11 @@ func (um *UDPMulticast) Output(payload any) error {
|
|||||||
|
|
||||||
payloadBytes, ok := payload.([]byte)
|
payloadBytes, ok := payload.([]byte)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("net.udp.multicast can only output bytes")
|
return errors.New("net.udp.multicast can only output bytes")
|
||||||
}
|
}
|
||||||
|
|
||||||
if um.conn == nil {
|
if um.conn == nil {
|
||||||
return fmt.Errorf("net.udp.multicast connection is not setup")
|
return errors.New("net.udp.multicast connection is not setup")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := um.conn.Write(payloadBytes)
|
_, err := um.conn.Write(payloadBytes)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package module
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
@@ -27,13 +28,13 @@ func init() {
|
|||||||
params := config.Params
|
params := config.Params
|
||||||
port, ok := params["port"]
|
port, ok := params["port"]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.udp.server requires a port parameter")
|
return nil, errors.New("net.udp.server requires a port parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
portNum, ok := port.(float64)
|
portNum, ok := port.(float64)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.udp.server port must be a number")
|
return nil, errors.New("net.udp.server port must be a number")
|
||||||
}
|
}
|
||||||
|
|
||||||
ipString := "0.0.0.0"
|
ipString := "0.0.0.0"
|
||||||
@@ -44,7 +45,7 @@ func init() {
|
|||||||
specificIpString, ok := ip.(string)
|
specificIpString, ok := ip.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.udp.server ip must be a string")
|
return nil, errors.New("net.udp.server ip must be a string")
|
||||||
}
|
}
|
||||||
ipString = specificIpString
|
ipString = specificIpString
|
||||||
}
|
}
|
||||||
@@ -107,5 +108,5 @@ func (us *UDPServer) Run() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (us *UDPServer) Output(payload any) error {
|
func (us *UDPServer) Output(payload any) error {
|
||||||
return fmt.Errorf("net.udp.server output is not implemented")
|
return errors.New("net.udp.server output is not implemented")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
@@ -16,7 +16,7 @@ func (fp *FloatParse) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
payloadString, ok := payload.(string)
|
payloadString, ok := payload.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("float.parse processor only accepts a string")
|
return nil, errors.New("float.parse processor only accepts a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(jwetzell): make bitSize configurable
|
// TODO(jwetzell): make bitSize configurable
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package processor
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"strconv"
|
"strconv"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
@@ -190,13 +190,13 @@ func init() {
|
|||||||
id, ok := params["id"]
|
id, ok := params["id"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("freed.create requires an id parameter")
|
return nil, errors.New("freed.create requires an id parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
idString, ok := id.(string)
|
idString, ok := id.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("freed.create id must be a string")
|
return nil, errors.New("freed.create id must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
idTemplate, err := template.New("id").Parse(idString)
|
idTemplate, err := template.New("id").Parse(idString)
|
||||||
@@ -208,13 +208,13 @@ func init() {
|
|||||||
pan, ok := params["pan"]
|
pan, ok := params["pan"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("freed.create requires a pan parameter")
|
return nil, errors.New("freed.create requires a pan parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
panString, ok := pan.(string)
|
panString, ok := pan.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("freed.create pan must be a string")
|
return nil, errors.New("freed.create pan must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
panTemplate, err := template.New("pan").Parse(panString)
|
panTemplate, err := template.New("pan").Parse(panString)
|
||||||
@@ -222,13 +222,13 @@ func init() {
|
|||||||
tilt, ok := params["tilt"]
|
tilt, ok := params["tilt"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("freed.create requires a tilt parameter")
|
return nil, errors.New("freed.create requires a tilt parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
tiltString, ok := tilt.(string)
|
tiltString, ok := tilt.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("freed.create tilt must be a string")
|
return nil, errors.New("freed.create tilt must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
tiltTemplate, err := template.New("tilt").Parse(tiltString)
|
tiltTemplate, err := template.New("tilt").Parse(tiltString)
|
||||||
@@ -236,13 +236,13 @@ func init() {
|
|||||||
roll, ok := params["roll"]
|
roll, ok := params["roll"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("freed.create requires a roll parameter")
|
return nil, errors.New("freed.create requires a roll parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
rollString, ok := roll.(string)
|
rollString, ok := roll.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("freed.create roll must be a string")
|
return nil, errors.New("freed.create roll must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
rollTemplate, err := template.New("roll").Parse(rollString)
|
rollTemplate, err := template.New("roll").Parse(rollString)
|
||||||
@@ -254,13 +254,13 @@ func init() {
|
|||||||
posX, ok := params["posX"]
|
posX, ok := params["posX"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("freed.create requires a posX parameter")
|
return nil, errors.New("freed.create requires a posX parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
posXString, ok := posX.(string)
|
posXString, ok := posX.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("freed.create posX must be a string")
|
return nil, errors.New("freed.create posX must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
posXTemplate, err := template.New("posX").Parse(posXString)
|
posXTemplate, err := template.New("posX").Parse(posXString)
|
||||||
@@ -272,13 +272,13 @@ func init() {
|
|||||||
posY, ok := params["posY"]
|
posY, ok := params["posY"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("freed.create requires a posY parameter")
|
return nil, errors.New("freed.create requires a posY parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
posYString, ok := posY.(string)
|
posYString, ok := posY.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("freed.create posY must be a string")
|
return nil, errors.New("freed.create posY must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
posYTemplate, err := template.New("posY").Parse(posYString)
|
posYTemplate, err := template.New("posY").Parse(posYString)
|
||||||
@@ -290,13 +290,13 @@ func init() {
|
|||||||
posZ, ok := params["posZ"]
|
posZ, ok := params["posZ"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("freed.create requires a posZ parameter")
|
return nil, errors.New("freed.create requires a posZ parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
posZString, ok := posZ.(string)
|
posZString, ok := posZ.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("freed.create posZ must be a string")
|
return nil, errors.New("freed.create posZ must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
posZTemplate, err := template.New("posZ").Parse(posZString)
|
posZTemplate, err := template.New("posZ").Parse(posZString)
|
||||||
@@ -308,13 +308,13 @@ func init() {
|
|||||||
zoom, ok := params["zoom"]
|
zoom, ok := params["zoom"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("freed.create requires a zoom parameter")
|
return nil, errors.New("freed.create requires a zoom parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
zoomString, ok := zoom.(string)
|
zoomString, ok := zoom.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("freed.create zoom must be a string")
|
return nil, errors.New("freed.create zoom must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
zoomTemplate, err := template.New("zoom").Parse(zoomString)
|
zoomTemplate, err := template.New("zoom").Parse(zoomString)
|
||||||
@@ -322,13 +322,13 @@ func init() {
|
|||||||
focus, ok := params["focus"]
|
focus, ok := params["focus"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("freed.create requires a focus parameter")
|
return nil, errors.New("freed.create requires a focus parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
focusString, ok := focus.(string)
|
focusString, ok := focus.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("freed.create focus must be a string")
|
return nil, errors.New("freed.create focus must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
focusTemplate, err := template.New("focus").Parse(focusString)
|
focusTemplate, err := template.New("focus").Parse(focusString)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
|
|
||||||
freeD "github.com/jwetzell/free-d-go"
|
freeD "github.com/jwetzell/free-d-go"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
@@ -16,7 +16,7 @@ func (fdd *FreeDDecode) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
payloadBytes, ok := payload.([]byte)
|
payloadBytes, ok := payload.([]byte)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("freed.decode processor only accepts a []byte")
|
return nil, errors.New("freed.decode processor only accepts a []byte")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadMessage, err := freeD.Decode(payloadBytes)
|
payloadMessage, err := freeD.Decode(payloadBytes)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
|
|
||||||
freeD "github.com/jwetzell/free-d-go"
|
freeD "github.com/jwetzell/free-d-go"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
@@ -16,7 +16,7 @@ func (fde *FreeDEncode) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
payloadPosition, ok := payload.(freeD.FreeDPosition)
|
payloadPosition, ok := payload.(freeD.FreeDPosition)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("freed.decode processor only accepts a FreeDEncode")
|
return nil, errors.New("freed.decode processor only accepts a FreeDEncode")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadBytes := freeD.Encode(payloadPosition)
|
payloadBytes := freeD.Encode(payloadPosition)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package processor
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
@@ -50,25 +50,25 @@ func init() {
|
|||||||
method, ok := params["method"]
|
method, ok := params["method"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("http.request.create requires a method parameter")
|
return nil, errors.New("http.request.create requires a method parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
methodString, ok := method.(string)
|
methodString, ok := method.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("http.request.create url must be a string")
|
return nil, errors.New("http.request.create url must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
url, ok := params["url"]
|
url, ok := params["url"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("http.request.create requires a url parameter")
|
return nil, errors.New("http.request.create requires a url parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
urlString, ok := url.(string)
|
urlString, ok := url.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("http.request.create url must be a string")
|
return nil, errors.New("http.request.create url must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
urlTemplate, err := template.New("url").Parse(urlString)
|
urlTemplate, err := template.New("url").Parse(urlString)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ func (hre *HTTPRequestEncode) Process(ctx context.Context, payload any) (any, er
|
|||||||
payloadRequest, ok := payload.(*http.Request)
|
payloadRequest, ok := payload.(*http.Request)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("http.request.encode processor only accepts an http.Request")
|
return nil, errors.New("http.request.encode processor only accepts an http.Request")
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes, err := io.ReadAll(payloadRequest.Body)
|
bytes, err := io.ReadAll(payloadRequest.Body)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -20,7 +21,7 @@ func (hrf *HTTPRequestFilter) Process(ctx context.Context, payload any) (any, er
|
|||||||
payloadRequest, ok := payload.(*http.Request)
|
payloadRequest, ok := payload.(*http.Request)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("http.request.filter can only operate on http.Request payloads")
|
return nil, errors.New("http.request.filter can only operate on http.Request payloads")
|
||||||
}
|
}
|
||||||
|
|
||||||
if hrf.Method != "" {
|
if hrf.Method != "" {
|
||||||
@@ -48,13 +49,13 @@ func init() {
|
|||||||
path, ok := params["path"]
|
path, ok := params["path"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("http.request.filter requires a path parameter")
|
return nil, errors.New("http.request.filter requires a path parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
pathString, ok := path.(string)
|
pathString, ok := path.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("http.request.filter path must be a string")
|
return nil, errors.New("http.request.filter path must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
pathRegexp, err := regexp.Compile(fmt.Sprintf("^%s$", pathString))
|
pathRegexp, err := regexp.Compile(fmt.Sprintf("^%s$", pathString))
|
||||||
@@ -69,7 +70,7 @@ func init() {
|
|||||||
methodString, ok := method.(string)
|
methodString, ok := method.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("http.request.filter method must be a string")
|
return nil, errors.New("http.request.filter method must be a string")
|
||||||
}
|
}
|
||||||
return &HTTPRequestFilter{config: config, Path: pathRegexp, Method: methodString}, nil
|
return &HTTPRequestFilter{config: config, Path: pathRegexp, Method: methodString}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ func (hre *HTTPResponseEncode) Process(ctx context.Context, payload any) (any, e
|
|||||||
payloadResponse, ok := payload.(*http.Response)
|
payloadResponse, ok := payload.(*http.Response)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("http.response.encode processor only accepts an http.Response")
|
return nil, errors.New("http.response.encode processor only accepts an http.Response")
|
||||||
}
|
}
|
||||||
defer payloadResponse.Body.Close()
|
defer payloadResponse.Body.Close()
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
@@ -16,7 +16,7 @@ func (ip *IntParse) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
payloadString, ok := payload.(string)
|
payloadString, ok := payload.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("int.parse processor only accepts a string")
|
return nil, errors.New("int.parse processor only accepts a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(jwetzell): make base and bitSize configurable
|
// TODO(jwetzell): make base and bitSize configurable
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package processor
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"text/template"
|
"text/template"
|
||||||
@@ -34,13 +35,13 @@ func newMidiNoteOnCreate(config config.ProcessorConfig) (Processor, error) {
|
|||||||
channel, ok := params["channel"]
|
channel, ok := params["channel"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.create NoteOn requires a channel parameter")
|
return nil, errors.New("midi.message.create NoteOn requires a channel parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
channelString, ok := channel.(string)
|
channelString, ok := channel.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.create NoteOn channel must be a string")
|
return nil, errors.New("midi.message.create NoteOn channel must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
channelTemplate, err := template.New("channel").Parse(channelString)
|
channelTemplate, err := template.New("channel").Parse(channelString)
|
||||||
@@ -52,13 +53,13 @@ func newMidiNoteOnCreate(config config.ProcessorConfig) (Processor, error) {
|
|||||||
note, ok := params["note"]
|
note, ok := params["note"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.create NoteOn requires a note parameter")
|
return nil, errors.New("midi.message.create NoteOn requires a note parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
noteString, ok := note.(string)
|
noteString, ok := note.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.create NoteOn note must be a string")
|
return nil, errors.New("midi.message.create NoteOn note must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
noteTemplate, err := template.New("note").Parse(noteString)
|
noteTemplate, err := template.New("note").Parse(noteString)
|
||||||
@@ -70,13 +71,13 @@ func newMidiNoteOnCreate(config config.ProcessorConfig) (Processor, error) {
|
|||||||
velocity, ok := params["velocity"]
|
velocity, ok := params["velocity"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.create NoteOn requires a velocity parameter")
|
return nil, errors.New("midi.message.create NoteOn requires a velocity parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
velocityString, ok := velocity.(string)
|
velocityString, ok := velocity.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.create NoteOn velocity must be a string")
|
return nil, errors.New("midi.message.create NoteOn velocity must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
velocityTemplate, err := template.New("velocity").Parse(velocityString)
|
velocityTemplate, err := template.New("velocity").Parse(velocityString)
|
||||||
@@ -125,13 +126,13 @@ func newMidiNoteOffCreate(config config.ProcessorConfig) (Processor, error) {
|
|||||||
channel, ok := params["channel"]
|
channel, ok := params["channel"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.create NoteOn requires a channel parameter")
|
return nil, errors.New("midi.message.create NoteOn requires a channel parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
channelString, ok := channel.(string)
|
channelString, ok := channel.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.create NoteOn channel must be a string")
|
return nil, errors.New("midi.message.create NoteOn channel must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
channelTemplate, err := template.New("channel").Parse(channelString)
|
channelTemplate, err := template.New("channel").Parse(channelString)
|
||||||
@@ -143,13 +144,13 @@ func newMidiNoteOffCreate(config config.ProcessorConfig) (Processor, error) {
|
|||||||
note, ok := params["note"]
|
note, ok := params["note"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.create NoteOn requires a note parameter")
|
return nil, errors.New("midi.message.create NoteOn requires a note parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
noteString, ok := note.(string)
|
noteString, ok := note.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.create NoteOn note must be a string")
|
return nil, errors.New("midi.message.create NoteOn note must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
noteTemplate, err := template.New("note").Parse(noteString)
|
noteTemplate, err := template.New("note").Parse(noteString)
|
||||||
@@ -190,13 +191,13 @@ func newMidiControlChangeCreate(config config.ProcessorConfig) (Processor, error
|
|||||||
channel, ok := params["channel"]
|
channel, ok := params["channel"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.create ControlChange requires a channel parameter")
|
return nil, errors.New("midi.message.create ControlChange requires a channel parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
channelString, ok := channel.(string)
|
channelString, ok := channel.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.create ControlChange channel must be a string")
|
return nil, errors.New("midi.message.create ControlChange channel must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
channelTemplate, err := template.New("channel").Parse(channelString)
|
channelTemplate, err := template.New("channel").Parse(channelString)
|
||||||
@@ -208,13 +209,13 @@ func newMidiControlChangeCreate(config config.ProcessorConfig) (Processor, error
|
|||||||
controller, ok := params["controller"]
|
controller, ok := params["controller"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.create ControlChange requires a controller parameter")
|
return nil, errors.New("midi.message.create ControlChange requires a controller parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
controllerString, ok := controller.(string)
|
controllerString, ok := controller.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.create ControlChange controller must be a string")
|
return nil, errors.New("midi.message.create ControlChange controller must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
controllerTemplate, err := template.New("controller").Parse(controllerString)
|
controllerTemplate, err := template.New("controller").Parse(controllerString)
|
||||||
@@ -226,13 +227,13 @@ func newMidiControlChangeCreate(config config.ProcessorConfig) (Processor, error
|
|||||||
value, ok := params["value"]
|
value, ok := params["value"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.create ControlChange requires a value parameter")
|
return nil, errors.New("midi.message.create ControlChange requires a value parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
valueString, ok := value.(string)
|
valueString, ok := value.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.create ControlChange value must be a string")
|
return nil, errors.New("midi.message.create ControlChange value must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
valueTemplate, err := template.New("value").Parse(valueString)
|
valueTemplate, err := template.New("value").Parse(valueString)
|
||||||
@@ -282,13 +283,13 @@ func newMidiProgramChangeCreate(config config.ProcessorConfig) (Processor, error
|
|||||||
channel, ok := params["channel"]
|
channel, ok := params["channel"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.create ProgramChange requires a channel parameter")
|
return nil, errors.New("midi.message.create ProgramChange requires a channel parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
channelString, ok := channel.(string)
|
channelString, ok := channel.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.create ProgramChange channel must be a string")
|
return nil, errors.New("midi.message.create ProgramChange channel must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
channelTemplate, err := template.New("channel").Parse(channelString)
|
channelTemplate, err := template.New("channel").Parse(channelString)
|
||||||
@@ -300,13 +301,13 @@ func newMidiProgramChangeCreate(config config.ProcessorConfig) (Processor, error
|
|||||||
program, ok := params["program"]
|
program, ok := params["program"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.create ProgramChange requires a program parameter")
|
return nil, errors.New("midi.message.create ProgramChange requires a program parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
programString, ok := program.(string)
|
programString, ok := program.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.create ProgramChange program must be a string")
|
return nil, errors.New("midi.message.create ProgramChange program must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
programTemplate, err := template.New("program").Parse(programString)
|
programTemplate, err := template.New("program").Parse(programString)
|
||||||
@@ -349,13 +350,13 @@ func init() {
|
|||||||
msgType, ok := params["type"]
|
msgType, ok := params["type"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.create requires a type parameter")
|
return nil, errors.New("midi.message.create requires a type parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
msgTypeString, ok := msgType.(string)
|
msgTypeString, ok := msgType.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.create type parameter must be a string")
|
return nil, errors.New("midi.message.create type parameter must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
switch msgTypeString {
|
switch msgTypeString {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"gitlab.com/gomidi/midi/v2"
|
"gitlab.com/gomidi/midi/v2"
|
||||||
@@ -18,7 +18,7 @@ func (mmd *MIDIMessageDecode) Process(ctx context.Context, payload any) (any, er
|
|||||||
payloadBytes, ok := payload.([]byte)
|
payloadBytes, ok := payload.([]byte)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.decode processor only accepts a []byte")
|
return nil, errors.New("midi.message.decode processor only accepts a []byte")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadMessage := midi.Message(payloadBytes)
|
payloadMessage := midi.Message(payloadBytes)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"gitlab.com/gomidi/midi/v2"
|
"gitlab.com/gomidi/midi/v2"
|
||||||
@@ -18,7 +18,7 @@ func (mme *MIDIMessageEncode) Process(ctx context.Context, payload any) (any, er
|
|||||||
payloadMessage, ok := payload.(midi.Message)
|
payloadMessage, ok := payload.(midi.Message)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.encode processor only accepts an midi.Message")
|
return nil, errors.New("midi.message.encode processor only accepts an midi.Message")
|
||||||
}
|
}
|
||||||
|
|
||||||
return payloadMessage.Bytes(), nil
|
return payloadMessage.Bytes(), nil
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"gitlab.com/gomidi/midi/v2"
|
"gitlab.com/gomidi/midi/v2"
|
||||||
@@ -19,7 +19,7 @@ func (mmf *MIDIMessageFilter) Process(ctx context.Context, payload any) (any, er
|
|||||||
payloadMessage, ok := payload.(midi.Message)
|
payloadMessage, ok := payload.(midi.Message)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.filter processor only accepts an midi.Message")
|
return nil, errors.New("midi.message.filter processor only accepts an midi.Message")
|
||||||
}
|
}
|
||||||
|
|
||||||
if payloadMessage.Type().String() != mmf.MIDIType {
|
if payloadMessage.Type().String() != mmf.MIDIType {
|
||||||
@@ -41,12 +41,12 @@ func init() {
|
|||||||
midiType, ok := params["type"]
|
midiType, ok := params["type"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.filter requires a type parameter")
|
return nil, errors.New("midi.message.filter requires a type parameter")
|
||||||
}
|
}
|
||||||
midiTypeString, ok := midiType.(string)
|
midiTypeString, ok := midiType.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.filter type must be a string")
|
return nil, errors.New("midi.message.filter type must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &MIDIMessageFilter{config: config, MIDIType: midiTypeString}, nil
|
return &MIDIMessageFilter{config: config, MIDIType: midiTypeString}, nil
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
@@ -47,7 +48,7 @@ func (mmu *MIDIMessageUnpack) Process(ctx context.Context, payload any) (any, er
|
|||||||
payloadMidi, ok := payload.(midi.Message)
|
payloadMidi, ok := payload.(midi.Message)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("midi.message.unpack processor only accepts a midi.Message")
|
return nil, errors.New("midi.message.unpack processor only accepts a midi.Message")
|
||||||
}
|
}
|
||||||
|
|
||||||
switch payloadMidi.Type() {
|
switch payloadMidi.Type() {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
@@ -74,44 +74,44 @@ func init() {
|
|||||||
topic, ok := params["topic"]
|
topic, ok := params["topic"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("mqtt.message.create requires a topic parameter")
|
return nil, errors.New("mqtt.message.create requires a topic parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
topicString, ok := topic.(string)
|
topicString, ok := topic.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("mqtt.message.create topic must be a string")
|
return nil, errors.New("mqtt.message.create topic must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
qos, ok := params["qos"]
|
qos, ok := params["qos"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("mqtt.message.create requires a qos parameter")
|
return nil, errors.New("mqtt.message.create requires a qos parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
qosByte, ok := qos.(float64)
|
qosByte, ok := qos.(float64)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("mqtt.message.create qos must be a number")
|
return nil, errors.New("mqtt.message.create qos must be a number")
|
||||||
}
|
}
|
||||||
|
|
||||||
retained, ok := params["retained"]
|
retained, ok := params["retained"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("mqtt.message.create requires a retained parameter")
|
return nil, errors.New("mqtt.message.create requires a retained parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
retainedBool, ok := retained.(bool)
|
retainedBool, ok := retained.(bool)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("mqtt.message.create retained must be a boolean")
|
return nil, errors.New("mqtt.message.create retained must be a boolean")
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO(jwetzell): convert payload into []byte or string for sending
|
//TODO(jwetzell): convert payload into []byte or string for sending
|
||||||
payload, ok := params["payload"]
|
payload, ok := params["payload"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("mqtt.message.create requires a payload parameter")
|
return nil, errors.New("mqtt.message.create requires a payload parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
if payloadBytes, ok := payload.([]byte); ok {
|
if payloadBytes, ok := payload.([]byte); ok {
|
||||||
@@ -121,7 +121,7 @@ func init() {
|
|||||||
payloadString, ok := payload.(string)
|
payloadString, ok := payload.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("mqtt.message.create payload must be a string or byte array")
|
return nil, errors.New("mqtt.message.create payload must be a string or byte array")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadBytes := []byte(payloadString)
|
payloadBytes := []byte(payloadString)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
|
|
||||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
@@ -16,7 +16,7 @@ func (mme *MQTTMessageEncode) Process(ctx context.Context, payload any) (any, er
|
|||||||
payloadMessage, ok := payload.(mqtt.Message)
|
payloadMessage, ok := payload.(mqtt.Message)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("mqtt.message.encode processor only accepts an mqtt.Message")
|
return nil, errors.New("mqtt.message.encode processor only accepts an mqtt.Message")
|
||||||
}
|
}
|
||||||
|
|
||||||
return payloadMessage.Payload(), nil
|
return payloadMessage.Payload(), nil
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package processor
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
@@ -52,25 +52,25 @@ func init() {
|
|||||||
subject, ok := params["subject"]
|
subject, ok := params["subject"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("nats.message.create requires a subject parameter")
|
return nil, errors.New("nats.message.create requires a subject parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
subjectString, ok := subject.(string)
|
subjectString, ok := subject.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("nats.message.create subject must be a string")
|
return nil, errors.New("nats.message.create subject must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
payload, ok := params["payload"]
|
payload, ok := params["payload"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("osc.message.create requires a payload parameter")
|
return nil, errors.New("nats.message.create requires a payload parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadString, ok := payload.(string)
|
payloadString, ok := payload.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("osc.message.create payload must be a string")
|
return nil, errors.New("nats.message.create payload must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadTemplate, err := template.New("payload").Parse(payloadString)
|
payloadTemplate, err := template.New("payload").Parse(payloadString)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/nats-io/nats.go"
|
"github.com/nats-io/nats.go"
|
||||||
@@ -16,7 +16,7 @@ func (nme *NATSMessageEncode) Process(ctx context.Context, payload any) (any, er
|
|||||||
payloadMessage, ok := payload.(*nats.Msg)
|
payloadMessage, ok := payload.(*nats.Msg)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("nats.message.encode processor only accepts an nats.Msg")
|
return nil, errors.New("nats.message.encode processor only accepts an nats.Msg")
|
||||||
}
|
}
|
||||||
|
|
||||||
return payloadMessage.Data, nil
|
return payloadMessage.Data, nil
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"text/template"
|
"text/template"
|
||||||
@@ -31,11 +32,11 @@ func (o *OSCMessageCreate) Process(ctx context.Context, payload any) (any, error
|
|||||||
addressString := addressBuffer.String()
|
addressString := addressBuffer.String()
|
||||||
|
|
||||||
if len(addressString) == 0 {
|
if len(addressString) == 0 {
|
||||||
return nil, fmt.Errorf("osc.message.create address must not be empty")
|
return nil, errors.New("osc.message.create address must not be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
if addressString[0] != '/' {
|
if addressString[0] != '/' {
|
||||||
return nil, fmt.Errorf("osc.message.create address must start with '/'")
|
return nil, errors.New("osc.message.create address must start with '/'")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadMessage := osc.OSCMessage{
|
payloadMessage := osc.OSCMessage{
|
||||||
@@ -82,13 +83,13 @@ func init() {
|
|||||||
address, ok := params["address"]
|
address, ok := params["address"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("osc.message.create requires an address parameter")
|
return nil, errors.New("osc.message.create requires an address parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
addressString, ok := address.(string)
|
addressString, ok := address.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("osc.message.create address must be a string")
|
return nil, errors.New("osc.message.create address must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
addressTemplate, err := template.New("address").Parse(addressString)
|
addressTemplate, err := template.New("address").Parse(addressString)
|
||||||
@@ -109,17 +110,17 @@ func init() {
|
|||||||
types, ok := params["types"]
|
types, ok := params["types"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("osc.message.create requires a types parameter with args")
|
return nil, errors.New("osc.message.create requires a types parameter with args")
|
||||||
}
|
}
|
||||||
|
|
||||||
typesString, ok := types.(string)
|
typesString, ok := types.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("osc.message.create types must be a string")
|
return nil, errors.New("osc.message.create types must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(rawArgs) != len(typesString) {
|
if len(rawArgs) != len(typesString) {
|
||||||
return nil, fmt.Errorf("osc.message.create args and types must be the same length")
|
return nil, errors.New("osc.message.create args and types must be the same length")
|
||||||
}
|
}
|
||||||
|
|
||||||
argTemplates := []*template.Template{}
|
argTemplates := []*template.Template{}
|
||||||
@@ -128,7 +129,7 @@ func init() {
|
|||||||
argString, ok := rawArg.(string)
|
argString, ok := rawArg.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("osc.message.create arg must be a string")
|
return nil, errors.New("osc.message.create arg must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
argTemplate, err := template.New("arg").Parse(argString)
|
argTemplate, err := template.New("arg").Parse(argString)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
|
|
||||||
osc "github.com/jwetzell/osc-go"
|
osc "github.com/jwetzell/osc-go"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
@@ -16,15 +16,15 @@ func (o *OSCMessageDecode) Process(ctx context.Context, payload any) (any, error
|
|||||||
payloadBytes, ok := payload.([]byte)
|
payloadBytes, ok := payload.([]byte)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("osc.message.decode processor only accepts a []byte payload")
|
return nil, errors.New("osc.message.decode processor only accepts a []byte payload")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(payloadBytes) == 0 {
|
if len(payloadBytes) == 0 {
|
||||||
return nil, fmt.Errorf("osc.message.decode processor can't work on empty []byte")
|
return nil, errors.New("osc.message.decode processor can't work on empty []byte")
|
||||||
}
|
}
|
||||||
|
|
||||||
if payloadBytes[0] != '/' {
|
if payloadBytes[0] != '/' {
|
||||||
return nil, fmt.Errorf("osc.message.decode processor needs an OSC looking []byte")
|
return nil, errors.New("osc.message.decode processor needs an OSC looking []byte")
|
||||||
}
|
}
|
||||||
|
|
||||||
message, err := osc.MessageFromBytes(payloadBytes)
|
message, err := osc.MessageFromBytes(payloadBytes)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
|
|
||||||
osc "github.com/jwetzell/osc-go"
|
osc "github.com/jwetzell/osc-go"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
@@ -16,7 +16,7 @@ func (o *OSCMessageEncode) Process(ctx context.Context, payload any) (any, error
|
|||||||
payloadMessage, ok := payload.(osc.OSCMessage)
|
payloadMessage, ok := payload.(osc.OSCMessage)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("osc.message.encode processor only accepts an OSCMessage")
|
return nil, errors.New("osc.message.encode processor only accepts an OSCMessage")
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes := payloadMessage.ToBytes()
|
bytes := payloadMessage.ToBytes()
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -20,7 +21,7 @@ func (o *OSCMessageFilter) Process(ctx context.Context, payload any) (any, error
|
|||||||
payloadMessage, ok := payload.(osc.OSCMessage)
|
payloadMessage, ok := payload.(osc.OSCMessage)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("osc.message.filter can only operate on OSCMessage payloads")
|
return nil, errors.New("osc.message.filter can only operate on OSCMessage payloads")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !o.Address.MatchString(payloadMessage.Address) {
|
if !o.Address.MatchString(payloadMessage.Address) {
|
||||||
@@ -42,13 +43,13 @@ func init() {
|
|||||||
address, ok := params["address"]
|
address, ok := params["address"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("osc.message.filter requires an address parameter")
|
return nil, errors.New("osc.message.filter requires an address parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
addressString, ok := address.(string)
|
addressString, ok := address.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("osc.message.filter address must be a string")
|
return nil, errors.New("osc.message.filter address must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
addressPattern := strings.ReplaceAll(addressString, "?", ".")
|
addressPattern := strings.ReplaceAll(addressString, "?", ".")
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package processor
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
osc "github.com/jwetzell/osc-go"
|
osc "github.com/jwetzell/osc-go"
|
||||||
@@ -19,7 +19,7 @@ func (o *OSCMessageTransform) Process(ctx context.Context, payload any) (any, er
|
|||||||
payloadMessage, ok := payload.(osc.OSCMessage)
|
payloadMessage, ok := payload.(osc.OSCMessage)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("osc.message.transform processor only accepts an OSCMessage")
|
return nil, errors.New("osc.message.transform processor only accepts an OSCMessage")
|
||||||
}
|
}
|
||||||
|
|
||||||
var addressBuffer bytes.Buffer
|
var addressBuffer bytes.Buffer
|
||||||
@@ -33,11 +33,11 @@ func (o *OSCMessageTransform) Process(ctx context.Context, payload any) (any, er
|
|||||||
addressString := addressBuffer.String()
|
addressString := addressBuffer.String()
|
||||||
|
|
||||||
if len(addressString) == 0 {
|
if len(addressString) == 0 {
|
||||||
return nil, fmt.Errorf("osc.message.transform address must not be empty")
|
return nil, errors.New("osc.message.transform address must not be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
if addressString[0] != '/' {
|
if addressString[0] != '/' {
|
||||||
return nil, fmt.Errorf("osc.message.transform address must start with '/'")
|
return nil, errors.New("osc.message.transform address must start with '/'")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadMessage.Address = addressString
|
payloadMessage.Address = addressString
|
||||||
@@ -57,13 +57,13 @@ func init() {
|
|||||||
address, ok := params["address"]
|
address, ok := params["address"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("osc.message.transform requires an address parameter")
|
return nil, errors.New("osc.message.transform requires an address parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
addressString, ok := address.(string)
|
addressString, ok := address.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("osc.message.transform address must be a string")
|
return nil, errors.New("osc.message.transform address must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
addressTemplate, err := template.New("address").Parse(addressString)
|
addressTemplate, err := template.New("address").Parse(addressString)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
|
|
||||||
"github.com/expr-lang/expr"
|
"github.com/expr-lang/expr"
|
||||||
"github.com/expr-lang/expr/vm"
|
"github.com/expr-lang/expr/vm"
|
||||||
@@ -38,13 +38,13 @@ func init() {
|
|||||||
expression, ok := params["expression"]
|
expression, ok := params["expression"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("script.expr requires an expression parameter")
|
return nil, errors.New("script.expr requires an expression parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
expressionString, ok := expression.(string)
|
expressionString, ok := expression.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("script.expr expression must be a string")
|
return nil, errors.New("script.expr expression must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
program, err := expr.Compile(expressionString)
|
program, err := expr.Compile(expressionString)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package processor
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"errors"
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"modernc.org/quickjs"
|
"modernc.org/quickjs"
|
||||||
@@ -74,13 +74,13 @@ func init() {
|
|||||||
program, ok := params["program"]
|
program, ok := params["program"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("script.js requires a program parameter")
|
return nil, errors.New("script.js requires a program parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
programString, ok := program.(string)
|
programString, ok := program.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("script.js program must be a string")
|
return nil, errors.New("script.js program must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ScriptJS{config: config, Program: programString}, nil
|
return &ScriptJS{config: config, Program: programString}, nil
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package processor
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
@@ -39,13 +39,13 @@ func init() {
|
|||||||
tmpl, ok := params["template"]
|
tmpl, ok := params["template"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("string.create requires a template parameter")
|
return nil, errors.New("string.create requires a template parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
templateString, ok := tmpl.(string)
|
templateString, ok := tmpl.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("string.create template must be a string")
|
return nil, errors.New("string.create template must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
templateTemplate, err := template.New("template").Parse(templateString)
|
templateTemplate, err := template.New("template").Parse(templateString)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
@@ -15,7 +15,7 @@ func (sd *StringDecode) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
payloadBytes, ok := payload.([]byte)
|
payloadBytes, ok := payload.([]byte)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("string.decode processor only accepts a []byte")
|
return nil, errors.New("string.decode processor only accepts a []byte")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadMessage := string(payloadBytes)
|
payloadMessage := string(payloadBytes)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
@@ -15,7 +15,7 @@ func (se *StringEncode) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
payloadString, ok := payload.(string)
|
payloadString, ok := payload.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("string.encode processor only accepts a string")
|
return nil, errors.New("string.encode processor only accepts a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadBytes := []byte(payloadString)
|
payloadBytes := []byte(payloadString)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
@@ -17,7 +17,7 @@ func (se *StringFilter) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
payloadString, ok := payload.(string)
|
payloadString, ok := payload.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("string.filter processor only accepts a string")
|
return nil, errors.New("string.filter processor only accepts a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !se.Pattern.MatchString(payloadString) {
|
if !se.Pattern.MatchString(payloadString) {
|
||||||
@@ -40,13 +40,13 @@ func init() {
|
|||||||
pattern, ok := params["pattern"]
|
pattern, ok := params["pattern"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("http.request.filter requires a pattern parameter")
|
return nil, errors.New("string.filter requires a pattern parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
patternString, ok := pattern.(string)
|
patternString, ok := pattern.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("http.request.filter pattern must be a string")
|
return nil, errors.New("string.filter pattern must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
patternRegexp, err := regexp.Compile(patternString)
|
patternRegexp, err := regexp.Compile(patternString)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
@@ -17,7 +17,7 @@ func (se *StringSplit) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
payloadString, ok := payload.(string)
|
payloadString, ok := payload.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("string.split only accepts a string")
|
return nil, errors.New("string.split only accepts a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadParts := strings.Split(payloadString, se.Separator)
|
payloadParts := strings.Split(payloadString, se.Separator)
|
||||||
@@ -38,13 +38,13 @@ func init() {
|
|||||||
separator, ok := params["separator"]
|
separator, ok := params["separator"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("string.split requires a separator")
|
return nil, errors.New("string.split requires a separator")
|
||||||
}
|
}
|
||||||
|
|
||||||
separatorString, ok := separator.(string)
|
separatorString, ok := separator.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("string.split separator must be a string")
|
return nil, errors.New("string.split separator must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &StringSplit{config: config, Separator: separatorString}, nil
|
return &StringSplit{config: config, Separator: separatorString}, nil
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
@@ -16,7 +16,7 @@ func (up *UintParse) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
payloadString, ok := payload.(string)
|
payloadString, ok := payload.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("uint.parse processor only accepts a string")
|
return nil, errors.New("uint.parse processor only accepts a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(jwetzell): make base and bitSize configurable
|
// TODO(jwetzell): make base and bitSize configurable
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package showbridge
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -45,7 +46,7 @@ func NewRouter(ctx context.Context, config config.Config) (*Router, []module.Mod
|
|||||||
moduleErrors = append(moduleErrors, module.ModuleError{
|
moduleErrors = append(moduleErrors, module.ModuleError{
|
||||||
Index: moduleIndex,
|
Index: moduleIndex,
|
||||||
Config: moduleDecl,
|
Config: moduleDecl,
|
||||||
Error: fmt.Errorf("module type not defined"),
|
Error: errors.New("module type not defined"),
|
||||||
})
|
})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -60,7 +61,7 @@ func NewRouter(ctx context.Context, config config.Config) (*Router, []module.Mod
|
|||||||
moduleErrors = append(moduleErrors, module.ModuleError{
|
moduleErrors = append(moduleErrors, module.ModuleError{
|
||||||
Index: moduleIndex,
|
Index: moduleIndex,
|
||||||
Config: moduleDecl,
|
Config: moduleDecl,
|
||||||
Error: fmt.Errorf("duplicate module id"),
|
Error: errors.New("duplicate module id"),
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user