mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 13:25:40 +00:00
rename processing to processor
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
package config
|
||||
|
||||
import "github.com/jwetzell/showbridge-go/internal/processing"
|
||||
|
||||
type Config struct {
|
||||
Modules []ModuleConfig `json:"modules"`
|
||||
Routes []RouteConfig `json:"routes"`
|
||||
@@ -14,7 +12,12 @@ type ModuleConfig struct {
|
||||
}
|
||||
|
||||
type RouteConfig struct {
|
||||
Input string `json:"input"`
|
||||
Processors []processing.ProcessorConfig `json:"processors"`
|
||||
Output string `json:"output"`
|
||||
Input string `json:"input"`
|
||||
Processors []ProcessorConfig `json:"processors"`
|
||||
Output string `json:"output"`
|
||||
}
|
||||
|
||||
type ProcessorConfig struct {
|
||||
Type string `json:"type"`
|
||||
Params map[string]any `json:"params"`
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processing"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
"github.com/jwetzell/showbridge-go/internal/route"
|
||||
)
|
||||
|
||||
@@ -105,7 +105,7 @@ func (mc *MQTTClient) Run() error {
|
||||
}
|
||||
|
||||
func (mc *MQTTClient) Output(payload any) error {
|
||||
payloadMessage, ok := payload.(processing.MQTTMessage)
|
||||
payloadMessage, ok := payload.(processor.MQTTMessage)
|
||||
|
||||
if !ok {
|
||||
return fmt.Errorf("net.mqtt.client is only able to output a MQTTMessage")
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"log/slog"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processing"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
"github.com/jwetzell/showbridge-go/internal/route"
|
||||
"github.com/nats-io/nats.go"
|
||||
)
|
||||
@@ -93,7 +93,7 @@ func (nc *NATSClient) Run() error {
|
||||
|
||||
func (nc *NATSClient) Output(payload any) error {
|
||||
|
||||
payloadMessage, ok := payload.(processing.NATSMessage)
|
||||
payloadMessage, ok := payload.(processor.NATSMessage)
|
||||
|
||||
if !ok {
|
||||
return fmt.Errorf("net.nats.client is only able to output NATSMessage")
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type DebugLog struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
}
|
||||
|
||||
func (dl *DebugLog) Process(ctx context.Context, payload any) (any, error) {
|
||||
@@ -22,7 +24,7 @@ func (dl *DebugLog) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "debug.log",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
return &DebugLog{config: config}, nil
|
||||
},
|
||||
})
|
||||
@@ -1,13 +1,15 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type FloatParse struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
}
|
||||
|
||||
func (fp *FloatParse) Process(ctx context.Context, payload any) (any, error) {
|
||||
@@ -32,7 +34,7 @@ func (fp *FloatParse) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "float.parse",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
return &FloatParse{config: config}, nil
|
||||
},
|
||||
})
|
||||
@@ -1,4 +1,4 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -8,10 +8,11 @@ import (
|
||||
"text/template"
|
||||
|
||||
freeD "github.com/jwetzell/free-d-go"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type FreeDCreate struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
Id *template.Template
|
||||
Pan *template.Template
|
||||
Tilt *template.Template
|
||||
@@ -178,7 +179,7 @@ func (fc *FreeDCreate) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "freed.create",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
|
||||
// TODO(jwetzell): make some params optional
|
||||
params := config.Params
|
||||
@@ -1,4 +1,4 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -6,10 +6,11 @@ import (
|
||||
"log/slog"
|
||||
|
||||
freeD "github.com/jwetzell/free-d-go"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type FreeDDecode struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
}
|
||||
|
||||
func (fdd *FreeDDecode) Process(ctx context.Context, payload any) (any, error) {
|
||||
@@ -33,7 +34,7 @@ func (fdd *FreeDDecode) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "freed.decode",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
return &FreeDDecode{config: config}, nil
|
||||
},
|
||||
})
|
||||
@@ -1,14 +1,15 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
freeD "github.com/jwetzell/free-d-go"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type FreeDEncode struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
}
|
||||
|
||||
func (fde *FreeDEncode) Process(ctx context.Context, payload any) (any, error) {
|
||||
@@ -29,7 +30,7 @@ func (fde *FreeDEncode) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "freed.encode",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
return &FreeDEncode{config: config}, nil
|
||||
},
|
||||
})
|
||||
@@ -1,4 +1,4 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -6,10 +6,12 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"text/template"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type HTTPRequestCreate struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
Method string
|
||||
URL *template.Template
|
||||
}
|
||||
@@ -42,7 +44,7 @@ func (hre *HTTPRequestCreate) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "http.request.create",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
params := config.Params
|
||||
|
||||
method, ok := params["method"]
|
||||
@@ -1,14 +1,16 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type HTTPRequestEncode struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
}
|
||||
|
||||
func (hre *HTTPRequestEncode) Process(ctx context.Context, payload any) (any, error) {
|
||||
@@ -33,7 +35,7 @@ func (hre *HTTPRequestEncode) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "http.request.encode",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
return &HTTPRequestEncode{config: config}, nil
|
||||
},
|
||||
})
|
||||
@@ -1,14 +1,16 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"regexp"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type HTTPRequestFilter struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
Path *regexp.Regexp
|
||||
Method string
|
||||
}
|
||||
@@ -41,7 +43,7 @@ func (hrf *HTTPRequestFilter) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "http.request.filter",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
params := config.Params
|
||||
path, ok := params["path"]
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type HTTPResponseEncode struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
}
|
||||
|
||||
func (hre *HTTPResponseEncode) Process(ctx context.Context, payload any) (any, error) {
|
||||
@@ -34,7 +36,7 @@ func (hre *HTTPResponseEncode) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "http.response.encode",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
return &HTTPResponseEncode{config: config}, nil
|
||||
},
|
||||
})
|
||||
@@ -1,13 +1,15 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type IntParse struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
}
|
||||
|
||||
func (ip *IntParse) Process(ctx context.Context, payload any) (any, error) {
|
||||
@@ -32,7 +34,7 @@ func (ip *IntParse) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "int.parse",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
return &IntParse{config: config}, nil
|
||||
},
|
||||
})
|
||||
@@ -1,16 +1,17 @@
|
||||
//go:build cgo
|
||||
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"gitlab.com/gomidi/midi/v2"
|
||||
)
|
||||
|
||||
type MIDIMessageDecode struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
}
|
||||
|
||||
func (mmd *MIDIMessageDecode) Process(ctx context.Context, payload any) (any, error) {
|
||||
@@ -32,7 +33,7 @@ func (mmd *MIDIMessageDecode) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "midi.message.decode",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
return &MIDIMessageDecode{config: config}, nil
|
||||
},
|
||||
})
|
||||
@@ -1,16 +1,17 @@
|
||||
//go:build cgo
|
||||
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"gitlab.com/gomidi/midi/v2"
|
||||
)
|
||||
|
||||
type MIDIMessageEncode struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
}
|
||||
|
||||
func (mme *MIDIMessageEncode) Process(ctx context.Context, payload any) (any, error) {
|
||||
@@ -30,7 +31,7 @@ func (mme *MIDIMessageEncode) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "midi.message.encode",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
return &MIDIMessageEncode{config: config}, nil
|
||||
},
|
||||
})
|
||||
@@ -1,8 +1,10 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type MQTTMessage struct {
|
||||
@@ -13,7 +15,7 @@ type MQTTMessage struct {
|
||||
}
|
||||
|
||||
type MQTTMessageCreate struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
Topic string
|
||||
QoS byte
|
||||
Retained bool
|
||||
@@ -39,7 +41,7 @@ func (mmc *MQTTMessageCreate) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "mqtt.message.create",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
params := config.Params
|
||||
topic, ok := params["topic"]
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type MQTTMessageEncode struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
}
|
||||
|
||||
func (mme *MQTTMessageEncode) Process(ctx context.Context, payload any) (any, error) {
|
||||
@@ -28,7 +29,7 @@ func (mme *MQTTMessageEncode) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "mqtt.message.encode",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
return &MQTTMessageEncode{config: config}, nil
|
||||
},
|
||||
})
|
||||
@@ -1,10 +1,12 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"text/template"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type NATSMessage struct {
|
||||
@@ -13,7 +15,7 @@ type NATSMessage struct {
|
||||
}
|
||||
|
||||
type NATSMessageCreate struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
Subject string
|
||||
Payload *template.Template
|
||||
}
|
||||
@@ -44,7 +46,7 @@ func (nmc *NATSMessageCreate) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "nats.message.create",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
params := config.Params
|
||||
// TODO(jwetzell): support template for subject
|
||||
subject, ok := params["subject"]
|
||||
@@ -1,14 +1,15 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/nats-io/nats.go"
|
||||
)
|
||||
|
||||
type NATSMessageEncode struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
}
|
||||
|
||||
func (nme *NATSMessageEncode) Process(ctx context.Context, payload any) (any, error) {
|
||||
@@ -28,7 +29,7 @@ func (nme *NATSMessageEncode) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "nats.message.encode",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
return &NATSMessageEncode{config: config}, nil
|
||||
},
|
||||
})
|
||||
@@ -1,4 +1,4 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -9,10 +9,11 @@ import (
|
||||
"text/template"
|
||||
|
||||
"github.com/jwetzell/osc-go"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type OSCMessageCreate struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
Address *template.Template
|
||||
Args []*template.Template
|
||||
Types string
|
||||
@@ -76,7 +77,7 @@ func (o *OSCMessageCreate) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "osc.message.create",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
params := config.Params
|
||||
address, ok := params["address"]
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
osc "github.com/jwetzell/osc-go"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type OSCMessageDecode struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
}
|
||||
|
||||
func (o *OSCMessageDecode) Process(ctx context.Context, payload any) (any, error) {
|
||||
@@ -40,7 +41,7 @@ func (o *OSCMessageDecode) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "osc.message.decode",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
return &OSCMessageDecode{config: config}, nil
|
||||
},
|
||||
})
|
||||
@@ -1,14 +1,15 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
osc "github.com/jwetzell/osc-go"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type OSCMessageEncode struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
}
|
||||
|
||||
func (o *OSCMessageEncode) Process(ctx context.Context, payload any) (any, error) {
|
||||
@@ -29,7 +30,7 @@ func (o *OSCMessageEncode) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "osc.message.encode",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
return &OSCMessageEncode{config: config}, nil
|
||||
},
|
||||
})
|
||||
@@ -1,4 +1,4 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -7,10 +7,11 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/jwetzell/osc-go"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type OSCMessageFilter struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
Address *regexp.Regexp
|
||||
}
|
||||
|
||||
@@ -36,7 +37,7 @@ func (o *OSCMessageFilter) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "osc.message.filter",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
params := config.Params
|
||||
address, ok := params["address"]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -7,10 +7,11 @@ import (
|
||||
"text/template"
|
||||
|
||||
osc "github.com/jwetzell/osc-go"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type OSCMessageTransform struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
Address *template.Template
|
||||
}
|
||||
|
||||
@@ -51,7 +52,7 @@ func (o *OSCMessageTransform) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "osc.message.transform",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
params := config.Params
|
||||
address, ok := params["address"]
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type Processor interface {
|
||||
@@ -11,14 +13,9 @@ type Processor interface {
|
||||
Process(context.Context, any) (any, error)
|
||||
}
|
||||
|
||||
type ProcessorConfig struct {
|
||||
Type string `json:"type"`
|
||||
Params map[string]any `json:"params"`
|
||||
}
|
||||
|
||||
type ProcessorRegistration struct {
|
||||
Type string `json:"type"`
|
||||
New func(ProcessorConfig) (Processor, error)
|
||||
New func(config.ProcessorConfig) (Processor, error)
|
||||
}
|
||||
|
||||
func RegisterProcessor(processor ProcessorRegistration) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -6,11 +6,12 @@ import (
|
||||
|
||||
"github.com/expr-lang/expr"
|
||||
"github.com/expr-lang/expr/vm"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
// NOTE(jwetzell): see language definition https://expr-lang.org/docs/language-definition
|
||||
type ScriptExpr struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
Program *vm.Program
|
||||
}
|
||||
|
||||
@@ -31,7 +32,7 @@ func (se *ScriptExpr) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "script.expr",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
params := config.Params
|
||||
|
||||
expression, ok := params["expression"]
|
||||
@@ -1,15 +1,16 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"modernc.org/quickjs"
|
||||
)
|
||||
|
||||
type ScriptJS struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
Program string
|
||||
}
|
||||
|
||||
@@ -67,7 +68,7 @@ func (sj *ScriptJS) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "script.js",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
params := config.Params
|
||||
|
||||
program, ok := params["program"]
|
||||
@@ -1,14 +1,16 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"text/template"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type StringCreate struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
Template *template.Template
|
||||
}
|
||||
|
||||
@@ -32,7 +34,7 @@ func (sc *StringCreate) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "string.create",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
params := config.Params
|
||||
tmpl, ok := params["template"]
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type StringDecode struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
}
|
||||
|
||||
func (sd *StringDecode) Process(ctx context.Context, payload any) (any, error) {
|
||||
@@ -28,7 +30,7 @@ func (sd *StringDecode) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "string.decode",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
return &StringDecode{config: config}, nil
|
||||
},
|
||||
})
|
||||
@@ -1,15 +1,15 @@
|
||||
package processing_test
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/processing"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestGoodStringDecode(t *testing.T) {
|
||||
stringDecoder := processing.StringDecode{}
|
||||
stringDecoder := processor.StringDecode{}
|
||||
tests := []struct {
|
||||
processor processing.Processor
|
||||
processor processor.Processor
|
||||
name string
|
||||
payload any
|
||||
expected string
|
||||
@@ -1,12 +1,14 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type StringEncode struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
}
|
||||
|
||||
func (se *StringEncode) Process(ctx context.Context, payload any) (any, error) {
|
||||
@@ -28,7 +30,7 @@ func (se *StringEncode) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "string.encode",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
return &StringEncode{config: config}, nil
|
||||
},
|
||||
})
|
||||
@@ -1,16 +1,16 @@
|
||||
package processing_test
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/processing"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestGoodStringEncode(t *testing.T) {
|
||||
stringEncoder := processing.StringEncode{}
|
||||
stringEncoder := processor.StringEncode{}
|
||||
tests := []struct {
|
||||
processor processing.Processor
|
||||
processor processor.Processor
|
||||
name string
|
||||
payload any
|
||||
expected []byte
|
||||
@@ -1,13 +1,15 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type StringFilter struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
Pattern *regexp.Regexp
|
||||
}
|
||||
|
||||
@@ -32,7 +34,7 @@ func (se *StringFilter) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "string.filter",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
params := config.Params
|
||||
|
||||
pattern, ok := params["pattern"]
|
||||
@@ -1,13 +1,15 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type StringSplit struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
Separator string
|
||||
}
|
||||
|
||||
@@ -30,7 +32,7 @@ func (se *StringSplit) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "string.split",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
params := config.Params
|
||||
|
||||
separator, ok := params["separator"]
|
||||
@@ -1,13 +1,15 @@
|
||||
package processing
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
type UintParse struct {
|
||||
config ProcessorConfig
|
||||
config config.ProcessorConfig
|
||||
}
|
||||
|
||||
func (up *UintParse) Process(ctx context.Context, payload any) (any, error) {
|
||||
@@ -32,7 +34,7 @@ func (up *UintParse) Type() string {
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "uint.parse",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
return &UintParse{config: config}, nil
|
||||
},
|
||||
})
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processing"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
type RouteError struct {
|
||||
@@ -33,16 +33,16 @@ type Route interface {
|
||||
|
||||
type ProcessorRoute struct {
|
||||
input string
|
||||
processors []processing.Processor
|
||||
processors []processor.Processor
|
||||
output string
|
||||
}
|
||||
|
||||
func NewRoute(config config.RouteConfig) (Route, error) {
|
||||
processors := []processing.Processor{}
|
||||
processors := []processor.Processor{}
|
||||
|
||||
if len(config.Processors) > 0 {
|
||||
for _, processorDecl := range config.Processors {
|
||||
processorInfo, ok := processing.ProcessorRegistry[processorDecl.Type]
|
||||
processorInfo, ok := processor.ProcessorRegistry[processorDecl.Type]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("problem loading processor registration for processor type: %s", processorDecl.Type)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user