mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-30 06:45:30 +00:00
Compare commits
45 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e5e1ea9f63 | ||
|
|
1cdfe929b4 | ||
|
|
012c416432 | ||
|
|
0763b4d720 | ||
|
|
14f3ae74a7 | ||
|
|
c2b73ac710 | ||
|
|
57262c3377 | ||
|
|
1fb59cc947 | ||
|
|
2fbca6209e | ||
|
|
3fedb7ac92 | ||
|
|
3f4271b5ef | ||
|
|
1e3b2571fb | ||
|
|
4559c6efbd | ||
|
|
7e75fdb758 | ||
|
|
2127c6fd5b | ||
|
|
2a40fa561c | ||
|
|
1467d9de16 | ||
|
|
5fc7b7399f | ||
|
|
3d664fff67 | ||
|
|
9c03ad2c14 | ||
|
|
35262fd505 | ||
|
|
feccab91d5 | ||
|
|
b17e0489a5 | ||
|
|
97c1975c7f | ||
|
|
6336800641 | ||
|
|
d9ac6d1a85 | ||
|
|
be3b9e3d5a | ||
|
|
44cc2e322c | ||
|
|
5f9547fddb | ||
|
|
8d8c5d4073 | ||
|
|
6d382ecd20 | ||
|
|
f0aa5a9eb0 | ||
|
|
e84bd6ead4 | ||
|
|
3d54ac7a0d | ||
|
|
2eae266903 | ||
|
|
c7d407d507 | ||
|
|
2d74e14387 | ||
|
|
e2a0f4ef90 | ||
|
|
54307bc817 | ||
|
|
e95fb44064 | ||
|
|
36c0e9b23e | ||
|
|
b57faaccb9 | ||
|
|
814bb9c1dc | ||
|
|
6fa2c1a746 | ||
|
|
f273aedbc6 |
42
api.go
42
api.go
@@ -6,6 +6,7 @@ import (
|
|||||||
_ "embed"
|
_ "embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -14,12 +15,19 @@ import (
|
|||||||
"github.com/jwetzell/showbridge-go/internal/route"
|
"github.com/jwetzell/showbridge-go/internal/route"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed schema
|
||||||
|
var schema embed.FS
|
||||||
|
|
||||||
func (r *Router) startAPIServer(config config.ApiConfig) {
|
func (r *Router) startAPIServer(config config.ApiConfig) {
|
||||||
|
if !config.Enabled {
|
||||||
|
r.logger.Warn("API not enabled")
|
||||||
|
return
|
||||||
|
}
|
||||||
r.logger.Debug("starting API server", "port", config.Port)
|
r.logger.Debug("starting API server", "port", config.Port)
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("/ws", r.handleWebsocket)
|
mux.HandleFunc("/ws", r.handleWebsocket)
|
||||||
mux.HandleFunc("/health", r.handleHealthHTTP)
|
mux.HandleFunc("/health", r.handleHealthHTTP)
|
||||||
mux.HandleFunc("/schema/{schema}", r.handleSchemaHTTP)
|
mux.Handle("/schema/{schema}", HandleFS(schema))
|
||||||
mux.HandleFunc("/api/v1/config", r.handleConfigHTTP)
|
mux.HandleFunc("/api/v1/config", r.handleConfigHTTP)
|
||||||
|
|
||||||
r.apiServerMu.Lock()
|
r.apiServerMu.Lock()
|
||||||
@@ -36,6 +44,9 @@ func (r *Router) startAPIServer(config config.ApiConfig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Router) stopAPIServer() {
|
func (r *Router) stopAPIServer() {
|
||||||
|
if r.apiServer == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
r.logger.Debug("stopping API server")
|
r.logger.Debug("stopping API server")
|
||||||
r.apiServerMu.Lock()
|
r.apiServerMu.Lock()
|
||||||
defer r.apiServerMu.Unlock()
|
defer r.apiServerMu.Unlock()
|
||||||
@@ -78,6 +89,10 @@ func (r *Router) handleConfigHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Write(configJSON)
|
w.Write(configJSON)
|
||||||
case http.MethodPut:
|
case http.MethodPut:
|
||||||
|
if r.updatingConfig {
|
||||||
|
http.Error(w, "Config update in progress.", http.StatusConflict)
|
||||||
|
return
|
||||||
|
}
|
||||||
var newConfig config.Config
|
var newConfig config.Config
|
||||||
err := json.NewDecoder(req.Body).Decode(&newConfig)
|
err := json.NewDecoder(req.Body).Decode(&newConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -119,28 +134,11 @@ func (r *Router) handleConfigHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:embed schema
|
func HandleFS(fs fs.FS) http.HandlerFunc {
|
||||||
var schema embed.FS
|
handler := http.FileServerFS(fs)
|
||||||
|
return func(w http.ResponseWriter, req *http.Request) {
|
||||||
func (r *Router) handleSchemaHTTP(w http.ResponseWriter, req *http.Request) {
|
|
||||||
switch req.Method {
|
|
||||||
case http.MethodGet:
|
|
||||||
schemaName := req.PathValue("schema")
|
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
configSchema, err := schema.ReadFile(fmt.Sprintf("schema/%s.schema.json", schemaName))
|
handler.ServeHTTP(w, req)
|
||||||
if err != nil {
|
|
||||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
w.Write(configSchema)
|
|
||||||
case http.MethodOptions:
|
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
|
||||||
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
|
|
||||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
default:
|
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
|
||||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
api:
|
api:
|
||||||
|
enabled: true
|
||||||
port: 8080
|
port: 8080
|
||||||
modules:
|
modules:
|
||||||
- id: http
|
- id: http
|
||||||
|
|||||||
9
go.mod
9
go.mod
@@ -4,7 +4,7 @@ go 1.26.0
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/eclipse/paho.mqtt.golang v1.5.1
|
github.com/eclipse/paho.mqtt.golang v1.5.1
|
||||||
github.com/emiago/diago v0.27.0
|
github.com/emiago/diago v0.28.0
|
||||||
github.com/emiago/sipgo v1.2.1
|
github.com/emiago/sipgo v1.2.1
|
||||||
github.com/expr-lang/expr v1.17.8
|
github.com/expr-lang/expr v1.17.8
|
||||||
github.com/extism/go-sdk v1.7.1
|
github.com/extism/go-sdk v1.7.1
|
||||||
@@ -15,6 +15,7 @@ require (
|
|||||||
github.com/jwetzell/psn-go v0.3.0
|
github.com/jwetzell/psn-go v0.3.0
|
||||||
github.com/nats-io/nats-server/v2 v2.12.5
|
github.com/nats-io/nats-server/v2 v2.12.5
|
||||||
github.com/nats-io/nats.go v1.49.0
|
github.com/nats-io/nats.go v1.49.0
|
||||||
|
github.com/redis/go-redis/v9 v9.18.0
|
||||||
github.com/urfave/cli/v3 v3.7.0
|
github.com/urfave/cli/v3 v3.7.0
|
||||||
gitlab.com/gomidi/midi/v2 v2.3.23
|
gitlab.com/gomidi/midi/v2 v2.3.23
|
||||||
go.bug.st/serial v1.6.4
|
go.bug.st/serial v1.6.4
|
||||||
@@ -23,6 +24,7 @@ require (
|
|||||||
go.opentelemetry.io/otel/sdk v1.42.0
|
go.opentelemetry.io/otel/sdk v1.42.0
|
||||||
go.opentelemetry.io/otel/trace v1.42.0
|
go.opentelemetry.io/otel/trace v1.42.0
|
||||||
modernc.org/quickjs v0.17.1
|
modernc.org/quickjs v0.17.1
|
||||||
|
modernc.org/sqlite v1.47.0
|
||||||
sigs.k8s.io/yaml v1.6.0
|
sigs.k8s.io/yaml v1.6.0
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,6 +33,7 @@ require (
|
|||||||
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
|
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
github.com/creack/goselect v0.1.2 // indirect
|
github.com/creack/goselect v0.1.2 // indirect
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||||
github.com/dylibso/observe-sdk/go v0.0.0-20240819160327-2d926c5d788a // indirect
|
github.com/dylibso/observe-sdk/go v0.0.0-20240819160327-2d926c5d788a // indirect
|
||||||
github.com/emiago/dtls/v3 v3.0.0-20260122183559-8b8d23e359c0 // indirect
|
github.com/emiago/dtls/v3 v3.0.0-20260122183559-8b8d23e359c0 // indirect
|
||||||
@@ -68,9 +71,9 @@ require (
|
|||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.42.0 // indirect
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.42.0 // indirect
|
||||||
go.opentelemetry.io/otel/metric v1.42.0 // indirect
|
go.opentelemetry.io/otel/metric v1.42.0 // indirect
|
||||||
go.opentelemetry.io/proto/otlp v1.9.0 // indirect
|
go.opentelemetry.io/proto/otlp v1.9.0 // indirect
|
||||||
|
go.uber.org/atomic v1.11.0 // indirect
|
||||||
go.yaml.in/yaml/v2 v2.4.2 // indirect
|
go.yaml.in/yaml/v2 v2.4.2 // indirect
|
||||||
golang.org/x/crypto v0.48.0 // indirect
|
golang.org/x/crypto v0.48.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect
|
|
||||||
golang.org/x/net v0.51.0 // indirect
|
golang.org/x/net v0.51.0 // indirect
|
||||||
golang.org/x/sync v0.19.0 // indirect
|
golang.org/x/sync v0.19.0 // indirect
|
||||||
golang.org/x/sys v0.42.0 // indirect
|
golang.org/x/sys v0.42.0 // indirect
|
||||||
@@ -81,7 +84,7 @@ require (
|
|||||||
google.golang.org/grpc v1.79.2 // indirect
|
google.golang.org/grpc v1.79.2 // indirect
|
||||||
google.golang.org/protobuf v1.36.11 // indirect
|
google.golang.org/protobuf v1.36.11 // indirect
|
||||||
gopkg.in/hraban/opus.v2 v2.0.0-20230925203106-0188a62cb302 // indirect
|
gopkg.in/hraban/opus.v2 v2.0.0-20230925203106-0188a62cb302 // indirect
|
||||||
modernc.org/libc v1.67.1 // indirect
|
modernc.org/libc v1.70.0 // indirect
|
||||||
modernc.org/libquickjs v0.12.3 // indirect
|
modernc.org/libquickjs v0.12.3 // indirect
|
||||||
modernc.org/mathutil v1.7.1 // indirect
|
modernc.org/mathutil v1.7.1 // indirect
|
||||||
modernc.org/memory v1.11.0 // indirect
|
modernc.org/memory v1.11.0 // indirect
|
||||||
|
|||||||
48
go.sum
48
go.sum
@@ -1,5 +1,9 @@
|
|||||||
github.com/antithesishq/antithesis-sdk-go v0.6.0-default-no-op h1:kpBdlEPbRvff0mDD1gk7o9BhI16b9p5yYAXRlidpqJE=
|
github.com/antithesishq/antithesis-sdk-go v0.6.0-default-no-op h1:kpBdlEPbRvff0mDD1gk7o9BhI16b9p5yYAXRlidpqJE=
|
||||||
github.com/antithesishq/antithesis-sdk-go v0.6.0-default-no-op/go.mod h1:IUpT2DPAKh6i/YhSbt6Gl3v2yvUZjmKncl7U91fup7E=
|
github.com/antithesishq/antithesis-sdk-go v0.6.0-default-no-op/go.mod h1:IUpT2DPAKh6i/YhSbt6Gl3v2yvUZjmKncl7U91fup7E=
|
||||||
|
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||||
|
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
||||||
|
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
||||||
|
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
|
||||||
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
||||||
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
|
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||||
@@ -8,14 +12,16 @@ github.com/creack/goselect v0.1.2 h1:2DNy14+JPjRBgPzAd1thbQp4BSIihxcBf0IXhQXDRa0
|
|||||||
github.com/creack/goselect v0.1.2/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY=
|
github.com/creack/goselect v0.1.2/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||||
github.com/dylibso/observe-sdk/go v0.0.0-20240819160327-2d926c5d788a h1:UwSIFv5g5lIvbGgtf3tVwC7Ky9rmMFBp0RMs+6f6YqE=
|
github.com/dylibso/observe-sdk/go v0.0.0-20240819160327-2d926c5d788a h1:UwSIFv5g5lIvbGgtf3tVwC7Ky9rmMFBp0RMs+6f6YqE=
|
||||||
github.com/dylibso/observe-sdk/go v0.0.0-20240819160327-2d926c5d788a/go.mod h1:C8DzXehI4zAbrdlbtOByKX6pfivJTBiV9Jjqv56Yd9Q=
|
github.com/dylibso/observe-sdk/go v0.0.0-20240819160327-2d926c5d788a/go.mod h1:C8DzXehI4zAbrdlbtOByKX6pfivJTBiV9Jjqv56Yd9Q=
|
||||||
github.com/eclipse/paho.mqtt.golang v1.5.1 h1:/VSOv3oDLlpqR2Epjn1Q7b2bSTplJIeV2ISgCl2W7nE=
|
github.com/eclipse/paho.mqtt.golang v1.5.1 h1:/VSOv3oDLlpqR2Epjn1Q7b2bSTplJIeV2ISgCl2W7nE=
|
||||||
github.com/eclipse/paho.mqtt.golang v1.5.1/go.mod h1:1/yJCneuyOoCOzKSsOTUc0AJfpsItBGWvYpBLimhArU=
|
github.com/eclipse/paho.mqtt.golang v1.5.1/go.mod h1:1/yJCneuyOoCOzKSsOTUc0AJfpsItBGWvYpBLimhArU=
|
||||||
github.com/emiago/diago v0.27.0 h1:5SQBbcLR9ooxhSMlTkU9QSuDv/2nhMO9lxuWJTd/7rE=
|
github.com/emiago/diago v0.28.0 h1:VCiimhFYLoBTsxH6WrufLSt6tKWG8Fv7LfCkZHqct2E=
|
||||||
github.com/emiago/diago v0.27.0/go.mod h1:8hUxCDPJY2p32hh+4ed7vHW/3yTMmEa3BjNctUPeGD0=
|
github.com/emiago/diago v0.28.0/go.mod h1:eQT6j9co9PMQ/25aUiM2jpvwxxWFXLWi2w5R3lZNmKg=
|
||||||
github.com/emiago/dtls/v3 v3.0.0-20260122183559-8b8d23e359c0 h1:o4LxpUnZ1zxiQ+Qjc9kLwXcjz31NGAHmnZ7xoJto3VM=
|
github.com/emiago/dtls/v3 v3.0.0-20260122183559-8b8d23e359c0 h1:o4LxpUnZ1zxiQ+Qjc9kLwXcjz31NGAHmnZ7xoJto3VM=
|
||||||
github.com/emiago/dtls/v3 v3.0.0-20260122183559-8b8d23e359c0/go.mod h1:ydcZ977eS1I6uOWodzMuw30BwvNAzT9su/xcNYSJqjA=
|
github.com/emiago/dtls/v3 v3.0.0-20260122183559-8b8d23e359c0/go.mod h1:ydcZ977eS1I6uOWodzMuw30BwvNAzT9su/xcNYSJqjA=
|
||||||
github.com/emiago/sipgo v1.2.1 h1:5JTwogbe3yQFA3sjBVueN2Q4WTU350tGeBwPYT8HMv0=
|
github.com/emiago/sipgo v1.2.1 h1:5JTwogbe3yQFA3sjBVueN2Q4WTU350tGeBwPYT8HMv0=
|
||||||
@@ -45,6 +51,8 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
|||||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||||
github.com/google/go-tpm v0.9.8 h1:slArAR9Ft+1ybZu0lBwpSmpwhRXaa85hWtMinMyRAWo=
|
github.com/google/go-tpm v0.9.8 h1:slArAR9Ft+1ybZu0lBwpSmpwhRXaa85hWtMinMyRAWo=
|
||||||
github.com/google/go-tpm v0.9.8/go.mod h1:h9jEsEECg7gtLis0upRBQU+GhYVH6jMjrFxI8u6bVUY=
|
github.com/google/go-tpm v0.9.8/go.mod h1:h9jEsEECg7gtLis0upRBQU+GhYVH6jMjrFxI8u6bVUY=
|
||||||
|
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
|
||||||
|
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||||
@@ -67,6 +75,8 @@ github.com/jwetzell/psn-go v0.3.0 h1:WVpCEmExYE8a+I5hQak5jNJJp2x35VdGX/VuMUKPmhY
|
|||||||
github.com/jwetzell/psn-go v0.3.0/go.mod h1:bcEAeti4sQM375buujb3mIfmUstD4Aby18gq3ENb6+o=
|
github.com/jwetzell/psn-go v0.3.0/go.mod h1:bcEAeti4sQM375buujb3mIfmUstD4Aby18gq3ENb6+o=
|
||||||
github.com/klauspost/compress v1.18.4 h1:RPhnKRAQ4Fh8zU2FY/6ZFDwTVTxgJ/EMydqSTzE9a2c=
|
github.com/klauspost/compress v1.18.4 h1:RPhnKRAQ4Fh8zU2FY/6ZFDwTVTxgJ/EMydqSTzE9a2c=
|
||||||
github.com/klauspost/compress v1.18.4/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
|
github.com/klauspost/compress v1.18.4/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
|
||||||
|
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
|
||||||
|
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
@@ -103,6 +113,8 @@ github.com/pion/transport/v4 v4.0.1 h1:sdROELU6BZ63Ab7FrOLn13M6YdJLY20wldXW2Cu2k
|
|||||||
github.com/pion/transport/v4 v4.0.1/go.mod h1:nEuEA4AD5lPdcIegQDpVLgNoDGreqM/YqmEx3ovP4jM=
|
github.com/pion/transport/v4 v4.0.1/go.mod h1:nEuEA4AD5lPdcIegQDpVLgNoDGreqM/YqmEx3ovP4jM=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/redis/go-redis/v9 v9.18.0 h1:pMkxYPkEbMPwRdenAzUNyFNrDgHx9U+DrBabWNfSRQs=
|
||||||
|
github.com/redis/go-redis/v9 v9.18.0/go.mod h1:k3ufPphLU5YXwNTUcCRXGxUoF1fqxnhFQmscfkCoDA0=
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||||
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
|
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
|
||||||
@@ -117,6 +129,8 @@ github.com/urfave/cli/v3 v3.7.0 h1:AGSnbUyjtLiM+WJUb4dzXKldl/gL+F8OwmRDtVr6g2U=
|
|||||||
github.com/urfave/cli/v3 v3.7.0/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
|
github.com/urfave/cli/v3 v3.7.0/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
|
||||||
github.com/zaf/g711 v1.4.0 h1:XZYkjjiAg9QTBnHqEg37m2I9q3IIDv5JRYXs2N8ma7c=
|
github.com/zaf/g711 v1.4.0 h1:XZYkjjiAg9QTBnHqEg37m2I9q3IIDv5JRYXs2N8ma7c=
|
||||||
github.com/zaf/g711 v1.4.0/go.mod h1:eCDXt3dSp/kYYAoooba7ukD/Q75jvAaS4WOMr0l1Roo=
|
github.com/zaf/g711 v1.4.0/go.mod h1:eCDXt3dSp/kYYAoooba7ukD/Q75jvAaS4WOMr0l1Roo=
|
||||||
|
github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
|
||||||
|
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
|
||||||
gitlab.com/gomidi/midi/v2 v2.3.23 h1:P8NxV4EzV9c+BjpwTeB+G/qa+Xdq/UTazS2fKxY0O0g=
|
gitlab.com/gomidi/midi/v2 v2.3.23 h1:P8NxV4EzV9c+BjpwTeB+G/qa+Xdq/UTazS2fKxY0O0g=
|
||||||
gitlab.com/gomidi/midi/v2 v2.3.23/go.mod h1:jDpP4O4skYi+7iVwt6Zyp18bd2M4hkjtMuw2cmgKgfw=
|
gitlab.com/gomidi/midi/v2 v2.3.23/go.mod h1:jDpP4O4skYi+7iVwt6Zyp18bd2M4hkjtMuw2cmgKgfw=
|
||||||
go.bug.st/serial v1.6.4 h1:7FmqNPgVp3pu2Jz5PoPtbZ9jJO5gnEnZIvnI1lzve8A=
|
go.bug.st/serial v1.6.4 h1:7FmqNPgVp3pu2Jz5PoPtbZ9jJO5gnEnZIvnI1lzve8A=
|
||||||
@@ -139,6 +153,8 @@ go.opentelemetry.io/otel/trace v1.42.0 h1:OUCgIPt+mzOnaUTpOQcBiM/PLQ/Op7oq6g4Len
|
|||||||
go.opentelemetry.io/otel/trace v1.42.0/go.mod h1:f3K9S+IFqnumBkKhRJMeaZeNk9epyhnCmQh/EysQCdc=
|
go.opentelemetry.io/otel/trace v1.42.0/go.mod h1:f3K9S+IFqnumBkKhRJMeaZeNk9epyhnCmQh/EysQCdc=
|
||||||
go.opentelemetry.io/proto/otlp v1.9.0 h1:l706jCMITVouPOqEnii2fIAuO3IVGBRPV5ICjceRb/A=
|
go.opentelemetry.io/proto/otlp v1.9.0 h1:l706jCMITVouPOqEnii2fIAuO3IVGBRPV5ICjceRb/A=
|
||||||
go.opentelemetry.io/proto/otlp v1.9.0/go.mod h1:xE+Cx5E/eEHw+ISFkwPLwCZefwVjY+pqKg1qcK03+/4=
|
go.opentelemetry.io/proto/otlp v1.9.0/go.mod h1:xE+Cx5E/eEHw+ISFkwPLwCZefwVjY+pqKg1qcK03+/4=
|
||||||
|
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
|
||||||
|
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
|
||||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||||
go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
|
go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
|
||||||
@@ -147,10 +163,8 @@ go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
|
|||||||
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||||
golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts=
|
golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts=
|
||||||
golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos=
|
golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos=
|
||||||
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 h1:mgKeJMpvi0yx/sU5GsxQ7p6s2wtOnGAHZWCHUM4KGzY=
|
golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8=
|
||||||
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70=
|
golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w=
|
||||||
golang.org/x/mod v0.32.0 h1:9F4d3PHLljb6x//jOyokMv3eX+YDeepZSEo3mFJy93c=
|
|
||||||
golang.org/x/mod v0.32.0/go.mod h1:SgipZ/3h2Ci89DlEtEXWUk/HteuRin+HHhN+WbNhguU=
|
|
||||||
golang.org/x/net v0.51.0 h1:94R/GTO7mt3/4wIKpcR5gkGmRLOuE/2hNGeWq/GBIFo=
|
golang.org/x/net v0.51.0 h1:94R/GTO7mt3/4wIKpcR5gkGmRLOuE/2hNGeWq/GBIFo=
|
||||||
golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y=
|
golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y=
|
||||||
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
|
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
|
||||||
@@ -163,8 +177,8 @@ golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
|
|||||||
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
|
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
|
||||||
golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U=
|
golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U=
|
||||||
golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno=
|
golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno=
|
||||||
golang.org/x/tools v0.41.0 h1:a9b8iMweWG+S0OBnlU36rzLp20z1Rp10w+IY2czHTQc=
|
golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k=
|
||||||
golang.org/x/tools v0.41.0/go.mod h1:XSY6eDqxVNiYgezAVqqCeihT4j1U2CCsqvH3WhQpnlg=
|
golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0=
|
||||||
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
|
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
|
||||||
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
|
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20260209200024-4cfbd4190f57 h1:JLQynH/LBHfCTSbDWl+py8C+Rg/k1OVH3xfcaiANuF0=
|
google.golang.org/genproto/googleapis/api v0.0.0-20260209200024-4cfbd4190f57 h1:JLQynH/LBHfCTSbDWl+py8C+Rg/k1OVH3xfcaiANuF0=
|
||||||
@@ -186,18 +200,18 @@ gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
|
|||||||
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
|
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
|
||||||
modernc.org/cc/v4 v4.27.1 h1:9W30zRlYrefrDV2JE2O8VDtJ1yPGownxciz5rrbQZis=
|
modernc.org/cc/v4 v4.27.1 h1:9W30zRlYrefrDV2JE2O8VDtJ1yPGownxciz5rrbQZis=
|
||||||
modernc.org/cc/v4 v4.27.1/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0=
|
modernc.org/cc/v4 v4.27.1/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0=
|
||||||
modernc.org/ccgo/v4 v4.30.1 h1:4r4U1J6Fhj98NKfSjnPUN7Ze2c6MnAdL0hWw6+LrJpc=
|
modernc.org/ccgo/v4 v4.32.0 h1:hjG66bI/kqIPX1b2yT6fr/jt+QedtP2fqojG2VrFuVw=
|
||||||
modernc.org/ccgo/v4 v4.30.1/go.mod h1:bIOeI1JL54Utlxn+LwrFyjCx2n2RDiYEaJVSrgdrRfM=
|
modernc.org/ccgo/v4 v4.32.0/go.mod h1:6F08EBCx5uQc38kMGl+0Nm0oWczoo1c7cgpzEry7Uc0=
|
||||||
modernc.org/fileutil v1.3.40 h1:ZGMswMNc9JOCrcrakF1HrvmergNLAmxOPjizirpfqBA=
|
modernc.org/fileutil v1.4.0 h1:j6ZzNTftVS054gi281TyLjHPp6CPHr2KCxEXjEbD6SM=
|
||||||
modernc.org/fileutil v1.3.40/go.mod h1:HxmghZSZVAz/LXcMNwZPA/DRrQZEVP9VX0V4LQGQFOc=
|
modernc.org/fileutil v1.4.0/go.mod h1:EqdKFDxiByqxLk8ozOxObDSfcVOv/54xDs/DUHdvCUU=
|
||||||
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
|
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
|
||||||
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
|
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
|
||||||
modernc.org/gc/v3 v3.1.1 h1:k8T3gkXWY9sEiytKhcgyiZ2L0DTyCQ/nvX+LoCljoRE=
|
modernc.org/gc/v3 v3.1.2 h1:ZtDCnhonXSZexk/AYsegNRV1lJGgaNZJuKjJSWKyEqo=
|
||||||
modernc.org/gc/v3 v3.1.1/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY=
|
modernc.org/gc/v3 v3.1.2/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY=
|
||||||
modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks=
|
modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks=
|
||||||
modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
|
modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
|
||||||
modernc.org/libc v1.67.1 h1:bFaqOaa5/zbWYJo8aW0tXPX21hXsngG2M7mckCnFSVk=
|
modernc.org/libc v1.70.0 h1:U58NawXqXbgpZ/dcdS9kMshu08aiA6b7gusEusqzNkw=
|
||||||
modernc.org/libc v1.67.1/go.mod h1:QvvnnJ5P7aitu0ReNpVIEyesuhmDLQ8kaEoyMjIFZJA=
|
modernc.org/libc v1.70.0/go.mod h1:OVmxFGP1CI/Z4L3E0Q3Mf1PDE0BucwMkcXjjLntvHJo=
|
||||||
modernc.org/libquickjs v0.12.3 h1:2IU9B6njBmce2PuYttJDkXeoLRV9WnvgP+eU5HAC8YI=
|
modernc.org/libquickjs v0.12.3 h1:2IU9B6njBmce2PuYttJDkXeoLRV9WnvgP+eU5HAC8YI=
|
||||||
modernc.org/libquickjs v0.12.3/go.mod h1:iCsgVxnHTX3i0YPxxHBmJk0GLA5sVUHXWI/090UXgeE=
|
modernc.org/libquickjs v0.12.3/go.mod h1:iCsgVxnHTX3i0YPxxHBmJk0GLA5sVUHXWI/090UXgeE=
|
||||||
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
|
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
|
||||||
@@ -210,6 +224,8 @@ modernc.org/quickjs v0.17.1 h1:CbYnbTf7ksZk9YZ1rRM2Ab1Zfi+X6s50kXiOhpd2NIg=
|
|||||||
modernc.org/quickjs v0.17.1/go.mod h1:hATT7DIJc33I5Q/Fjffhm0tpUHNSqdKHma/ossibTA0=
|
modernc.org/quickjs v0.17.1/go.mod h1:hATT7DIJc33I5Q/Fjffhm0tpUHNSqdKHma/ossibTA0=
|
||||||
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
|
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
|
||||||
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
|
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
|
||||||
|
modernc.org/sqlite v1.47.0 h1:R1XyaNpoW4Et9yly+I2EeX7pBza/w+pmYee/0HJDyKk=
|
||||||
|
modernc.org/sqlite v1.47.0/go.mod h1:hWjRO6Tj/5Ik8ieqxQybiEOUXy0NJFNp2tpvVpKlvig=
|
||||||
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
|
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
|
||||||
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
|
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
|
||||||
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
||||||
|
|||||||
26
internal/common/module.go
Normal file
26
internal/common/module.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Module interface {
|
||||||
|
Id() string
|
||||||
|
Type() string
|
||||||
|
Start(context.Context) error
|
||||||
|
Stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
type OutputModule interface {
|
||||||
|
Output(context.Context, any) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type KeyValueModule interface {
|
||||||
|
Get(key string) (any, error)
|
||||||
|
Set(key string, value any) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type DatabaseModule interface {
|
||||||
|
Database() *sql.DB
|
||||||
|
}
|
||||||
40
internal/common/payload.go
Normal file
40
internal/common/payload.go
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
)
|
||||||
|
|
||||||
|
type WrappedPayload struct {
|
||||||
|
Payload any
|
||||||
|
Modules map[string]Module
|
||||||
|
Sender any
|
||||||
|
Source string
|
||||||
|
End bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetWrappedPayload(ctx context.Context, payload any) WrappedPayload {
|
||||||
|
wrappedPayload := WrappedPayload{
|
||||||
|
Payload: payload,
|
||||||
|
End: false,
|
||||||
|
}
|
||||||
|
modules := ctx.Value(ModulesContextKey)
|
||||||
|
if modules != nil {
|
||||||
|
moduleMap, ok := modules.(map[string]Module)
|
||||||
|
if ok {
|
||||||
|
wrappedPayload.Modules = moduleMap
|
||||||
|
} else {
|
||||||
|
wrappedPayload.Modules = make(map[string]Module)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sender := ctx.Value(SenderContextKey)
|
||||||
|
if sender != nil {
|
||||||
|
wrappedPayload.Sender = sender
|
||||||
|
}
|
||||||
|
|
||||||
|
source := ctx.Value(SourceContextKey)
|
||||||
|
if source != nil {
|
||||||
|
wrappedPayload.Source = source.(string)
|
||||||
|
}
|
||||||
|
return wrappedPayload
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ApiConfig struct {
|
type ApiConfig struct {
|
||||||
|
Enabled bool `json:"enabled"`
|
||||||
Port int `json:"port"`
|
Port int `json:"port"`
|
||||||
}
|
}
|
||||||
type ModuleConfig struct {
|
type ModuleConfig struct {
|
||||||
|
|||||||
81
internal/module/db-sqlite.go
Normal file
81
internal/module/db-sqlite.go
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
package module
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
|
||||||
|
_ "modernc.org/sqlite"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DbSqlite struct {
|
||||||
|
config config.ModuleConfig
|
||||||
|
Dsn string
|
||||||
|
ctx context.Context
|
||||||
|
router common.RouteIO
|
||||||
|
db *sql.DB
|
||||||
|
logger *slog.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterModule(ModuleRegistration{
|
||||||
|
Type: "db.sqlite",
|
||||||
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
|
params := config.Params
|
||||||
|
|
||||||
|
dsnString, err := params.GetString("dsn")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("db.sqlite dsn error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &DbSqlite{Dsn: dsnString, config: config, logger: CreateLogger(config)}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *DbSqlite) Id() string {
|
||||||
|
return t.config.Id
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *DbSqlite) Type() string {
|
||||||
|
return t.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *DbSqlite) Start(ctx context.Context) error {
|
||||||
|
t.logger.Debug("running")
|
||||||
|
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return errors.New("db.sqlite unable to get router from context")
|
||||||
|
}
|
||||||
|
t.router = router
|
||||||
|
t.ctx = ctx
|
||||||
|
|
||||||
|
db, err := sql.Open("sqlite", t.Dsn)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("db.sqlite error opening database: %w", err)
|
||||||
|
}
|
||||||
|
t.db = db
|
||||||
|
defer t.db.Close()
|
||||||
|
<-ctx.Done()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *DbSqlite) Output(ctx context.Context, payload any) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *DbSqlite) Stop() {
|
||||||
|
if t.db != nil {
|
||||||
|
t.db.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *DbSqlite) Database() *sql.DB {
|
||||||
|
return t.db
|
||||||
|
}
|
||||||
@@ -56,7 +56,7 @@ func (hsrw *HTTPServerResponseWriter) Write(data []byte) (int, error) {
|
|||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "http.server",
|
Type: "http.server",
|
||||||
New: func(config config.ModuleConfig) (Module, error) {
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
portNum, err := params.GetInt("port")
|
portNum, err := params.GetInt("port")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -205,7 +205,3 @@ func (hs *HTTPServer) Output(ctx context.Context, payload any) error {
|
|||||||
func (hs *HTTPServer) Stop() {
|
func (hs *HTTPServer) Stop() {
|
||||||
hs.cancel()
|
hs.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hs *HTTPServer) Get(key string) (any, error) {
|
|
||||||
return nil, errors.New("http.server does not support Get")
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ type MIDIInput struct {
|
|||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "midi.input",
|
Type: "midi.input",
|
||||||
New: func(config config.ModuleConfig) (Module, error) {
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
portString, err := params.GetString("port")
|
portString, err := params.GetString("port")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -82,19 +82,6 @@ func (mi *MIDIInput) Start(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mi *MIDIInput) Output(ctx context.Context, payload any) error {
|
|
||||||
return errors.New("midi.input output is not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mi *MIDIInput) Stop() {
|
func (mi *MIDIInput) Stop() {
|
||||||
mi.cancel()
|
mi.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mi *MIDIInput) Get(key string) (any, error) {
|
|
||||||
switch key {
|
|
||||||
case "port":
|
|
||||||
return mi.Port, nil
|
|
||||||
default:
|
|
||||||
return nil, errors.New("midi.input key not found")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ type MIDIOutput struct {
|
|||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "midi.output",
|
Type: "midi.output",
|
||||||
New: func(config config.ModuleConfig) (Module, error) {
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
|
|
||||||
portString, err := params.GetString("port")
|
portString, err := params.GetString("port")
|
||||||
@@ -87,7 +87,7 @@ func (mo *MIDIOutput) Output(ctx context.Context, payload any) error {
|
|||||||
payloadMessage, ok := common.GetAnyAs[midi.Message](payload)
|
payloadMessage, ok := common.GetAnyAs[midi.Message](payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("midi.output can only ouptut midi.Message")
|
return errors.New("midi.output can only output midi.Message")
|
||||||
}
|
}
|
||||||
|
|
||||||
return mo.SendFunc(payloadMessage)
|
return mo.SendFunc(payloadMessage)
|
||||||
@@ -96,12 +96,3 @@ func (mo *MIDIOutput) Output(ctx context.Context, payload any) error {
|
|||||||
func (mo *MIDIOutput) Stop() {
|
func (mo *MIDIOutput) Stop() {
|
||||||
mo.cancel()
|
mo.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mo *MIDIOutput) Get(key string) (any, error) {
|
|
||||||
switch key {
|
|
||||||
case "port":
|
|
||||||
return mo.Port, nil
|
|
||||||
default:
|
|
||||||
return nil, errors.New("midi.output key not found")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package module
|
package module
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,18 +15,9 @@ type ModuleError struct {
|
|||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Module interface {
|
|
||||||
Id() string
|
|
||||||
Type() string
|
|
||||||
Start(context.Context) error
|
|
||||||
Stop()
|
|
||||||
Output(context.Context, any) error
|
|
||||||
Get(key string) (any, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type ModuleRegistration struct {
|
type ModuleRegistration struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
New func(config.ModuleConfig) (Module, error)
|
New func(config.ModuleConfig) (common.Module, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterModule(mod ModuleRegistration) {
|
func RegisterModule(mod ModuleRegistration) {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ type MQTTClient struct {
|
|||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "mqtt.client",
|
Type: "mqtt.client",
|
||||||
New: func(config config.ModuleConfig) (Module, error) {
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
brokerString, err := params.GetString("broker")
|
brokerString, err := params.GetString("broker")
|
||||||
|
|
||||||
@@ -125,7 +125,3 @@ func (mc *MQTTClient) Output(ctx context.Context, payload any) error {
|
|||||||
func (mc *MQTTClient) Stop() {
|
func (mc *MQTTClient) Stop() {
|
||||||
mc.cancel()
|
mc.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mc *MQTTClient) Get(key string) (any, error) {
|
|
||||||
return nil, errors.New("mqtt.client does not support Get")
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ type NATSClient struct {
|
|||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "nats.client",
|
Type: "nats.client",
|
||||||
New: func(config config.ModuleConfig) (Module, error) {
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
urlString, err := params.GetString("url")
|
urlString, err := params.GetString("url")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -116,7 +116,3 @@ func (nc *NATSClient) Output(ctx context.Context, payload any) error {
|
|||||||
func (nc *NATSClient) Stop() {
|
func (nc *NATSClient) Stop() {
|
||||||
nc.cancel()
|
nc.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nc *NATSClient) Get(key string) (any, error) {
|
|
||||||
return nil, errors.New("nats.client does not support Get")
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ type NATSServer struct {
|
|||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "nats.server",
|
Type: "nats.server",
|
||||||
New: func(moduleConfig config.ModuleConfig) (Module, error) {
|
New: func(moduleConfig config.ModuleConfig) (common.Module, error) {
|
||||||
params := moduleConfig.Params
|
params := moduleConfig.Params
|
||||||
portNum, err := params.GetInt("port")
|
portNum, err := params.GetInt("port")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -102,17 +102,9 @@ func (ns *NATSServer) Start(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ns *NATSServer) Output(ctx context.Context, payload any) error {
|
|
||||||
return errors.New("nats.server does not support output")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ns *NATSServer) Stop() {
|
func (ns *NATSServer) Stop() {
|
||||||
ns.cancel()
|
ns.cancel()
|
||||||
if ns.server != nil {
|
if ns.server != nil {
|
||||||
ns.server.Shutdown()
|
ns.server.Shutdown()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ns *NATSServer) Get(key string) (any, error) {
|
|
||||||
return nil, errors.New("nats.server does not support Get")
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package module
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
@@ -26,7 +25,7 @@ type PSNClient struct {
|
|||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "psn.client",
|
Type: "psn.client",
|
||||||
New: func(config config.ModuleConfig) (Module, error) {
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
|
|
||||||
return &PSNClient{config: config, decoder: psn.NewDecoder(), logger: CreateLogger(config)}, nil
|
return &PSNClient{config: config, decoder: psn.NewDecoder(), logger: CreateLogger(config)}, nil
|
||||||
},
|
},
|
||||||
@@ -105,21 +104,6 @@ func (pc *PSNClient) Start(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *PSNClient) Output(ctx context.Context, payload any) error {
|
|
||||||
return fmt.Errorf("psn.client output is not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pc *PSNClient) Stop() {
|
func (pc *PSNClient) Stop() {
|
||||||
pc.cancel()
|
pc.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *PSNClient) Get(key string) (any, error) {
|
|
||||||
switch key {
|
|
||||||
case "trackers":
|
|
||||||
return pc.decoder.Trackers, nil
|
|
||||||
case "name":
|
|
||||||
return pc.decoder.SystemName, nil
|
|
||||||
default:
|
|
||||||
return nil, errors.New("psn.client key not found")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
108
internal/module/redis-client.go
Normal file
108
internal/module/redis-client.go
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
package module
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RedisClient struct {
|
||||||
|
config config.ModuleConfig
|
||||||
|
ctx context.Context
|
||||||
|
router common.RouteIO
|
||||||
|
Host string
|
||||||
|
Port uint16
|
||||||
|
client *redis.Client
|
||||||
|
logger *slog.Logger
|
||||||
|
cancel context.CancelFunc
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterModule(ModuleRegistration{
|
||||||
|
Type: "redis.client",
|
||||||
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
|
params := config.Params
|
||||||
|
hostString, err := params.GetString("host")
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("redis.client host error: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
portInt, err := params.GetInt("port")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("redis.client port error: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return &RedisClient{config: config, Host: hostString, Port: uint16(portInt), logger: CreateLogger(config)}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc *RedisClient) Id() string {
|
||||||
|
return rc.config.Id
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc *RedisClient) Type() string {
|
||||||
|
return rc.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc *RedisClient) Start(ctx context.Context) error {
|
||||||
|
rc.logger.Debug("running")
|
||||||
|
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return errors.New("redis.client unable to get router from context")
|
||||||
|
}
|
||||||
|
|
||||||
|
rc.router = router
|
||||||
|
moduleContext, cancel := context.WithCancel(ctx)
|
||||||
|
rc.ctx = moduleContext
|
||||||
|
rc.cancel = cancel
|
||||||
|
|
||||||
|
client := redis.NewClient(&redis.Options{
|
||||||
|
Addr: fmt.Sprintf("%s:%d", rc.Host, rc.Port),
|
||||||
|
Password: "",
|
||||||
|
DB: 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
rc.client = client
|
||||||
|
|
||||||
|
defer client.Close()
|
||||||
|
|
||||||
|
<-rc.ctx.Done()
|
||||||
|
rc.logger.Debug("done")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc *RedisClient) Output(ctx context.Context, payload any) error {
|
||||||
|
|
||||||
|
return errors.ErrUnsupported
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc *RedisClient) Stop() {
|
||||||
|
rc.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc *RedisClient) Get(key string) (any, error) {
|
||||||
|
if rc.client != nil {
|
||||||
|
val, err := rc.client.Get(rc.ctx, key).Result()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
return nil, errors.New("redis.client not setup")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc *RedisClient) Set(key string, value any) error {
|
||||||
|
if rc.client != nil {
|
||||||
|
status := rc.client.Set(rc.ctx, key, value, 0)
|
||||||
|
return status.Err()
|
||||||
|
}
|
||||||
|
return errors.New("redis.client not setup")
|
||||||
|
}
|
||||||
@@ -30,7 +30,7 @@ type SerialClient struct {
|
|||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "serial.client",
|
Type: "serial.client",
|
||||||
New: func(config config.ModuleConfig) (Module, error) {
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
portString, err := params.GetString("port")
|
portString, err := params.GetString("port")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -156,10 +156,10 @@ func (sc *SerialClient) Start(ctx context.Context) error {
|
|||||||
|
|
||||||
func (sc *SerialClient) Output(ctx context.Context, payload any) error {
|
func (sc *SerialClient) Output(ctx context.Context, payload any) error {
|
||||||
|
|
||||||
payloadBytes, ok := common.GetAnyAs[[]byte](payload)
|
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("serial.client can only ouptut bytes")
|
return errors.New("serial.client can only output bytes")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := sc.port.Write(sc.Framer.Encode(payloadBytes))
|
_, err := sc.port.Write(sc.Framer.Encode(payloadBytes))
|
||||||
@@ -169,12 +169,3 @@ func (sc *SerialClient) Output(ctx context.Context, payload any) error {
|
|||||||
func (sc *SerialClient) Stop() {
|
func (sc *SerialClient) Stop() {
|
||||||
sc.cancel()
|
sc.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sc *SerialClient) Get(key string) (any, error) {
|
|
||||||
switch key {
|
|
||||||
case "port":
|
|
||||||
return sc.Port, nil
|
|
||||||
default:
|
|
||||||
return nil, errors.New("serial.client key not found")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ type sipCallContextKey string
|
|||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "sip.call.server",
|
Type: "sip.call.server",
|
||||||
New: func(moduleConfig config.ModuleConfig) (Module, error) {
|
New: func(moduleConfig config.ModuleConfig) (common.Module, error) {
|
||||||
params := moduleConfig.Params
|
params := moduleConfig.Params
|
||||||
portNum, err := params.GetInt("port")
|
portNum, err := params.GetInt("port")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -221,7 +221,3 @@ func (scs *SIPCallServer) Output(ctx context.Context, payload any) error {
|
|||||||
func (scs *SIPCallServer) Stop() {
|
func (scs *SIPCallServer) Stop() {
|
||||||
scs.cancel()
|
scs.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (scs *SIPCallServer) Get(key string) (any, error) {
|
|
||||||
return nil, errors.New("sip.call.server does not support Get")
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ type SIPDTMFCall struct {
|
|||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "sip.dtmf.server",
|
Type: "sip.dtmf.server",
|
||||||
New: func(moduleConfig config.ModuleConfig) (Module, error) {
|
New: func(moduleConfig config.ModuleConfig) (common.Module, error) {
|
||||||
params := moduleConfig.Params
|
params := moduleConfig.Params
|
||||||
|
|
||||||
portNum, err := params.GetInt("port")
|
portNum, err := params.GetInt("port")
|
||||||
@@ -249,7 +249,3 @@ func (sds *SIPDTMFServer) Output(ctx context.Context, payload any) error {
|
|||||||
func (sds *SIPDTMFServer) Stop() {
|
func (sds *SIPDTMFServer) Stop() {
|
||||||
sds.cancel()
|
sds.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sds *SIPDTMFServer) Get(key string) (any, error) {
|
|
||||||
return nil, errors.New("sip.dtmf.server does not support Get")
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ type TCPClient struct {
|
|||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "net.tcp.client",
|
Type: "net.tcp.client",
|
||||||
New: func(config config.ModuleConfig) (Module, error) {
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
hostString, err := params.GetString("host")
|
hostString, err := params.GetString("host")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -152,7 +152,7 @@ func (tc *TCPClient) Output(ctx context.Context, payload any) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
payloadBytes, ok := common.GetAnyAs[[]byte](payload)
|
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("net.tcp.client is only able to output bytes")
|
return errors.New("net.tcp.client is only able to output bytes")
|
||||||
}
|
}
|
||||||
@@ -163,20 +163,3 @@ func (tc *TCPClient) Output(ctx context.Context, payload any) error {
|
|||||||
func (tc *TCPClient) Stop() {
|
func (tc *TCPClient) Stop() {
|
||||||
tc.cancel()
|
tc.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tc *TCPClient) Get(key string) (any, error) {
|
|
||||||
switch key {
|
|
||||||
case "host":
|
|
||||||
host, err := tc.config.Params.GetString("host")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("net.tcp.client host error: %w", err)
|
|
||||||
}
|
|
||||||
return host, nil
|
|
||||||
case "ip":
|
|
||||||
return tc.Addr.IP.String(), nil
|
|
||||||
case "port":
|
|
||||||
return tc.Addr.Port, nil
|
|
||||||
default:
|
|
||||||
return nil, errors.New("net.tcp.client key not found")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ type TCPServer struct {
|
|||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "net.tcp.server",
|
Type: "net.tcp.server",
|
||||||
New: func(moduleConfig config.ModuleConfig) (Module, error) {
|
New: func(moduleConfig config.ModuleConfig) (common.Module, error) {
|
||||||
params := moduleConfig.Params
|
params := moduleConfig.Params
|
||||||
portNum, err := params.GetInt("port")
|
portNum, err := params.GetInt("port")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -206,7 +206,7 @@ AcceptLoop:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TCPServer) Output(ctx context.Context, payload any) error {
|
func (ts *TCPServer) Output(ctx context.Context, payload any) error {
|
||||||
payloadBytes, ok := common.GetAnyAs[[]byte](payload)
|
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("net.tcp.server is only able to output bytes")
|
return errors.New("net.tcp.server is only able to output bytes")
|
||||||
@@ -232,14 +232,3 @@ func (ts *TCPServer) Stop() {
|
|||||||
ts.cancel()
|
ts.cancel()
|
||||||
ts.wg.Wait()
|
ts.wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TCPServer) Get(key string) (any, error) {
|
|
||||||
switch key {
|
|
||||||
case "ip":
|
|
||||||
return ts.Addr.IP.String(), nil
|
|
||||||
case "port":
|
|
||||||
return ts.Addr.Port, nil
|
|
||||||
default:
|
|
||||||
return nil, errors.New("net.tcp.server key not found")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/module"
|
"github.com/jwetzell/showbridge-go/internal/module"
|
||||||
)
|
)
|
||||||
@@ -11,10 +12,6 @@ import (
|
|||||||
type TestModule struct {
|
type TestModule struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *TestModule) Output(ctx context.Context, payload any) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *TestModule) Start(ctx context.Context) error {
|
func (m *TestModule) Start(ctx context.Context) error {
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
return nil
|
return nil
|
||||||
@@ -30,10 +27,6 @@ func (m *TestModule) Id() string {
|
|||||||
return "test"
|
return "test"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *TestModule) Get(key string) (any, error) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestModuleBadRegistrationNoType(t *testing.T) {
|
func TestModuleBadRegistrationNoType(t *testing.T) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r == nil {
|
if r := recover(); r == nil {
|
||||||
@@ -43,7 +36,7 @@ func TestModuleBadRegistrationNoType(t *testing.T) {
|
|||||||
|
|
||||||
module.RegisterModule(module.ModuleRegistration{
|
module.RegisterModule(module.ModuleRegistration{
|
||||||
Type: "",
|
Type: "",
|
||||||
New: func(config config.ModuleConfig) (module.Module, error) {
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
return &TestModule{}, nil
|
return &TestModule{}, nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -71,14 +64,14 @@ func TestModuleBadRegistrationExistingType(t *testing.T) {
|
|||||||
|
|
||||||
module.RegisterModule(module.ModuleRegistration{
|
module.RegisterModule(module.ModuleRegistration{
|
||||||
Type: "module.test",
|
Type: "module.test",
|
||||||
New: func(config config.ModuleConfig) (module.Module, error) {
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
return &TestModule{}, nil
|
return &TestModule{}, nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
module.RegisterModule(module.ModuleRegistration{
|
module.RegisterModule(module.ModuleRegistration{
|
||||||
Type: "module.test",
|
Type: "module.test",
|
||||||
New: func(config config.ModuleConfig) (module.Module, error) {
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
return &TestModule{}, nil
|
return &TestModule{}, nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ type TimeInterval struct {
|
|||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "time.interval",
|
Type: "time.interval",
|
||||||
New: func(config config.ModuleConfig) (Module, error) {
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
|
|
||||||
durationInt, err := params.GetInt("duration")
|
durationInt, err := params.GetInt("duration")
|
||||||
@@ -74,20 +74,6 @@ func (i *TimeInterval) Start(ctx context.Context) error {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *TimeInterval) Output(ctx context.Context, payload any) error {
|
|
||||||
i.ticker.Reset(time.Millisecond * time.Duration(i.Duration))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *TimeInterval) Stop() {
|
func (i *TimeInterval) Stop() {
|
||||||
i.cancel()
|
i.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *TimeInterval) Get(key string) (any, error) {
|
|
||||||
switch key {
|
|
||||||
case "duration":
|
|
||||||
return i.Duration, nil
|
|
||||||
default:
|
|
||||||
return nil, errors.New("time.interval key not found")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ type TimeTimer struct {
|
|||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "time.timer",
|
Type: "time.timer",
|
||||||
New: func(config config.ModuleConfig) (Module, error) {
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
|
|
||||||
durationNum, err := params.GetInt("duration")
|
durationNum, err := params.GetInt("duration")
|
||||||
@@ -73,20 +73,6 @@ func (t *TimeTimer) Start(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TimeTimer) Output(ctx context.Context, payload any) error {
|
|
||||||
t.timer.Reset(time.Millisecond * time.Duration(t.Duration))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *TimeTimer) Stop() {
|
func (t *TimeTimer) Stop() {
|
||||||
t.cancel()
|
t.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TimeTimer) Get(key string) (any, error) {
|
|
||||||
switch key {
|
|
||||||
case "duration":
|
|
||||||
return t.Duration, nil
|
|
||||||
default:
|
|
||||||
return nil, errors.New("time.timer key not found")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ type UDPClient struct {
|
|||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "net.udp.client",
|
Type: "net.udp.client",
|
||||||
New: func(config config.ModuleConfig) (Module, error) {
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
hostString, err := params.GetString("host")
|
hostString, err := params.GetString("host")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -87,7 +87,7 @@ func (uc *UDPClient) Start(ctx context.Context) error {
|
|||||||
|
|
||||||
func (uc *UDPClient) Output(ctx context.Context, payload any) error {
|
func (uc *UDPClient) Output(ctx context.Context, payload any) error {
|
||||||
|
|
||||||
payloadBytes, ok := common.GetAnyAs[[]byte](payload)
|
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("net.udp.client is only able to output bytes")
|
return errors.New("net.udp.client is only able to output bytes")
|
||||||
}
|
}
|
||||||
@@ -106,20 +106,3 @@ func (uc *UDPClient) Output(ctx context.Context, payload any) error {
|
|||||||
func (uc *UDPClient) Stop() {
|
func (uc *UDPClient) Stop() {
|
||||||
uc.cancel()
|
uc.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (uc *UDPClient) Get(key string) (any, error) {
|
|
||||||
switch key {
|
|
||||||
case "host":
|
|
||||||
host, err := uc.config.Params.GetString("host")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("net.udp.client host error: %w", err)
|
|
||||||
}
|
|
||||||
return host, nil
|
|
||||||
case "ip":
|
|
||||||
return uc.Addr.IP.String(), nil
|
|
||||||
case "port":
|
|
||||||
return uc.Addr.Port, nil
|
|
||||||
default:
|
|
||||||
return nil, errors.New("net.udp.client key not found")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ type UDPMulticast struct {
|
|||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "net.udp.multicast",
|
Type: "net.udp.multicast",
|
||||||
New: func(moduleConfig config.ModuleConfig) (Module, error) {
|
New: func(moduleConfig config.ModuleConfig) (common.Module, error) {
|
||||||
params := moduleConfig.Params
|
params := moduleConfig.Params
|
||||||
ipString, err := params.GetString("ip")
|
ipString, err := params.GetString("ip")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -108,7 +108,7 @@ func (um *UDPMulticast) Start(ctx context.Context) error {
|
|||||||
|
|
||||||
func (um *UDPMulticast) Output(ctx context.Context, payload any) error {
|
func (um *UDPMulticast) Output(ctx context.Context, payload any) error {
|
||||||
|
|
||||||
payloadBytes, ok := common.GetAnyAs[[]byte](payload)
|
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("net.udp.multicast can only output bytes")
|
return errors.New("net.udp.multicast can only output bytes")
|
||||||
}
|
}
|
||||||
@@ -124,14 +124,3 @@ func (um *UDPMulticast) Output(ctx context.Context, payload any) error {
|
|||||||
func (um *UDPMulticast) Stop() {
|
func (um *UDPMulticast) Stop() {
|
||||||
um.cancel()
|
um.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (um *UDPMulticast) Get(key string) (any, error) {
|
|
||||||
switch key {
|
|
||||||
case "ip":
|
|
||||||
return um.Addr.IP.String(), nil
|
|
||||||
case "port":
|
|
||||||
return um.Addr.Port, nil
|
|
||||||
default:
|
|
||||||
return nil, errors.New("net.udp.multicast key not found")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ type UDPServer struct {
|
|||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "net.udp.server",
|
Type: "net.udp.server",
|
||||||
New: func(moduleConfig config.ModuleConfig) (Module, error) {
|
New: func(moduleConfig config.ModuleConfig) (common.Module, error) {
|
||||||
params := moduleConfig.Params
|
params := moduleConfig.Params
|
||||||
portNum, err := params.GetInt("port")
|
portNum, err := params.GetInt("port")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -123,14 +123,3 @@ func (us *UDPServer) Output(ctx context.Context, payload any) error {
|
|||||||
func (us *UDPServer) Stop() {
|
func (us *UDPServer) Stop() {
|
||||||
us.cancel()
|
us.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us *UDPServer) Get(key string) (any, error) {
|
|
||||||
switch key {
|
|
||||||
case "ip":
|
|
||||||
return us.Addr.IP.String(), nil
|
|
||||||
case "port":
|
|
||||||
return us.Addr.Port, nil
|
|
||||||
default:
|
|
||||||
return nil, errors.New("net.udp.server key not found")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -13,20 +13,25 @@ type ArtNetPacketDecode struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (apd *ArtNetPacketDecode) Process(ctx context.Context, payload any) (any, error) {
|
func (apd *ArtNetPacketDecode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
payloadBytes, ok := common.GetAnyAs[[]byte](payload)
|
payload := wrappedPayload.Payload
|
||||||
|
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("artnet.packet.decode processor only accepts a []byte")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("artnet.packet.decode processor only accepts a []byte")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadMessage, err := artnet.Decode(payloadBytes)
|
payloadMessage, err := artnet.Decode(payloadBytes)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return payloadMessage, nil
|
wrappedPayload.Payload = payloadMessage
|
||||||
|
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (apd *ArtNetPacketDecode) Type() string {
|
func (apd *ArtNetPacketDecode) Type() string {
|
||||||
|
|||||||
@@ -13,19 +13,24 @@ type ArtNetPacketEncode struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ape *ArtNetPacketEncode) Process(ctx context.Context, payload any) (any, error) {
|
func (ape *ArtNetPacketEncode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
payload := wrappedPayload.Payload
|
||||||
payloadPacket, ok := common.GetAnyAs[artnet.ArtNetPacket](payload)
|
payloadPacket, ok := common.GetAnyAs[artnet.ArtNetPacket](payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("artnet.packet.encode processor only accepts an ArtNetPacket")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("artnet.packet.encode processor only accepts an ArtNetPacket")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadBytes, err := payloadPacket.MarshalBinary()
|
payloadBytes, err := payloadPacket.MarshalBinary()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return payloadBytes, nil
|
wrappedPayload.Payload = payloadBytes
|
||||||
|
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ape *ArtNetPacketEncode) Type() string {
|
func (ape *ArtNetPacketEncode) Type() string {
|
||||||
|
|||||||
130
internal/processor/db-query.go
Normal file
130
internal/processor/db-query.go
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
package processor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DbQuery struct {
|
||||||
|
config config.ProcessorConfig
|
||||||
|
ModuleId string
|
||||||
|
Query *template.Template
|
||||||
|
logger *slog.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dq *DbQuery) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
if wrappedPayload.Modules == nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("db.query wrapped payload has no modules")
|
||||||
|
}
|
||||||
|
|
||||||
|
module, ok := wrappedPayload.Modules[dq.ModuleId]
|
||||||
|
if !ok {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("db.query unable to find module with id: %s", dq.ModuleId)
|
||||||
|
}
|
||||||
|
|
||||||
|
dbModule, ok := module.(common.DatabaseModule)
|
||||||
|
if !ok {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("db.query module with id %s is not a DatabaseModule", dq.ModuleId)
|
||||||
|
}
|
||||||
|
|
||||||
|
db := dbModule.Database()
|
||||||
|
if db == nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("db.query module with id %s returned nil database", dq.ModuleId)
|
||||||
|
}
|
||||||
|
|
||||||
|
var queryBuffer bytes.Buffer
|
||||||
|
err := dq.Query.Execute(&queryBuffer, wrappedPayload)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// support proper parameterized queries
|
||||||
|
rows, err := db.QueryContext(ctx, queryBuffer.String())
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("db.query error executing query: %w", err)
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
|
columns, err := rows.Columns()
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("db.query error getting columns: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
results := make([]map[string]any, 0)
|
||||||
|
|
||||||
|
for rows.Next() {
|
||||||
|
columnValues := make([]interface{}, len(columns))
|
||||||
|
|
||||||
|
for i := range columnValues {
|
||||||
|
columnValues[i] = new(interface{})
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := rows.Scan(columnValues...); err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("db.query error scanning row: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
rowMap := make(map[string]any)
|
||||||
|
for i, colName := range columns {
|
||||||
|
value := *columnValues[i].(*interface{})
|
||||||
|
rowMap[colName] = value
|
||||||
|
}
|
||||||
|
results = append(results, rowMap)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(results) == 0 {
|
||||||
|
wrappedPayload.Payload = nil
|
||||||
|
return wrappedPayload, nil
|
||||||
|
} else if len(results) == 1 {
|
||||||
|
wrappedPayload.Payload = results[0]
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
wrappedPayload.Payload = results
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dq *DbQuery) Type() string {
|
||||||
|
return dq.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterProcessor(ProcessorRegistration{
|
||||||
|
Type: "db.query",
|
||||||
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
|
|
||||||
|
params := config.Params
|
||||||
|
|
||||||
|
moduleIdString, err := params.GetString("module")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("db.query module error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
queryString, err := params.GetString("query")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("db.query query error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
queryTemplate, err := template.New("query").Parse(queryString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &DbQuery{config: config, ModuleId: moduleIdString, Query: queryTemplate, logger: slog.Default().With("component", "processor", "type", config.Type)}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -13,11 +14,12 @@ type DebugLog struct {
|
|||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dl *DebugLog) Process(ctx context.Context, payload any) (any, error) {
|
func (dl *DebugLog) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
payload := wrappedPayload.Payload
|
||||||
payloadString := fmt.Sprintf("%+v", payload)
|
payloadString := fmt.Sprintf("%+v", payload)
|
||||||
payloadType := fmt.Sprintf("%T", payload)
|
payloadType := fmt.Sprintf("%T", payload)
|
||||||
dl.logger.Debug("", "payload", payloadString, "payloadType", payloadType)
|
dl.logger.Debug("", "payload", payloadString, "payloadType", payloadType)
|
||||||
return payload, nil
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dl *DebugLog) Type() string {
|
func (dl *DebugLog) Type() string {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/expr-lang/expr"
|
"github.com/expr-lang/expr"
|
||||||
"github.com/expr-lang/expr/vm"
|
"github.com/expr-lang/expr/vm"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,24 +16,29 @@ type FilterExpr struct {
|
|||||||
Program *vm.Program
|
Program *vm.Program
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fe *FilterExpr) Process(ctx context.Context, payload any) (any, error) {
|
func (fe *FilterExpr) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
|
||||||
exprEnv := GetEnvData(ctx, payload)
|
exprEnv := wrappedPayload
|
||||||
|
|
||||||
output, err := expr.Run(fe.Program, exprEnv)
|
output, err := expr.Run(fe.Program, exprEnv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
outputBool, ok := output.(bool)
|
outputBool, ok := output.(bool)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("filter.expr expression did not return a boolean")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("filter.expr expression did not return a boolean")
|
||||||
}
|
}
|
||||||
if !outputBool {
|
if !outputBool {
|
||||||
return nil, nil
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return payload, nil
|
wrappedPayload.Payload = exprEnv.Payload
|
||||||
|
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fe *FilterExpr) Type() string {
|
func (fe *FilterExpr) Type() string {
|
||||||
|
|||||||
@@ -15,18 +15,22 @@ type FilterRegex struct {
|
|||||||
Pattern *regexp.Regexp
|
Pattern *regexp.Regexp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fr *FilterRegex) Process(ctx context.Context, payload any) (any, error) {
|
func (fr *FilterRegex) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
payload := wrappedPayload.Payload
|
||||||
payloadString, ok := common.GetAnyAs[string](payload)
|
payloadString, ok := common.GetAnyAs[string](payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("filter.regex processor only accepts a string")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("filter.regex processor only accepts a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !fr.Pattern.MatchString(payloadString) {
|
if !fr.Pattern.MatchString(payloadString) {
|
||||||
return nil, nil
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return payloadString, nil
|
wrappedPayload.Payload = payloadString
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fr *FilterRegex) Type() string {
|
func (fr *FilterRegex) Type() string {
|
||||||
|
|||||||
@@ -15,18 +15,22 @@ type FloatParse struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fp *FloatParse) Process(ctx context.Context, payload any) (any, error) {
|
func (fp *FloatParse) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
payload := wrappedPayload.Payload
|
||||||
payloadString, ok := common.GetAnyAs[string](payload)
|
payloadString, ok := common.GetAnyAs[string](payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("float.parse processor only accepts a string")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("float.parse processor only accepts a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadFloat, err := strconv.ParseFloat(payloadString, fp.BitSize)
|
payloadFloat, err := strconv.ParseFloat(payloadString, fp.BitSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
return payloadFloat, nil
|
wrappedPayload.Payload = payloadFloat
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fp *FloatParse) Type() string {
|
func (fp *FloatParse) Type() string {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math/rand/v2"
|
"math/rand/v2"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,16 +17,19 @@ type FloatRandom struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fr *FloatRandom) Process(ctx context.Context, payload any) (any, error) {
|
func (fr *FloatRandom) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
if fr.BitSize == 32 {
|
if fr.BitSize == 32 {
|
||||||
payloadFloat := rand.Float32()*(float32(fr.Max)-float32(fr.Min)) + float32(fr.Min)
|
payloadFloat := rand.Float32()*(float32(fr.Max)-float32(fr.Min)) + float32(fr.Min)
|
||||||
return payloadFloat, nil
|
wrappedPayload.Payload = payloadFloat
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
if fr.BitSize == 64 {
|
if fr.BitSize == 64 {
|
||||||
payloadFloat := rand.Float64()*(fr.Max-fr.Min) + fr.Min
|
payloadFloat := rand.Float64()*(fr.Max-fr.Min) + fr.Min
|
||||||
return payloadFloat, nil
|
wrappedPayload.Payload = payloadFloat
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
return nil, errors.New("float.random bitSize error: must be 32 or 64")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("float.random bitSize error: must be 32 or 64")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fr *FloatRandom) Type() string {
|
func (fr *FloatRandom) Type() string {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
freeD "github.com/jwetzell/free-d-go"
|
freeD "github.com/jwetzell/free-d-go"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -24,15 +25,16 @@ type FreeDCreate struct {
|
|||||||
Focus *template.Template
|
Focus *template.Template
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fc *FreeDCreate) Process(ctx context.Context, payload any) (any, error) {
|
func (fc *FreeDCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
|
||||||
templateData := GetTemplateData(ctx, payload)
|
templateData := wrappedPayload
|
||||||
|
|
||||||
var idBuffer bytes.Buffer
|
var idBuffer bytes.Buffer
|
||||||
err := fc.Id.Execute(&idBuffer, templateData)
|
err := fc.Id.Execute(&idBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
idString := idBuffer.String()
|
idString := idBuffer.String()
|
||||||
@@ -40,14 +42,16 @@ func (fc *FreeDCreate) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
idNum, err := strconv.ParseUint(idString, 10, 8)
|
idNum, err := strconv.ParseUint(idString, 10, 8)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var panBuffer bytes.Buffer
|
var panBuffer bytes.Buffer
|
||||||
err = fc.Pan.Execute(&panBuffer, templateData)
|
err = fc.Pan.Execute(&panBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
panString := panBuffer.String()
|
panString := panBuffer.String()
|
||||||
@@ -55,14 +59,16 @@ func (fc *FreeDCreate) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
panNum, err := strconv.ParseFloat(panString, 32)
|
panNum, err := strconv.ParseFloat(panString, 32)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var tiltBuffer bytes.Buffer
|
var tiltBuffer bytes.Buffer
|
||||||
err = fc.Tilt.Execute(&tiltBuffer, templateData)
|
err = fc.Tilt.Execute(&tiltBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
tiltString := tiltBuffer.String()
|
tiltString := tiltBuffer.String()
|
||||||
@@ -70,14 +76,16 @@ func (fc *FreeDCreate) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
tiltNum, err := strconv.ParseFloat(tiltString, 32)
|
tiltNum, err := strconv.ParseFloat(tiltString, 32)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var rollBuffer bytes.Buffer
|
var rollBuffer bytes.Buffer
|
||||||
err = fc.Tilt.Execute(&rollBuffer, templateData)
|
err = fc.Roll.Execute(&rollBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
rollString := rollBuffer.String()
|
rollString := rollBuffer.String()
|
||||||
@@ -85,14 +93,16 @@ func (fc *FreeDCreate) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
rollNum, err := strconv.ParseFloat(rollString, 32)
|
rollNum, err := strconv.ParseFloat(rollString, 32)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var posXBuffer bytes.Buffer
|
var posXBuffer bytes.Buffer
|
||||||
err = fc.PosX.Execute(&posXBuffer, templateData)
|
err = fc.PosX.Execute(&posXBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
posXString := posXBuffer.String()
|
posXString := posXBuffer.String()
|
||||||
@@ -100,14 +110,16 @@ func (fc *FreeDCreate) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
posXNum, err := strconv.ParseFloat(posXString, 32)
|
posXNum, err := strconv.ParseFloat(posXString, 32)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var posYBuffer bytes.Buffer
|
var posYBuffer bytes.Buffer
|
||||||
err = fc.PosY.Execute(&posYBuffer, templateData)
|
err = fc.PosY.Execute(&posYBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
posYString := posYBuffer.String()
|
posYString := posYBuffer.String()
|
||||||
@@ -115,14 +127,16 @@ func (fc *FreeDCreate) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
posYNum, err := strconv.ParseFloat(posYString, 32)
|
posYNum, err := strconv.ParseFloat(posYString, 32)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var posZBuffer bytes.Buffer
|
var posZBuffer bytes.Buffer
|
||||||
err = fc.PosZ.Execute(&posZBuffer, templateData)
|
err = fc.PosZ.Execute(&posZBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
posZString := posZBuffer.String()
|
posZString := posZBuffer.String()
|
||||||
@@ -130,14 +144,16 @@ func (fc *FreeDCreate) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
posZNum, err := strconv.ParseFloat(posZString, 32)
|
posZNum, err := strconv.ParseFloat(posZString, 32)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var zoomBuffer bytes.Buffer
|
var zoomBuffer bytes.Buffer
|
||||||
err = fc.Zoom.Execute(&zoomBuffer, templateData)
|
err = fc.Zoom.Execute(&zoomBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
zoomString := zoomBuffer.String()
|
zoomString := zoomBuffer.String()
|
||||||
@@ -145,14 +161,16 @@ func (fc *FreeDCreate) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
zoomNum, err := strconv.ParseInt(zoomString, 10, 32)
|
zoomNum, err := strconv.ParseInt(zoomString, 10, 32)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var focusBuffer bytes.Buffer
|
var focusBuffer bytes.Buffer
|
||||||
err = fc.Focus.Execute(&focusBuffer, templateData)
|
err = fc.Focus.Execute(&focusBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
focusString := focusBuffer.String()
|
focusString := focusBuffer.String()
|
||||||
@@ -160,7 +178,8 @@ func (fc *FreeDCreate) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
focusNum, err := strconv.ParseInt(focusString, 10, 32)
|
focusNum, err := strconv.ParseInt(focusString, 10, 32)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadMessage := freeD.FreeDPosition{
|
payloadMessage := freeD.FreeDPosition{
|
||||||
@@ -175,7 +194,9 @@ func (fc *FreeDCreate) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
Focus: int32(focusNum),
|
Focus: int32(focusNum),
|
||||||
}
|
}
|
||||||
|
|
||||||
return payloadMessage, nil
|
wrappedPayload.Payload = payloadMessage
|
||||||
|
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fc *FreeDCreate) Type() string {
|
func (fc *FreeDCreate) Type() string {
|
||||||
@@ -207,6 +228,10 @@ func init() {
|
|||||||
|
|
||||||
panTemplate, err := template.New("pan").Parse(panString)
|
panTemplate, err := template.New("pan").Parse(panString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
tiltString, err := params.GetString("tilt")
|
tiltString, err := params.GetString("tilt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("freed.create tilt error: %w", err)
|
return nil, fmt.Errorf("freed.create tilt error: %w", err)
|
||||||
@@ -214,6 +239,10 @@ func init() {
|
|||||||
|
|
||||||
tiltTemplate, err := template.New("tilt").Parse(tiltString)
|
tiltTemplate, err := template.New("tilt").Parse(tiltString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
rollString, err := params.GetString("roll")
|
rollString, err := params.GetString("roll")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("freed.create roll error: %w", err)
|
return nil, fmt.Errorf("freed.create roll error: %w", err)
|
||||||
@@ -265,12 +294,19 @@ func init() {
|
|||||||
|
|
||||||
zoomTemplate, err := template.New("zoom").Parse(zoomString)
|
zoomTemplate, err := template.New("zoom").Parse(zoomString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
focusString, err := params.GetString("focus")
|
focusString, err := params.GetString("focus")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("freed.create focus error: %w", err)
|
return nil, fmt.Errorf("freed.create focus error: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
focusTemplate, err := template.New("focus").Parse(focusString)
|
focusTemplate, err := template.New("focus").Parse(focusString)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return &FreeDCreate{
|
return &FreeDCreate{
|
||||||
config: config,
|
config: config,
|
||||||
|
|||||||
@@ -13,18 +13,22 @@ type FreeDDecode struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fd *FreeDDecode) Process(ctx context.Context, payload any) (any, error) {
|
func (fd *FreeDDecode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
payloadBytes, ok := common.GetAnyAs[[]byte](payload)
|
payload := wrappedPayload.Payload
|
||||||
|
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("freed.decode processor only accepts a []byte")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("freed.decode processor only accepts a []byte")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadMessage, err := freeD.Decode(payloadBytes)
|
payloadMessage, err := freeD.Decode(payloadBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
return payloadMessage, nil
|
wrappedPayload.Payload = payloadMessage
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fd *FreeDDecode) Type() string {
|
func (fd *FreeDDecode) Type() string {
|
||||||
|
|||||||
@@ -13,15 +13,19 @@ type FreeDEncode struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fe *FreeDEncode) Process(ctx context.Context, payload any) (any, error) {
|
func (fe *FreeDEncode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
payload := wrappedPayload.Payload
|
||||||
payloadPosition, ok := common.GetAnyAs[freeD.FreeDPosition](payload)
|
payloadPosition, ok := common.GetAnyAs[freeD.FreeDPosition](payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("freed.decode processor only accepts a FreeDEncode")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("freed.encode processor only accepts a FreeDPosition")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadBytes := freeD.Encode(payloadPosition)
|
payloadBytes := freeD.Encode(payloadPosition)
|
||||||
return payloadBytes, nil
|
|
||||||
|
wrappedPayload.Payload = payloadBytes
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fe *FreeDEncode) Type() string {
|
func (fe *FreeDEncode) Type() string {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,15 +20,16 @@ type HTTPRequestDo struct {
|
|||||||
URL *template.Template
|
URL *template.Template
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hrd *HTTPRequestDo) Process(ctx context.Context, payload any) (any, error) {
|
func (hrd *HTTPRequestDo) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
|
||||||
templateData := GetTemplateData(ctx, payload)
|
templateData := wrappedPayload
|
||||||
|
|
||||||
var urlBuffer bytes.Buffer
|
var urlBuffer bytes.Buffer
|
||||||
err := hrd.URL.Execute(&urlBuffer, templateData)
|
err := hrd.URL.Execute(&urlBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
urlString := urlBuffer.String()
|
urlString := urlBuffer.String()
|
||||||
@@ -36,26 +38,30 @@ func (hrd *HTTPRequestDo) Process(ctx context.Context, payload any) (any, error)
|
|||||||
request, err := http.NewRequest(hrd.Method, urlString, bytes.NewBuffer([]byte{}))
|
request, err := http.NewRequest(hrd.Method, urlString, bytes.NewBuffer([]byte{}))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := hrd.client.Do(request)
|
response, err := hrd.client.Do(request)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := io.ReadAll(response.Body)
|
body, err := io.ReadAll(response.Body)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO(jwetzell): support headers, etc
|
//TODO(jwetzell): support headers, etc
|
||||||
return HTTPResponse{
|
wrappedPayload.Payload = HTTPResponse{
|
||||||
Status: response.StatusCode,
|
Status: response.StatusCode,
|
||||||
Body: body,
|
Body: body,
|
||||||
}, nil
|
}
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hrd *HTTPRequestDo) Type() string {
|
func (hrd *HTTPRequestDo) Type() string {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,20 +21,21 @@ type HTTPResponse struct {
|
|||||||
Body []byte
|
Body []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hrc *HTTPResponseCreate) Process(ctx context.Context, payload any) (any, error) {
|
func (hrc *HTTPResponseCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
templateData := GetTemplateData(ctx, payload)
|
templateData := wrappedPayload
|
||||||
|
|
||||||
var bodyBuffer bytes.Buffer
|
var bodyBuffer bytes.Buffer
|
||||||
err := hrc.BodyTmpl.Execute(&bodyBuffer, templateData)
|
err := hrc.BodyTmpl.Execute(&bodyBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
wrappedPayload.Payload = HTTPResponse{
|
||||||
return HTTPResponse{
|
|
||||||
Status: hrc.Status,
|
Status: hrc.Status,
|
||||||
Body: bodyBuffer.Bytes(),
|
Body: bodyBuffer.Bytes(),
|
||||||
}, nil
|
}
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hrc *HTTPResponseCreate) Type() string {
|
func (hrc *HTTPResponseCreate) Type() string {
|
||||||
|
|||||||
@@ -16,18 +16,22 @@ type IntParse struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ip *IntParse) Process(ctx context.Context, payload any) (any, error) {
|
func (ip *IntParse) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
payload := wrappedPayload.Payload
|
||||||
payloadString, ok := common.GetAnyAs[string](payload)
|
payloadString, ok := common.GetAnyAs[string](payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("int.parse processor only accepts a string")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("int.parse processor only accepts a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadInt, err := strconv.ParseInt(payloadString, ip.Base, ip.BitSize)
|
payloadInt, err := strconv.ParseInt(payloadString, ip.Base, ip.BitSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
return payloadInt, nil
|
wrappedPayload.Payload = payloadInt
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ip *IntParse) Type() string {
|
func (ip *IntParse) Type() string {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math/rand/v2"
|
"math/rand/v2"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,9 +16,10 @@ type IntRandom struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ir *IntRandom) Process(ctx context.Context, payload any) (any, error) {
|
func (ir *IntRandom) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
payloadInt := rand.IntN(ir.Max-ir.Min+1) + ir.Min
|
payloadInt := rand.IntN(ir.Max-ir.Min+1) + ir.Min
|
||||||
return payloadInt, nil
|
wrappedPayload.Payload = payloadInt
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ir *IntRandom) Type() string {
|
func (ir *IntRandom) Type() string {
|
||||||
|
|||||||
@@ -17,14 +17,17 @@ type IntScale struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ir *IntScale) Process(ctx context.Context, payload any) (any, error) {
|
func (ir *IntScale) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
payload := wrappedPayload.Payload
|
||||||
payloadInt, ok := common.GetAnyAs[int](payload)
|
payloadInt, ok := common.GetAnyAs[int](payload)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("int.scale can only process an int")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("int.scale can only process an int")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadInt = (payloadInt-ir.InMin)*(ir.OutMax-ir.OutMin)/(ir.InMax-ir.InMin) + ir.OutMin
|
payloadInt = (payloadInt-ir.InMin)*(ir.OutMax-ir.OutMin)/(ir.InMax-ir.InMin) + ir.OutMin
|
||||||
return payloadInt, nil
|
wrappedPayload.Payload = payloadInt
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ir *IntScale) Type() string {
|
func (ir *IntScale) Type() string {
|
||||||
|
|||||||
@@ -13,14 +13,16 @@ type JsonDecode struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (jd *JsonDecode) Process(ctx context.Context, payload any) (any, error) {
|
func (jd *JsonDecode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
payload := wrappedPayload.Payload
|
||||||
|
|
||||||
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
|
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
payloadString, ok := common.GetAnyAs[string](payload)
|
payloadString, ok := common.GetAnyAs[string](payload)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("json.decode can only process a string or []byte")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("json.decode can only process a string or []byte")
|
||||||
}
|
}
|
||||||
payloadBytes = []byte(payloadString)
|
payloadBytes = []byte(payloadString)
|
||||||
}
|
}
|
||||||
@@ -29,10 +31,12 @@ func (jd *JsonDecode) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
|
|
||||||
err := json.Unmarshal(payloadBytes, &payloadJson)
|
err := json.Unmarshal(payloadBytes, &payloadJson)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return payloadJson, nil
|
wrappedPayload.Payload = payloadJson
|
||||||
|
return wrappedPayload, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -12,20 +13,23 @@ type JsonEncode struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (je *JsonEncode) Process(ctx context.Context, payload any) (any, error) {
|
func (je *JsonEncode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
payload := wrappedPayload.Payload
|
||||||
var payloadBuffer bytes.Buffer
|
var payloadBuffer bytes.Buffer
|
||||||
|
|
||||||
err := json.NewEncoder(&payloadBuffer).Encode(payload)
|
err := json.NewEncoder(&payloadBuffer).Encode(payload)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadBytes := payloadBuffer.Bytes()
|
payloadBytes := payloadBuffer.Bytes()
|
||||||
|
|
||||||
payloadBytes = payloadBytes[0 : len(payloadBytes)-1]
|
payloadBytes = payloadBytes[0 : len(payloadBytes)-1]
|
||||||
|
|
||||||
return payloadBytes, nil
|
wrappedPayload.Payload = payloadBytes
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (je *JsonEncode) Type() string {
|
func (je *JsonEncode) Type() string {
|
||||||
|
|||||||
71
internal/processor/kv-get.go
Normal file
71
internal/processor/kv-get.go
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
package processor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type KVGet struct {
|
||||||
|
config config.ProcessorConfig
|
||||||
|
ModuleId string
|
||||||
|
Key string
|
||||||
|
logger *slog.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func (kvg *KVGet) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
if wrappedPayload.Modules == nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("kv.get wrapped payload has no modules")
|
||||||
|
}
|
||||||
|
|
||||||
|
module, ok := wrappedPayload.Modules[kvg.ModuleId]
|
||||||
|
if !ok {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("kv.get unable to find module with id: %s", kvg.ModuleId)
|
||||||
|
}
|
||||||
|
|
||||||
|
kvModule, ok := module.(common.KeyValueModule)
|
||||||
|
if !ok {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("kv.get module with id %s is not a KeyValueModule", kvg.ModuleId)
|
||||||
|
}
|
||||||
|
|
||||||
|
value, err := kvModule.Get(kvg.Key)
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("kv.get error getting key: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
wrappedPayload.Payload = value
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (kvg *KVGet) Type() string {
|
||||||
|
return kvg.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterProcessor(ProcessorRegistration{
|
||||||
|
Type: "kv.get",
|
||||||
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
|
|
||||||
|
params := config.Params
|
||||||
|
|
||||||
|
moduleIdString, err := params.GetString("module")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("kv.get module error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
keyString, err := params.GetString("key")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("kv.get key error: %w", err)
|
||||||
|
}
|
||||||
|
return &KVGet{config: config, ModuleId: moduleIdString, Key: keyString, logger: slog.Default().With("component", "processor", "type", config.Type)}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
93
internal/processor/kv-set.go
Normal file
93
internal/processor/kv-set.go
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
package processor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"html/template"
|
||||||
|
"log/slog"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type KVSet struct {
|
||||||
|
config config.ProcessorConfig
|
||||||
|
ModuleId string
|
||||||
|
Key string
|
||||||
|
Value *template.Template
|
||||||
|
logger *slog.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func (kvs *KVSet) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
|
||||||
|
if wrappedPayload.Modules == nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("kv.set wrapped payload has no modules")
|
||||||
|
}
|
||||||
|
|
||||||
|
module, ok := wrappedPayload.Modules[kvs.ModuleId]
|
||||||
|
if !ok {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("kv.set unable to find module with id: %s", kvs.ModuleId)
|
||||||
|
}
|
||||||
|
|
||||||
|
kvModule, ok := module.(common.KeyValueModule)
|
||||||
|
if !ok {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("kv.set module with id %s is not a KeyValueModule", kvs.ModuleId)
|
||||||
|
}
|
||||||
|
|
||||||
|
var valueBuffer bytes.Buffer
|
||||||
|
err := kvs.Value.Execute(&valueBuffer, wrappedPayload)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = kvModule.Set(kvs.Key, valueBuffer.String())
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("kv.set error setting key: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (kvs *KVSet) Type() string {
|
||||||
|
return kvs.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterProcessor(ProcessorRegistration{
|
||||||
|
Type: "kv.set",
|
||||||
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
|
|
||||||
|
params := config.Params
|
||||||
|
|
||||||
|
moduleIdString, err := params.GetString("module")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("kv.set module error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
keyString, err := params.GetString("key")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("kv.set key error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
valueString, err := params.GetString("value")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("kv.set value error: %w", err)
|
||||||
|
}
|
||||||
|
valueTemplate, err := template.New("template").Parse(valueString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &KVSet{config: config, ModuleId: moduleIdString, Key: keyString, Value: valueTemplate, logger: slog.Default().With("component", "processor", "type", config.Type)}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"gitlab.com/gomidi/midi/v2"
|
"gitlab.com/gomidi/midi/v2"
|
||||||
)
|
)
|
||||||
@@ -16,11 +17,11 @@ import (
|
|||||||
// TODO(jwetzell): support using numbers in config file treated as hardcoded values
|
// TODO(jwetzell): support using numbers in config file treated as hardcoded values
|
||||||
type MIDIMessageCreate struct {
|
type MIDIMessageCreate struct {
|
||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
ProcessFunc func(ctx context.Context, payload any) (any, error)
|
ProcessFunc func(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mmc *MIDIMessageCreate) Process(ctx context.Context, payload any) (any, error) {
|
func (mmc *MIDIMessageCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
return mmc.ProcessFunc(ctx, payload)
|
return mmc.ProcessFunc(ctx, wrappedPayload)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mmc *MIDIMessageCreate) Type() string {
|
func (mmc *MIDIMessageCreate) Type() string {
|
||||||
@@ -64,14 +65,15 @@ func newMidiNoteOnCreate(config config.ProcessorConfig) (Processor, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &MIDIMessageCreate{config: config, ProcessFunc: func(ctx context.Context, payload any) (any, error) {
|
return &MIDIMessageCreate{config: config, ProcessFunc: func(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
templateData := GetTemplateData(ctx, payload)
|
templateData := wrappedPayload
|
||||||
|
|
||||||
var channelBuffer bytes.Buffer
|
var channelBuffer bytes.Buffer
|
||||||
err := channelTemplate.Execute(&channelBuffer, templateData)
|
err := channelTemplate.Execute(&channelBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
||||||
@@ -80,7 +82,8 @@ func newMidiNoteOnCreate(config config.ProcessorConfig) (Processor, error) {
|
|||||||
err = noteTemplate.Execute(¬eBuffer, templateData)
|
err = noteTemplate.Execute(¬eBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
noteValue, err := strconv.ParseUint(noteBuffer.String(), 10, 8)
|
noteValue, err := strconv.ParseUint(noteBuffer.String(), 10, 8)
|
||||||
@@ -89,12 +92,14 @@ func newMidiNoteOnCreate(config config.ProcessorConfig) (Processor, error) {
|
|||||||
err = velocityTemplate.Execute(&velocityBuffer, templateData)
|
err = velocityTemplate.Execute(&velocityBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
velocityValue, err := strconv.ParseUint(velocityBuffer.String(), 10, 8)
|
velocityValue, err := strconv.ParseUint(velocityBuffer.String(), 10, 8)
|
||||||
payloadMessage := midi.NoteOn(uint8(channelValue), uint8(noteValue), uint8(velocityValue))
|
payloadMessage := midi.NoteOn(uint8(channelValue), uint8(noteValue), uint8(velocityValue))
|
||||||
return payloadMessage, nil
|
wrappedPayload.Payload = payloadMessage
|
||||||
|
return wrappedPayload, nil
|
||||||
}}, nil
|
}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,15 +140,16 @@ func newMidiNoteOffCreate(config config.ProcessorConfig) (Processor, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &MIDIMessageCreate{config: config, ProcessFunc: func(ctx context.Context, payload any) (any, error) {
|
return &MIDIMessageCreate{config: config, ProcessFunc: func(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
|
||||||
templateData := GetTemplateData(ctx, payload)
|
templateData := wrappedPayload
|
||||||
|
|
||||||
var channelBuffer bytes.Buffer
|
var channelBuffer bytes.Buffer
|
||||||
err := channelTemplate.Execute(&channelBuffer, templateData)
|
err := channelTemplate.Execute(&channelBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
||||||
@@ -152,7 +158,8 @@ func newMidiNoteOffCreate(config config.ProcessorConfig) (Processor, error) {
|
|||||||
err = noteTemplate.Execute(¬eBuffer, templateData)
|
err = noteTemplate.Execute(¬eBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
noteValue, err := strconv.ParseUint(noteBuffer.String(), 10, 8)
|
noteValue, err := strconv.ParseUint(noteBuffer.String(), 10, 8)
|
||||||
@@ -161,13 +168,15 @@ func newMidiNoteOffCreate(config config.ProcessorConfig) (Processor, error) {
|
|||||||
err = velocityTemplate.Execute(&velocityBuffer, templateData)
|
err = velocityTemplate.Execute(&velocityBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
velocityValue, err := strconv.ParseUint(velocityBuffer.String(), 10, 8)
|
velocityValue, err := strconv.ParseUint(velocityBuffer.String(), 10, 8)
|
||||||
|
|
||||||
payloadMessage := midi.NoteOffVelocity(uint8(channelValue), uint8(noteValue), uint8(velocityValue))
|
payloadMessage := midi.NoteOffVelocity(uint8(channelValue), uint8(noteValue), uint8(velocityValue))
|
||||||
return payloadMessage, nil
|
wrappedPayload.Payload = payloadMessage
|
||||||
|
return wrappedPayload, nil
|
||||||
}}, nil
|
}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,15 +217,16 @@ func newMidiControlChangeCreate(config config.ProcessorConfig) (Processor, error
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &MIDIMessageCreate{config: config, ProcessFunc: func(ctx context.Context, payload any) (any, error) {
|
return &MIDIMessageCreate{config: config, ProcessFunc: func(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
|
||||||
templateData := GetTemplateData(ctx, payload)
|
templateData := wrappedPayload
|
||||||
|
|
||||||
var channelBuffer bytes.Buffer
|
var channelBuffer bytes.Buffer
|
||||||
err := channelTemplate.Execute(&channelBuffer, templateData)
|
err := channelTemplate.Execute(&channelBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
||||||
@@ -225,7 +235,8 @@ func newMidiControlChangeCreate(config config.ProcessorConfig) (Processor, error
|
|||||||
err = controlTemplate.Execute(&controlBuffer, templateData)
|
err = controlTemplate.Execute(&controlBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
controlValue, err := strconv.ParseUint(controlBuffer.String(), 10, 8)
|
controlValue, err := strconv.ParseUint(controlBuffer.String(), 10, 8)
|
||||||
@@ -234,13 +245,15 @@ func newMidiControlChangeCreate(config config.ProcessorConfig) (Processor, error
|
|||||||
err = valueTemplate.Execute(&valueBuffer, templateData)
|
err = valueTemplate.Execute(&valueBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
valueValue, err := strconv.ParseUint(valueBuffer.String(), 10, 8)
|
valueValue, err := strconv.ParseUint(valueBuffer.String(), 10, 8)
|
||||||
|
|
||||||
payloadMessage := midi.ControlChange(uint8(channelValue), uint8(controlValue), uint8(valueValue))
|
payloadMessage := midi.ControlChange(uint8(channelValue), uint8(controlValue), uint8(valueValue))
|
||||||
return payloadMessage, nil
|
wrappedPayload.Payload = payloadMessage
|
||||||
|
return wrappedPayload, nil
|
||||||
}}, nil
|
}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,14 +283,15 @@ func newMidiProgramChangeCreate(config config.ProcessorConfig) (Processor, error
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &MIDIMessageCreate{config: config, ProcessFunc: func(ctx context.Context, payload any) (any, error) {
|
return &MIDIMessageCreate{config: config, ProcessFunc: func(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
templateData := GetTemplateData(ctx, payload)
|
templateData := wrappedPayload
|
||||||
|
|
||||||
var channelBuffer bytes.Buffer
|
var channelBuffer bytes.Buffer
|
||||||
err := channelTemplate.Execute(&channelBuffer, templateData)
|
err := channelTemplate.Execute(&channelBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
||||||
@@ -286,13 +300,15 @@ func newMidiProgramChangeCreate(config config.ProcessorConfig) (Processor, error
|
|||||||
err = programTemplate.Execute(&programBuffer, templateData)
|
err = programTemplate.Execute(&programBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
programValue, err := strconv.ParseUint(programBuffer.String(), 10, 8)
|
programValue, err := strconv.ParseUint(programBuffer.String(), 10, 8)
|
||||||
|
|
||||||
payloadMessage := midi.ProgramChange(uint8(channelValue), uint8(programValue))
|
payloadMessage := midi.ProgramChange(uint8(channelValue), uint8(programValue))
|
||||||
return payloadMessage, nil
|
wrappedPayload.Payload = payloadMessage
|
||||||
|
return wrappedPayload, nil
|
||||||
}}, nil
|
}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,16 +15,19 @@ type MIDIMessageDecode struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mmd *MIDIMessageDecode) Process(ctx context.Context, payload any) (any, error) {
|
func (mmd *MIDIMessageDecode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
payloadBytes, ok := common.GetAnyAs[[]byte](payload)
|
payload := wrappedPayload.Payload
|
||||||
|
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("midi.message.decode processor only accepts a []byte")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("midi.message.decode processor only accepts a []byte")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadMessage := midi.Message(payloadBytes)
|
payloadMessage := midi.Message(payloadBytes)
|
||||||
|
|
||||||
return payloadMessage, nil
|
wrappedPayload.Payload = payloadMessage
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mmd *MIDIMessageDecode) Type() string {
|
func (mmd *MIDIMessageDecode) Type() string {
|
||||||
|
|||||||
@@ -15,14 +15,17 @@ type MIDIMessageEncode struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mme *MIDIMessageEncode) Process(ctx context.Context, payload any) (any, error) {
|
func (mme *MIDIMessageEncode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
payload := wrappedPayload.Payload
|
||||||
payloadMessage, ok := common.GetAnyAs[midi.Message](payload)
|
payloadMessage, ok := common.GetAnyAs[midi.Message](payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("midi.message.encode processor only accepts a midi.Message")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("midi.message.encode processor only accepts a midi.Message")
|
||||||
}
|
}
|
||||||
|
|
||||||
return payloadMessage.Bytes(), nil
|
wrappedPayload.Payload = payloadMessage.Bytes()
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mme *MIDIMessageEncode) Type() string {
|
func (mme *MIDIMessageEncode) Type() string {
|
||||||
|
|||||||
@@ -45,36 +45,44 @@ type MIDIPitchBend struct {
|
|||||||
Absolute uint16
|
Absolute uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mmu *MIDIMessageUnpack) Process(ctx context.Context, payload any) (any, error) {
|
func (mmu *MIDIMessageUnpack) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
payload := wrappedPayload.Payload
|
||||||
payloadMidi, ok := common.GetAnyAs[midi.Message](payload)
|
payloadMidi, ok := common.GetAnyAs[midi.Message](payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("midi.message.unpack processor only accepts a midi.Message")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("midi.message.unpack processor only accepts a midi.Message")
|
||||||
}
|
}
|
||||||
|
|
||||||
switch payloadMidi.Type() {
|
switch payloadMidi.Type() {
|
||||||
case midi.NoteOnMsg:
|
case midi.NoteOnMsg:
|
||||||
noteOnMsg := MIDINoteOn{}
|
noteOnMsg := MIDINoteOn{}
|
||||||
payloadMidi.GetNoteOn(¬eOnMsg.Channel, ¬eOnMsg.Note, ¬eOnMsg.Velocity)
|
payloadMidi.GetNoteOn(¬eOnMsg.Channel, ¬eOnMsg.Note, ¬eOnMsg.Velocity)
|
||||||
return noteOnMsg, nil
|
wrappedPayload.Payload = noteOnMsg
|
||||||
|
return wrappedPayload, nil
|
||||||
case midi.NoteOffMsg:
|
case midi.NoteOffMsg:
|
||||||
noteOffMsg := MIDINoteOff{}
|
noteOffMsg := MIDINoteOff{}
|
||||||
payloadMidi.GetNoteOff(¬eOffMsg.Channel, ¬eOffMsg.Note, ¬eOffMsg.Velocity)
|
payloadMidi.GetNoteOff(¬eOffMsg.Channel, ¬eOffMsg.Note, ¬eOffMsg.Velocity)
|
||||||
return noteOffMsg, nil
|
wrappedPayload.Payload = noteOffMsg
|
||||||
|
return wrappedPayload, nil
|
||||||
case midi.ControlChangeMsg:
|
case midi.ControlChangeMsg:
|
||||||
controlChangeMsg := MIDIControlChange{}
|
controlChangeMsg := MIDIControlChange{}
|
||||||
payloadMidi.GetControlChange(&controlChangeMsg.Channel, &controlChangeMsg.Control, &controlChangeMsg.Value)
|
payloadMidi.GetControlChange(&controlChangeMsg.Channel, &controlChangeMsg.Control, &controlChangeMsg.Value)
|
||||||
return controlChangeMsg, nil
|
wrappedPayload.Payload = controlChangeMsg
|
||||||
|
return wrappedPayload, nil
|
||||||
case midi.ProgramChangeMsg:
|
case midi.ProgramChangeMsg:
|
||||||
programChangeMsg := MIDIProgramChange{}
|
programChangeMsg := MIDIProgramChange{}
|
||||||
payloadMidi.GetProgramChange(&programChangeMsg.Channel, &programChangeMsg.Program)
|
payloadMidi.GetProgramChange(&programChangeMsg.Channel, &programChangeMsg.Program)
|
||||||
return programChangeMsg, nil
|
wrappedPayload.Payload = programChangeMsg
|
||||||
|
return wrappedPayload, nil
|
||||||
case midi.PitchBendMsg:
|
case midi.PitchBendMsg:
|
||||||
pitchBendMsg := MIDIPitchBend{}
|
pitchBendMsg := MIDIPitchBend{}
|
||||||
payloadMidi.GetPitchBend(&pitchBendMsg.Channel, &pitchBendMsg.Relative, &pitchBendMsg.Absolute)
|
payloadMidi.GetPitchBend(&pitchBendMsg.Channel, &pitchBendMsg.Relative, &pitchBendMsg.Absolute)
|
||||||
return pitchBendMsg, nil
|
wrappedPayload.Payload = pitchBendMsg
|
||||||
|
return wrappedPayload, nil
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("midi.message.unpack message type not supported %v", payloadMidi.Type())
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("midi.message.unpack message type not supported %v", payloadMidi.Type())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -60,17 +61,17 @@ func (mm MQTTMessage) Payload() []byte {
|
|||||||
|
|
||||||
func (mm MQTTMessage) Ack() {}
|
func (mm MQTTMessage) Ack() {}
|
||||||
|
|
||||||
func (mmc *MQTTMessageCreate) Process(ctx context.Context, payload any) (any, error) {
|
func (mmc *MQTTMessageCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
// TODO(jwetzell): support templating
|
// TODO(jwetzell): support templating
|
||||||
|
|
||||||
message := MQTTMessage{
|
wrappedPayload.Payload = MQTTMessage{
|
||||||
topic: mmc.Topic,
|
topic: mmc.Topic,
|
||||||
qos: mmc.QoS,
|
qos: mmc.QoS,
|
||||||
retained: mmc.Retained,
|
retained: mmc.Retained,
|
||||||
payload: mmc.Payload,
|
payload: mmc.Payload,
|
||||||
}
|
}
|
||||||
|
|
||||||
return message, nil
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mmc *MQTTMessageCreate) Type() string {
|
func (mmc *MQTTMessageCreate) Type() string {
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
package processor
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
|
|
||||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/common"
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
type MQTTMessageEncode struct {
|
|
||||||
config config.ProcessorConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mme *MQTTMessageEncode) Process(ctx context.Context, payload any) (any, error) {
|
|
||||||
payloadMessage, ok := common.GetAnyAs[mqtt.Message](payload)
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("mqtt.message.encode processor only accepts an mqtt.Message")
|
|
||||||
}
|
|
||||||
|
|
||||||
return payloadMessage.Payload(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mme *MQTTMessageEncode) Type() string {
|
|
||||||
return mme.config.Type
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
RegisterProcessor(ProcessorRegistration{
|
|
||||||
Type: "mqtt.message.encode",
|
|
||||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
|
||||||
return &MQTTMessageEncode{config: config}, nil
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,14 +21,16 @@ type NATSMessageCreate struct {
|
|||||||
Payload *template.Template
|
Payload *template.Template
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nmc *NATSMessageCreate) Process(ctx context.Context, payload any) (any, error) {
|
func (nmc *NATSMessageCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
templateData := GetTemplateData(ctx, payload)
|
|
||||||
|
templateData := wrappedPayload
|
||||||
|
|
||||||
var payloadBuffer bytes.Buffer
|
var payloadBuffer bytes.Buffer
|
||||||
err := nmc.Payload.Execute(&payloadBuffer, templateData)
|
err := nmc.Payload.Execute(&payloadBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadString := payloadBuffer.String()
|
payloadString := payloadBuffer.String()
|
||||||
@@ -36,17 +39,18 @@ func (nmc *NATSMessageCreate) Process(ctx context.Context, payload any) (any, er
|
|||||||
err = nmc.Subject.Execute(&subjectBuffer, templateData)
|
err = nmc.Subject.Execute(&subjectBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
subjectString := subjectBuffer.String()
|
subjectString := subjectBuffer.String()
|
||||||
|
|
||||||
message := NATSMessage{
|
wrappedPayload.Payload = NATSMessage{
|
||||||
Subject: subjectString,
|
Subject: subjectString,
|
||||||
Payload: []byte(payloadString),
|
Payload: []byte(payloadString),
|
||||||
}
|
}
|
||||||
|
|
||||||
return message, nil
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nmc *NATSMessageCreate) Type() string {
|
func (nmc *NATSMessageCreate) Type() string {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/jwetzell/osc-go"
|
"github.com/jwetzell/osc-go"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,25 +21,28 @@ type OSCMessageCreate struct {
|
|||||||
Types string
|
Types string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (omc *OSCMessageCreate) Process(ctx context.Context, payload any) (any, error) {
|
func (omc *OSCMessageCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
|
||||||
templateData := GetTemplateData(ctx, payload)
|
templateData := wrappedPayload
|
||||||
|
|
||||||
var addressBuffer bytes.Buffer
|
var addressBuffer bytes.Buffer
|
||||||
err := omc.Address.Execute(&addressBuffer, templateData)
|
err := omc.Address.Execute(&addressBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
addressString := addressBuffer.String()
|
addressString := addressBuffer.String()
|
||||||
|
|
||||||
if len(addressString) == 0 {
|
if len(addressString) == 0 {
|
||||||
return nil, errors.New("osc.message.create address must not be empty")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("osc.message.create address must not be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
if addressString[0] != '/' {
|
if addressString[0] != '/' {
|
||||||
return nil, errors.New("osc.message.create address must start with '/'")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("osc.message.create address must start with '/'")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadMessage := &osc.OSCMessage{
|
payloadMessage := &osc.OSCMessage{
|
||||||
@@ -52,7 +56,8 @@ func (omc *OSCMessageCreate) Process(ctx context.Context, payload any) (any, err
|
|||||||
err := argTemplate.Execute(&argBuffer, templateData)
|
err := argTemplate.Execute(&argBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
argString := argBuffer.String()
|
argString := argBuffer.String()
|
||||||
@@ -60,7 +65,8 @@ func (omc *OSCMessageCreate) Process(ctx context.Context, payload any) (any, err
|
|||||||
typedArg, err := argToTypedArg(argString, omc.Types[argIndex])
|
typedArg, err := argToTypedArg(argString, omc.Types[argIndex])
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
args = append(args, typedArg)
|
args = append(args, typedArg)
|
||||||
@@ -70,7 +76,8 @@ func (omc *OSCMessageCreate) Process(ctx context.Context, payload any) (any, err
|
|||||||
payloadMessage.Args = args
|
payloadMessage.Args = args
|
||||||
}
|
}
|
||||||
|
|
||||||
return payloadMessage, nil
|
wrappedPayload.Payload = payloadMessage
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (omc *OSCMessageCreate) Type() string {
|
func (omc *OSCMessageCreate) Type() string {
|
||||||
|
|||||||
@@ -14,26 +14,32 @@ type OSCMessageDecode struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (omd *OSCMessageDecode) Process(ctx context.Context, payload any) (any, error) {
|
func (omd *OSCMessageDecode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
payloadBytes, ok := common.GetAnyAs[[]byte](payload)
|
payload := wrappedPayload.Payload
|
||||||
|
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("osc.message.decode processor only accepts a []byte payload")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("osc.message.decode processor only accepts a []byte payload")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(payloadBytes) == 0 {
|
if len(payloadBytes) == 0 {
|
||||||
return nil, errors.New("osc.message.decode processor can't work on empty []byte")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("osc.message.decode processor can't work on empty []byte")
|
||||||
}
|
}
|
||||||
|
|
||||||
if payloadBytes[0] != '/' {
|
if payloadBytes[0] != '/' {
|
||||||
return nil, errors.New("osc.message.decode processor needs an OSC looking []byte")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("osc.message.decode processor needs an OSC looking []byte")
|
||||||
}
|
}
|
||||||
|
|
||||||
message, err := osc.MessageFromBytes(payloadBytes)
|
message, err := osc.MessageFromBytes(payloadBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("osc.message.decode processor failed to decode OSC message: %w", err)
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("osc.message.decode processor failed to decode OSC message: %w", err)
|
||||||
}
|
}
|
||||||
return message, nil
|
wrappedPayload.Payload = message
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (omd *OSCMessageDecode) Type() string {
|
func (omd *OSCMessageDecode) Type() string {
|
||||||
|
|||||||
@@ -13,15 +13,17 @@ type OSCMessageEncode struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ome *OSCMessageEncode) Process(ctx context.Context, payload any) (any, error) {
|
func (ome *OSCMessageEncode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
payload := wrappedPayload.Payload
|
||||||
payloadMessage, ok := common.GetAnyAs[*osc.OSCMessage](payload)
|
payloadMessage, ok := common.GetAnyAs[*osc.OSCMessage](payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("osc.message.encode processor only accepts an *OSCMessage")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("osc.message.encode processor only accepts an *OSCMessage")
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes := payloadMessage.ToBytes()
|
wrappedPayload.Payload = payloadMessage.ToBytes()
|
||||||
return bytes, nil
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ome *OSCMessageEncode) Type() string {
|
func (ome *OSCMessageEncode) Type() string {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
type Processor interface {
|
type Processor interface {
|
||||||
Type() string
|
Type() string
|
||||||
Process(context.Context, any) (any, error)
|
Process(context.Context, common.WrappedPayload) (common.WrappedPayload, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProcessorRegistration struct {
|
type ProcessorRegistration struct {
|
||||||
@@ -41,38 +41,3 @@ var (
|
|||||||
processorRegistryMu sync.RWMutex
|
processorRegistryMu sync.RWMutex
|
||||||
ProcessorRegistry = make(map[string]ProcessorRegistration)
|
ProcessorRegistry = make(map[string]ProcessorRegistration)
|
||||||
)
|
)
|
||||||
|
|
||||||
type TemplateData struct {
|
|
||||||
Payload any
|
|
||||||
Modules any
|
|
||||||
Sender any
|
|
||||||
}
|
|
||||||
|
|
||||||
type EnvData struct {
|
|
||||||
Payload any
|
|
||||||
Sender any
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetTemplateData(ctx context.Context, payload any) TemplateData {
|
|
||||||
templateData := TemplateData{Payload: payload}
|
|
||||||
modules := ctx.Value(common.ModulesContextKey)
|
|
||||||
if modules != nil {
|
|
||||||
templateData.Modules = modules
|
|
||||||
}
|
|
||||||
|
|
||||||
sender := ctx.Value(common.SenderContextKey)
|
|
||||||
if sender != nil {
|
|
||||||
templateData.Sender = sender
|
|
||||||
}
|
|
||||||
return templateData
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetEnvData(ctx context.Context, payload any) EnvData {
|
|
||||||
envData := EnvData{Payload: payload}
|
|
||||||
|
|
||||||
sender := ctx.Value(common.SenderContextKey)
|
|
||||||
if sender != nil {
|
|
||||||
envData.Sender = sender
|
|
||||||
}
|
|
||||||
return envData
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -16,20 +16,26 @@ type RouterInput struct {
|
|||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ro *RouterInput) Process(ctx context.Context, payload any) (any, error) {
|
func (ro *RouterInput) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
|
||||||
|
payload := wrappedPayload.Payload
|
||||||
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("router.input no router found")
|
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("router.input no router found")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := router.HandleInput(ctx, ro.SourceId, payload)
|
_, err := router.HandleInput(ctx, ro.SourceId, payload)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("router.input failed to send input")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("router.input failed to send input")
|
||||||
}
|
}
|
||||||
|
|
||||||
return payload, nil
|
wrappedPayload.Payload = payload
|
||||||
|
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ro *RouterInput) Type() string {
|
func (ro *RouterInput) Type() string {
|
||||||
|
|||||||
@@ -16,20 +16,22 @@ type RouterOutput struct {
|
|||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ro *RouterOutput) Process(ctx context.Context, payload any) (any, error) {
|
func (ro *RouterOutput) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
|
||||||
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("router.output no router found")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("router.output no router found")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := router.HandleOutput(ctx, ro.ModuleId, payload)
|
err := router.HandleOutput(ctx, ro.ModuleId, wrappedPayload.Payload)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("router.output failed to send output: %w", err)
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("router.output failed to send output: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return payload, nil
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ro *RouterOutput) Type() string {
|
func (ro *RouterOutput) Type() string {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/expr-lang/expr"
|
"github.com/expr-lang/expr"
|
||||||
"github.com/expr-lang/expr/vm"
|
"github.com/expr-lang/expr/vm"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,16 +16,18 @@ type ScriptExpr struct {
|
|||||||
Program *vm.Program
|
Program *vm.Program
|
||||||
}
|
}
|
||||||
|
|
||||||
func (se *ScriptExpr) Process(ctx context.Context, payload any) (any, error) {
|
func (se *ScriptExpr) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
|
||||||
exprEnv := GetEnvData(ctx, payload)
|
exprEnv := wrappedPayload
|
||||||
|
|
||||||
output, err := expr.Run(se.Program, exprEnv)
|
output, err := expr.Run(se.Program, exprEnv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return output, nil
|
wrappedPayload.Payload = output
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (se *ScriptExpr) Type() string {
|
func (se *ScriptExpr) Type() string {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/common"
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
@@ -18,55 +17,74 @@ type ScriptJS struct {
|
|||||||
Program string
|
Program string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sj *ScriptJS) Process(ctx context.Context, payload any) (any, error) {
|
func (sj *ScriptJS) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
|
||||||
//NOTE(jwetzell): some weird conversion going on with these types
|
//NOTE(jwetzell): some weird conversion going on with these types
|
||||||
_, isUint8Slice := common.GetAnyAs[[]uint8](payload)
|
_, isUint8Slice := common.GetAnyAs[[]uint8](wrappedPayload.Payload)
|
||||||
_, isbyteSlice := common.GetAnyAs[[]byte](payload)
|
_, isbyteSlice := common.GetAnyAs[[]byte](wrappedPayload.Payload)
|
||||||
|
|
||||||
if isUint8Slice || isbyteSlice {
|
if isUint8Slice || isbyteSlice {
|
||||||
intSlice, ok := common.GetAnyAsIntSlice(payload)
|
intSlice, ok := common.GetAnyAsIntSlice(wrappedPayload.Payload)
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
payload = intSlice
|
wrappedPayload.Payload = intSlice
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sj.vm.SetProperty(sj.vm.GlobalObject(), sj.payloadAtom, payload)
|
sj.vm.SetProperty(sj.vm.GlobalObject(), sj.payloadAtom, wrappedPayload.Payload)
|
||||||
|
|
||||||
sender := ctx.Value(common.SenderContextKey)
|
sj.vm.SetProperty(sj.vm.GlobalObject(), sj.senderAtom, wrappedPayload.Sender)
|
||||||
sj.vm.SetProperty(sj.vm.GlobalObject(), sj.senderAtom, sender)
|
|
||||||
|
|
||||||
_, err := sj.vm.Eval(sj.Program, quickjs.EvalGlobal)
|
_, err := sj.vm.Eval(sj.Program, quickjs.EvalGlobal)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
output, err := sj.vm.GetProperty(sj.vm.GlobalObject(), sj.payloadAtom)
|
output, err := sj.vm.GetProperty(sj.vm.GlobalObject(), sj.payloadAtom)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE(jwetzell): turn undefined into nil
|
// NOTE(jwetzell): turn undefined into nil
|
||||||
_, ok := output.(quickjs.Undefined)
|
_, ok := output.(quickjs.Undefined)
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
return nil, nil
|
wrappedPayload.End = true
|
||||||
|
wrappedPayload.Payload = nil
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE(jwetzell): turn object into map[string]interface{}
|
// NOTE(jwetzell): turn object into map[string]interface{}
|
||||||
outputObject, ok := output.(*quickjs.Object)
|
outputObject, ok := output.(*quickjs.Object)
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
|
var outputSlice []interface{}
|
||||||
|
|
||||||
|
err = outputObject.Into(&outputSlice)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
var outputMap map[string]interface{}
|
var outputMap map[string]interface{}
|
||||||
fmt.Println(outputObject.String())
|
err = outputObject.Into(&outputMap)
|
||||||
err := json.Unmarshal([]byte(outputObject.String()), &outputMap)
|
if err != nil {
|
||||||
return outputMap, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
} else {
|
||||||
|
wrappedPayload.Payload = outputMap
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return output, nil
|
} else {
|
||||||
|
wrappedPayload.Payload = outputSlice
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wrappedPayload.Payload = output
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sj *ScriptJS) Type() string {
|
func (sj *ScriptJS) Type() string {
|
||||||
|
|||||||
@@ -16,27 +16,32 @@ type ScriptWASM struct {
|
|||||||
Function string
|
Function string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sw *ScriptWASM) Process(ctx context.Context, payload any) (any, error) {
|
func (sw *ScriptWASM) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
|
||||||
payloadBytes, ok := common.GetAnyAs[[]byte](payload)
|
payload := wrappedPayload.Payload
|
||||||
|
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("script.wasm can only process a byte array")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("script.wasm can only process a byte array")
|
||||||
}
|
}
|
||||||
|
|
||||||
program, err := sw.Program.Instance(ctx, extism.PluginInstanceConfig{})
|
program, err := sw.Program.Instance(ctx, extism.PluginInstanceConfig{})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, output, err := program.Call(sw.Function, payloadBytes)
|
_, output, err := program.Call(sw.Function, payloadBytes)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
wrappedPayload.Payload = output
|
||||||
|
|
||||||
return output, nil
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sw *ScriptWASM) Type() string {
|
func (sw *ScriptWASM) Type() string {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -22,24 +23,26 @@ type SipAudioFileResponse struct {
|
|||||||
AudioFile string
|
AudioFile string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srac *SipResponseAudioCreate) Process(ctx context.Context, payload any) (any, error) {
|
func (srac *SipResponseAudioCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
|
||||||
templateData := GetTemplateData(ctx, payload)
|
templateData := wrappedPayload
|
||||||
|
|
||||||
var audioFileBuffer bytes.Buffer
|
var audioFileBuffer bytes.Buffer
|
||||||
err := srac.AudioFile.Execute(&audioFileBuffer, templateData)
|
err := srac.AudioFile.Execute(&audioFileBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
audioFileString := audioFileBuffer.String()
|
audioFileString := audioFileBuffer.String()
|
||||||
|
|
||||||
return SipAudioFileResponse{
|
wrappedPayload.Payload = SipAudioFileResponse{
|
||||||
PreWait: srac.PreWait,
|
PreWait: srac.PreWait,
|
||||||
PostWait: srac.PostWait,
|
PostWait: srac.PostWait,
|
||||||
AudioFile: audioFileString,
|
AudioFile: audioFileString,
|
||||||
}, nil
|
}
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srac *SipResponseAudioCreate) Type() string {
|
func (srac *SipResponseAudioCreate) Type() string {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,28 +26,31 @@ type SipDTMFResponse struct {
|
|||||||
Digits string
|
Digits string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srdc *SipResponseDTMFCreate) Process(ctx context.Context, payload any) (any, error) {
|
func (srdc *SipResponseDTMFCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
|
||||||
templateData := GetTemplateData(ctx, payload)
|
templateData := wrappedPayload
|
||||||
|
|
||||||
var digitsBuffer bytes.Buffer
|
var digitsBuffer bytes.Buffer
|
||||||
err := srdc.Digits.Execute(&digitsBuffer, templateData)
|
err := srdc.Digits.Execute(&digitsBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
digitsString := digitsBuffer.String()
|
digitsString := digitsBuffer.String()
|
||||||
|
|
||||||
if !srdc.validDTMF.MatchString(digitsString) {
|
if !srdc.validDTMF.MatchString(digitsString) {
|
||||||
return nil, errors.New("sip.response.dtmf.create result of digits template contains invalid characters")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("sip.response.dtmf.create result of digits template contains invalid characters")
|
||||||
}
|
}
|
||||||
|
|
||||||
return SipDTMFResponse{
|
wrappedPayload.Payload = SipDTMFResponse{
|
||||||
PreWait: srdc.PreWait,
|
PreWait: srdc.PreWait,
|
||||||
PostWait: srdc.PostWait,
|
PostWait: srdc.PostWait,
|
||||||
Digits: digitsString,
|
Digits: digitsString,
|
||||||
}, nil
|
}
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srdc *SipResponseDTMFCreate) Type() string {
|
func (srdc *SipResponseDTMFCreate) Type() string {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -14,19 +15,20 @@ type StringCreate struct {
|
|||||||
Template *template.Template
|
Template *template.Template
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sc *StringCreate) Process(ctx context.Context, payload any) (any, error) {
|
func (sc *StringCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
templateData := GetTemplateData(ctx, payload)
|
templateData := wrappedPayload
|
||||||
|
|
||||||
var templateBuffer bytes.Buffer
|
var templateBuffer bytes.Buffer
|
||||||
err := sc.Template.Execute(&templateBuffer, templateData)
|
err := sc.Template.Execute(&templateBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadString := templateBuffer.String()
|
wrappedPayload.Payload = templateBuffer.String()
|
||||||
|
|
||||||
return payloadString, nil
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sc *StringCreate) Type() string {
|
func (sc *StringCreate) Type() string {
|
||||||
|
|||||||
@@ -12,16 +12,19 @@ type StringDecode struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sd *StringDecode) Process(ctx context.Context, payload any) (any, error) {
|
func (sd *StringDecode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
payloadBytes, ok := common.GetAnyAs[[]byte](payload)
|
payload := wrappedPayload.Payload
|
||||||
|
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("string.decode processor only accepts a []byte")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("string.decode processor only accepts a []byte")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadMessage := string(payloadBytes)
|
payloadMessage := string(payloadBytes)
|
||||||
|
|
||||||
return payloadMessage, nil
|
wrappedPayload.Payload = payloadMessage
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sd *StringDecode) Type() string {
|
func (sd *StringDecode) Type() string {
|
||||||
|
|||||||
@@ -12,16 +12,18 @@ type StringEncode struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (se *StringEncode) Process(ctx context.Context, payload any) (any, error) {
|
func (se *StringEncode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
payload := wrappedPayload.Payload
|
||||||
payloadString, ok := common.GetAnyAs[string](payload)
|
payloadString, ok := common.GetAnyAs[string](payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("string.encode processor only accepts a string")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("string.encode processor only accepts a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadBytes := []byte(payloadString)
|
wrappedPayload.Payload = []byte(payloadString)
|
||||||
|
|
||||||
return payloadBytes, nil
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (se *StringEncode) Type() string {
|
func (se *StringEncode) Type() string {
|
||||||
|
|||||||
@@ -15,16 +15,18 @@ type StringSplit struct {
|
|||||||
Separator string
|
Separator string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *StringSplit) Process(ctx context.Context, payload any) (any, error) {
|
func (ss *StringSplit) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
payload := wrappedPayload.Payload
|
||||||
payloadString, ok := common.GetAnyAs[string](payload)
|
payloadString, ok := common.GetAnyAs[string](payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("string.split only accepts a string")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("string.split only accepts a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadParts := strings.Split(payloadString, ss.Separator)
|
wrappedPayload.Payload = strings.Split(payloadString, ss.Separator)
|
||||||
|
|
||||||
return payloadParts, nil
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *StringSplit) Type() string {
|
func (ss *StringSplit) Type() string {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -14,23 +15,27 @@ type StructFieldGet struct {
|
|||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sf *StructFieldGet) Process(ctx context.Context, payload any) (any, error) {
|
func (sf *StructFieldGet) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
payload := wrappedPayload.Payload
|
||||||
s := reflect.ValueOf(payload)
|
s := reflect.ValueOf(payload)
|
||||||
|
|
||||||
if s.Kind() != reflect.Struct {
|
if s.Kind() != reflect.Struct {
|
||||||
if s.Kind() == reflect.Pointer && s.Elem().Kind() == reflect.Struct {
|
if s.Kind() == reflect.Pointer && s.Elem().Kind() == reflect.Struct {
|
||||||
s = s.Elem()
|
s = s.Elem()
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New("struct.field.get processor only accepts a struct payload")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("struct.field.get processor only accepts a struct payload")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
field := s.FieldByName(sf.Name)
|
field := s.FieldByName(sf.Name)
|
||||||
if !field.IsValid() {
|
if !field.IsValid() {
|
||||||
return nil, fmt.Errorf("struct.field.get field '%s' does not exist", sf.Name)
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("struct.field.get field '%s' does not exist", sf.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
return field.Interface(), nil
|
wrappedPayload.Payload = field.Interface()
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sf *StructFieldGet) Type() string {
|
func (sf *StructFieldGet) Type() string {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -14,30 +15,36 @@ type StructMethodGet struct {
|
|||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *StructMethodGet) Process(ctx context.Context, payload any) (any, error) {
|
func (sm *StructMethodGet) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
payload := wrappedPayload.Payload
|
||||||
s := reflect.ValueOf(payload)
|
s := reflect.ValueOf(payload)
|
||||||
|
|
||||||
if s.Kind() != reflect.Struct {
|
if s.Kind() != reflect.Struct {
|
||||||
if s.Kind() == reflect.Pointer && s.Elem().Kind() == reflect.Struct {
|
if s.Kind() == reflect.Pointer && s.Elem().Kind() == reflect.Struct {
|
||||||
s = s.Elem()
|
s = s.Elem()
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New("struct.method.get processor only accepts a struct payload")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("struct.method.get processor only accepts a struct payload")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
method := s.MethodByName(sm.Name)
|
method := s.MethodByName(sm.Name)
|
||||||
if !method.IsValid() {
|
if !method.IsValid() {
|
||||||
return nil, fmt.Errorf("struct.method.get method '%s' does not exist", sm.Name)
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("struct.method.get method '%s' does not exist", sm.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
value := method.Call(nil)
|
value := method.Call(nil)
|
||||||
|
|
||||||
if len(value) == 0 {
|
if len(value) == 0 {
|
||||||
return nil, nil
|
wrappedPayload.End = true
|
||||||
|
wrappedPayload.Payload = nil
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(value) == 1 {
|
if len(value) == 1 {
|
||||||
return value[0].Interface(), nil
|
wrappedPayload.Payload = value[0].Interface()
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
results := make([]any, len(value))
|
results := make([]any, len(value))
|
||||||
@@ -46,7 +53,8 @@ func (sm *StructMethodGet) Process(ctx context.Context, payload any) (any, error
|
|||||||
results[i] = v.Interface()
|
results[i] = v.Interface()
|
||||||
}
|
}
|
||||||
|
|
||||||
return results, nil
|
wrappedPayload.Payload = results
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *StructMethodGet) Type() string {
|
func (sm *StructMethodGet) Type() string {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/jwetzell/artnet-go"
|
"github.com/jwetzell/artnet-go"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
)
|
)
|
||||||
@@ -57,15 +58,15 @@ func TestGoodArtnetPacketDecode(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
got, err := packetDecoder.Process(t.Context(), test.payload)
|
got, err := packetDecoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("artnet.packet.decode processing failed: %s", err)
|
t.Fatalf("artnet.packet.decode processing failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO(jwetzell): work out better way to compare the any/any
|
//TODO(jwetzell): work out better way to compare the any/any
|
||||||
if !reflect.DeepEqual(got, test.expected) {
|
if !reflect.DeepEqual(got.Payload, test.expected) {
|
||||||
t.Fatalf("artnet.packet.decode got %+v (%T), expected %+v (%T)", got, got, test.expected, test.expected)
|
t.Fatalf("artnet.packet.decode got %+v (%T), expected %+v (%T)", got.Payload, got.Payload, test.expected, test.expected)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -93,7 +94,7 @@ func TestBadArtnetPacketDecode(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
got, err := packetDecoder.Process(t.Context(), test.payload)
|
got, err := packetDecoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("artnet.packet.decode expected to fail but succeeded, got: %v", got)
|
t.Fatalf("artnet.packet.decode expected to fail but succeeded, got: %v", got)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/jwetzell/artnet-go"
|
"github.com/jwetzell/artnet-go"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
)
|
)
|
||||||
@@ -57,14 +58,14 @@ func TestGoodArtnetPacketEncode(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
got, err := packetEncoder.Process(t.Context(), test.payload)
|
got, err := packetEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("artnet.packet.encode processing failed: %s", err)
|
t.Fatalf("artnet.packet.encode processing failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO(jwetzell): work out better way to compare the any/any
|
//TODO(jwetzell): work out better way to compare the any/any
|
||||||
if !reflect.DeepEqual(got, test.expected) {
|
if !reflect.DeepEqual(got.Payload, test.expected) {
|
||||||
t.Fatalf("artnet.packet.encode got %+v (%T), expected %+v (%T)", got, got, test.expected, test.expected)
|
t.Fatalf("artnet.packet.encode got %+v (%T), expected %+v (%T)", got, got, test.expected, test.expected)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -88,7 +89,7 @@ func TestBadArtnetPacketEncode(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
got, err := packetEncoder.Process(t.Context(), test.payload)
|
got, err := packetEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("artnet.packet.encode expected to fail but succeeded, got: %v", got)
|
t.Fatalf("artnet.packet.encode expected to fail but succeeded, got: %v", got)
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package processor_test
|
package processor_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
)
|
)
|
||||||
@@ -28,12 +30,91 @@ func TestDebugLogFromRegistry(t *testing.T) {
|
|||||||
payload := "test"
|
payload := "test"
|
||||||
expected := "test"
|
expected := "test"
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), payload))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("debug.log processing failed: %s", err)
|
t.Fatalf("debug.log processing failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if got != expected {
|
if got.Payload != expected {
|
||||||
t.Fatalf("debug.log got %+v, expected %+v", got, expected)
|
t.Fatalf("debug.log got %+v, expected %+v", got, expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGoodDebugLog(t *testing.T) {
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
params map[string]any
|
||||||
|
payload any
|
||||||
|
expected any
|
||||||
|
}{}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
|
registration, ok := processor.ProcessorRegistry["debug.log"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("debug.log processor not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||||
|
Type: "debug.log",
|
||||||
|
Params: test.params,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("debug.log failed to create processor: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("debug.log processing failed: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(got.Payload, test.expected) {
|
||||||
|
t.Fatalf("debug.log got %+v (%T), expected %+v (%T)", got.Payload, got.Payload, test.expected, test.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadDebugLog(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
params map[string]any
|
||||||
|
payload any
|
||||||
|
errorString string
|
||||||
|
}{}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
|
registration, ok := processor.ProcessorRegistry["debug.log"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("debug.log processor not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||||
|
Type: "debug.log",
|
||||||
|
Params: test.params,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
if test.errorString != err.Error() {
|
||||||
|
t.Fatalf("debug.log got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("debug.log expected to fail but succeeded, got: %v", got)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err.Error() != test.errorString {
|
||||||
|
t.Fatalf("debug.log got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package processor_test
|
package processor_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
)
|
)
|
||||||
@@ -34,7 +34,7 @@ func TestGoodFilterExpr(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
params map[string]any
|
params map[string]any
|
||||||
payload any
|
payload any
|
||||||
expected any
|
match bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "number",
|
name: "number",
|
||||||
@@ -44,9 +44,7 @@ func TestGoodFilterExpr(t *testing.T) {
|
|||||||
payload: TestStruct{
|
payload: TestStruct{
|
||||||
Int: 1,
|
Int: 1,
|
||||||
},
|
},
|
||||||
expected: TestStruct{
|
match: true,
|
||||||
Int: 1,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "string",
|
name: "string",
|
||||||
@@ -56,9 +54,7 @@ func TestGoodFilterExpr(t *testing.T) {
|
|||||||
payload: TestStruct{
|
payload: TestStruct{
|
||||||
String: "hello",
|
String: "hello",
|
||||||
},
|
},
|
||||||
expected: TestStruct{
|
match: true,
|
||||||
String: "hello",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "not matching",
|
name: "not matching",
|
||||||
@@ -68,7 +64,7 @@ func TestGoodFilterExpr(t *testing.T) {
|
|||||||
payload: TestStruct{
|
payload: TestStruct{
|
||||||
Int: 0,
|
Int: 0,
|
||||||
},
|
},
|
||||||
expected: nil,
|
match: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,15 +84,15 @@ func TestGoodFilterExpr(t *testing.T) {
|
|||||||
t.Fatalf("filter.expr failed to create processor: %s", err)
|
t.Fatalf("filter.expr failed to create processor: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("filter.expr processing failed: %s", err)
|
t.Fatalf("filter.expr processing failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO(jwetzell): work out better way to compare the any/any
|
//TODO(jwetzell): work out better way to compare the any/any
|
||||||
if !reflect.DeepEqual(got, test.expected) {
|
if got.End != !test.match {
|
||||||
t.Fatalf("filter.expr got %+v (%T), expected %+v (%T)", got, got, test.expected, test.expected)
|
t.Fatalf("filter.expr did fitler properly %+v (%T), expected %+v (%T)", got, got, test.match, test.match)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -162,7 +158,7 @@ func TestBadFilterExpr(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("filter.expr expected to fail but succeeded, got: %v", got)
|
t.Fatalf("filter.expr expected to fail but succeeded, got: %v", got)
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package processor_test
|
package processor_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
)
|
)
|
||||||
@@ -31,12 +31,12 @@ func TestStringFilterFromRegistry(t *testing.T) {
|
|||||||
payload := "hello"
|
payload := "hello"
|
||||||
expected := "hello"
|
expected := "hello"
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), payload))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("filter.regex processing failed: %s", err)
|
t.Fatalf("filter.regex processing failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gotString, ok := got.(string)
|
gotString, ok := got.Payload.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("filter.regex should return byte slice")
|
t.Fatalf("filter.regex should return byte slice")
|
||||||
@@ -52,25 +52,25 @@ func TestGoodStringFilter(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
params map[string]any
|
params map[string]any
|
||||||
payload string
|
payload string
|
||||||
expected any
|
match bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "matches pattern",
|
name: "matches pattern",
|
||||||
payload: "hello",
|
payload: "hello",
|
||||||
params: map[string]any{"pattern": "hello"},
|
params: map[string]any{"pattern": "hello"},
|
||||||
expected: "hello",
|
match: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "does not match pattern",
|
name: "does not match pattern",
|
||||||
payload: "hello",
|
payload: "hello",
|
||||||
params: map[string]any{"pattern": "world"},
|
params: map[string]any{"pattern": "world"},
|
||||||
expected: nil,
|
match: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "basic regex",
|
name: "basic regex",
|
||||||
payload: "hello world",
|
payload: "hello world",
|
||||||
params: map[string]any{"pattern": ".* world"},
|
params: map[string]any{"pattern": ".* world"},
|
||||||
expected: "hello world",
|
match: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,26 +90,14 @@ func TestGoodStringFilter(t *testing.T) {
|
|||||||
t.Fatalf("filter.regex failed to create processor: %s", err)
|
t.Fatalf("filter.regex failed to create processor: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("filter.regex processing failed: %s", err)
|
t.Fatalf("filter.regex processing failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if test.expected == nil {
|
if got.End != !test.match {
|
||||||
if got != nil {
|
t.Fatalf("filter.regex did not filter properly %+v, expected %+v", got, test.match)
|
||||||
t.Fatalf("filter.regex got %+v, expected nil", got)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
gotString, ok := got.(string)
|
|
||||||
if !ok {
|
|
||||||
t.Fatalf("filter.regex returned a %T payload: %s", got, got)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !reflect.DeepEqual(gotString, test.expected) {
|
|
||||||
t.Fatalf("filter.regex got %+v, expected %+v", gotString, test.expected)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -173,10 +161,10 @@ func TestBadStringFilter(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("filter.regex expected to fail but got payload: %s", got)
|
t.Fatalf("filter.regex expected to fail but got payload: %+v", got)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err.Error() != test.errorString {
|
if err.Error() != test.errorString {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package processor_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
)
|
)
|
||||||
@@ -75,14 +76,14 @@ func TestGoodFloatParse(t *testing.T) {
|
|||||||
t.Fatalf("float.parse failed to create processor: %s", err)
|
t.Fatalf("float.parse failed to create processor: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("float.parse processing failed: %s", err)
|
t.Fatalf("float.parse processing failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gotFloat, ok := got.(float64)
|
gotFloat, ok := got.Payload.(float64)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("float.parse returned a %T payload: %s", got, got)
|
t.Fatalf("float.parse returned a %T payload: %+v", got, got)
|
||||||
}
|
}
|
||||||
if gotFloat != test.expected {
|
if gotFloat != test.expected {
|
||||||
t.Fatalf("float.parse got %f, expected %f", gotFloat, test.expected)
|
t.Fatalf("float.parse got %f, expected %f", gotFloat, test.expected)
|
||||||
@@ -151,7 +152,7 @@ func TestBadFloatParse(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("float.parse expected to fail but succeeded, got: %v", got)
|
t.Fatalf("float.parse expected to fail but succeeded, got: %v", got)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package processor_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
)
|
)
|
||||||
@@ -70,7 +71,7 @@ func TestGoodFloatRandom(t *testing.T) {
|
|||||||
t.Fatalf("float.random failed to create processor: %s", err)
|
t.Fatalf("float.random failed to create processor: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("float.random processing failed: %s", err)
|
t.Fatalf("float.random processing failed: %s", err)
|
||||||
}
|
}
|
||||||
@@ -82,16 +83,16 @@ func TestGoodFloatRandom(t *testing.T) {
|
|||||||
|
|
||||||
var gotFloat float64
|
var gotFloat float64
|
||||||
if bitSize == 32 {
|
if bitSize == 32 {
|
||||||
gotFloat32, ok := got.(float32)
|
gotFloat32, ok := got.Payload.(float32)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("float.random returned a %T payload: %s", got, got)
|
t.Fatalf("float.random returned a %T payload: %+v", got, got)
|
||||||
}
|
}
|
||||||
gotFloat = float64(gotFloat32)
|
gotFloat = float64(gotFloat32)
|
||||||
}
|
}
|
||||||
if bitSize == 64 {
|
if bitSize == 64 {
|
||||||
gotFloat64, ok := got.(float64)
|
gotFloat64, ok := got.Payload.(float64)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("float.random returned a %T payload: %s", got, got)
|
t.Fatalf("float.random returned a %T payload: %+v", got, got)
|
||||||
}
|
}
|
||||||
gotFloat = gotFloat64
|
gotFloat = gotFloat64
|
||||||
}
|
}
|
||||||
@@ -171,10 +172,10 @@ func TestBadFloatRandom(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("float.random expected to fail but got payload: %s", got)
|
t.Fatalf("float.random expected to fail but got payload: %+v", got)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err.Error() != test.errorString {
|
if err.Error() != test.errorString {
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package processor_test
|
package processor_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
freeD "github.com/jwetzell/free-d-go"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
)
|
)
|
||||||
@@ -36,3 +39,841 @@ func TestFreeDCreateFromRegistry(t *testing.T) {
|
|||||||
t.Fatalf("freed.create processor has wrong type: %s", processorInstance.Type())
|
t.Fatalf("freed.create processor has wrong type: %s", processorInstance.Type())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGoodFreeDCreate(t *testing.T) {
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
expected freeD.FreeDPosition
|
||||||
|
params map[string]any
|
||||||
|
payload any
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "basic freed",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "{{.Payload.id}}",
|
||||||
|
"pan": "{{.Payload.pan}}",
|
||||||
|
"tilt": "{{.Payload.tilt}}",
|
||||||
|
"roll": "{{.Payload.roll}}",
|
||||||
|
"posX": "{{.Payload.posX}}",
|
||||||
|
"posY": "{{.Payload.posY}}",
|
||||||
|
"posZ": "{{.Payload.posZ}}",
|
||||||
|
"zoom": "{{.Payload.zoom}}",
|
||||||
|
"focus": "{{.Payload.focus}}",
|
||||||
|
},
|
||||||
|
payload: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
expected: freeD.FreeDPosition{
|
||||||
|
ID: 1,
|
||||||
|
Pan: 180,
|
||||||
|
Tilt: 90,
|
||||||
|
Roll: -180,
|
||||||
|
PosX: 131069,
|
||||||
|
PosY: 131070,
|
||||||
|
PosZ: 131071,
|
||||||
|
Zoom: 66051,
|
||||||
|
Focus: 263430,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
|
registration, ok := processor.ProcessorRegistry["freed.create"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("freed.create processor not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||||
|
Type: "freed.create",
|
||||||
|
Params: test.params,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("freed.create failed to create processor: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("freed.create processing failed: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(got.Payload, test.expected) {
|
||||||
|
t.Fatalf("freed.create got %+v (%T), expected %+v (%T)", got.Payload, got.Payload, test.expected, test.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadFreeDCreate(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
params map[string]any
|
||||||
|
payload any
|
||||||
|
errorString string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "missing id",
|
||||||
|
params: map[string]any{
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "freed.create id error: not found",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "missing pan",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "freed.create pan error: not found",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "missing tilt",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "freed.create tilt error: not found",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "missing roll",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "freed.create roll error: not found",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "missing posX",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "freed.create posX error: not found",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "missing posY",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "freed.create posY error: not found",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "missing posZ",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "freed.create posZ error: not found",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "missing zoom",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "freed.create zoom error: not found",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "missing focus",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
},
|
||||||
|
errorString: "freed.create focus error: not found",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "id not string",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": 1,
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "freed.create id error: not a string",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "pan not string",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": 180,
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "freed.create pan error: not a string",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "tilt not string",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": 90,
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "freed.create tilt error: not a string",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "roll not string",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": -180,
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "freed.create roll error: not a string",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "posX not string",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": 131069,
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "freed.create posX error: not a string",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "posY not string",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": 131070,
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "freed.create posY error: not a string",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "posZ not string",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": 131071,
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "freed.create posZ error: not a string",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "zoom not string",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": 66051,
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "freed.create zoom error: not a string",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "focus not string",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": 263430,
|
||||||
|
},
|
||||||
|
errorString: "freed.create focus error: not a string",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "id template syntax error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "{{",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "template: id:1: unclosed action",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "pan template syntax error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "{{",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "template: pan:1: unclosed action",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "tilt template syntax error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "{{",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "template: tilt:1: unclosed action",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "roll template syntax error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "{{",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "template: roll:1: unclosed action",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "posX template syntax error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "{{",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "template: posX:1: unclosed action",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "posY template syntax error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "{{",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "template: posY:1: unclosed action",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "posZ template syntax error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "{{",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "template: posZ:1: unclosed action",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "zoom template syntax error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "{{",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "template: zoom:1: unclosed action",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "focus template syntax error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "{{",
|
||||||
|
},
|
||||||
|
errorString: "template: focus:1: unclosed action",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "id template error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "{{.Unknown}}",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "template: id:1:2: executing \"id\" at <.Unknown>: can't evaluate field Unknown in type common.WrappedPayload",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "pan template error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "{{.Unknown}}",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "template: pan:1:2: executing \"pan\" at <.Unknown>: can't evaluate field Unknown in type common.WrappedPayload",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "tilt template error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "{{.Unknown}}",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "template: tilt:1:2: executing \"tilt\" at <.Unknown>: can't evaluate field Unknown in type common.WrappedPayload",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "roll template error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "{{.Unknown}}",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "template: roll:1:2: executing \"roll\" at <.Unknown>: can't evaluate field Unknown in type common.WrappedPayload",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "posX template error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "{{.Unknown}}",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "template: posX:1:2: executing \"posX\" at <.Unknown>: can't evaluate field Unknown in type common.WrappedPayload",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "posY template error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "{{.Unknown}}",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "template: posY:1:2: executing \"posY\" at <.Unknown>: can't evaluate field Unknown in type common.WrappedPayload",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "posZ template error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "{{.Unknown}}",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "template: posZ:1:2: executing \"posZ\" at <.Unknown>: can't evaluate field Unknown in type common.WrappedPayload",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "zoom template error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "{{.Unknown}}",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
errorString: "template: zoom:1:2: executing \"zoom\" at <.Unknown>: can't evaluate field Unknown in type common.WrappedPayload",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "focus template error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "{{.Unknown}}",
|
||||||
|
},
|
||||||
|
errorString: "template: focus:1:2: executing \"focus\" at <.Unknown>: can't evaluate field Unknown in type common.WrappedPayload",
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "id number parsing error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "{{.Payload.id}}",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
payload: map[string]any{
|
||||||
|
"id": "not a number",
|
||||||
|
},
|
||||||
|
errorString: "strconv.ParseUint: parsing \"not a number\": invalid syntax",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "pan number parsing error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "{{.Payload.pan}}",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
payload: map[string]any{
|
||||||
|
"pan": "not a number",
|
||||||
|
},
|
||||||
|
errorString: "strconv.ParseFloat: parsing \"not a number\": invalid syntax",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "tilt number parsing error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "{{.Payload.tilt}}",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
payload: map[string]any{
|
||||||
|
"tilt": "not a number",
|
||||||
|
},
|
||||||
|
errorString: "strconv.ParseFloat: parsing \"not a number\": invalid syntax",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "roll number parsing error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "{{.Payload.roll}}",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
payload: map[string]any{
|
||||||
|
"roll": "not a number",
|
||||||
|
},
|
||||||
|
errorString: "strconv.ParseFloat: parsing \"not a number\": invalid syntax",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "posX number parsing error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "{{.Payload.posX}}",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
payload: map[string]any{
|
||||||
|
"posX": "not a number",
|
||||||
|
},
|
||||||
|
errorString: "strconv.ParseFloat: parsing \"not a number\": invalid syntax",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "posY number parsing error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "{{.Payload.posY}}",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
payload: map[string]any{
|
||||||
|
"posY": "not a number",
|
||||||
|
},
|
||||||
|
errorString: "strconv.ParseFloat: parsing \"not a number\": invalid syntax",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "posZ number parsing error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "{{.Payload.posZ}}",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
payload: map[string]any{
|
||||||
|
"posZ": "not a number",
|
||||||
|
},
|
||||||
|
errorString: "strconv.ParseFloat: parsing \"not a number\": invalid syntax",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "zoom number parsing error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "{{.Payload.zoom}}",
|
||||||
|
"focus": "263430",
|
||||||
|
},
|
||||||
|
payload: map[string]any{
|
||||||
|
"zoom": "not a number",
|
||||||
|
},
|
||||||
|
errorString: "strconv.ParseInt: parsing \"not a number\": invalid syntax",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "focus number parsing error",
|
||||||
|
params: map[string]any{
|
||||||
|
"id": "1",
|
||||||
|
"pan": "180",
|
||||||
|
"tilt": "90",
|
||||||
|
"roll": "-180",
|
||||||
|
"posX": "131069",
|
||||||
|
"posY": "131070",
|
||||||
|
"posZ": "131071",
|
||||||
|
"zoom": "66051",
|
||||||
|
"focus": "{{.Payload.focus}}",
|
||||||
|
},
|
||||||
|
payload: map[string]any{
|
||||||
|
"focus": "not a number",
|
||||||
|
},
|
||||||
|
errorString: "strconv.ParseInt: parsing \"not a number\": invalid syntax",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
|
registration, ok := processor.ProcessorRegistry["freed.create"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("freed.create processor not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||||
|
Type: "freed.create",
|
||||||
|
Params: test.params,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
if test.errorString != err.Error() {
|
||||||
|
t.Fatalf("freed.create got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("freed.create expected to fail but succeeded, got: %v", got)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err.Error() != test.errorString {
|
||||||
|
t.Fatalf("freed.create got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package processor_test
|
package processor_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
freeD "github.com/jwetzell/free-d-go"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
)
|
)
|
||||||
@@ -25,3 +28,77 @@ func TestFreeDDecodeFromRegistry(t *testing.T) {
|
|||||||
t.Fatalf("freed.decode processor has wrong type: %s", processorInstance.Type())
|
t.Fatalf("freed.decode processor has wrong type: %s", processorInstance.Type())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGoodFreeDDecode(t *testing.T) {
|
||||||
|
packetEncoder := processor.FreeDDecode{}
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
payload []byte
|
||||||
|
expected any
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "basic freed",
|
||||||
|
payload: []byte{0xd1, 0x01, 0x5a, 0x00, 0x00, 0x2d, 0x00, 0x00, 0xa6, 0x00, 0x00, 0x7f, 0xff, 0x40, 0x7f, 0xff, 0x80, 0x7f, 0xff,
|
||||||
|
0xc0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x00, 0x00, 50,
|
||||||
|
},
|
||||||
|
expected: freeD.FreeDPosition{
|
||||||
|
ID: 1,
|
||||||
|
Pan: 180,
|
||||||
|
Tilt: 90,
|
||||||
|
Roll: -180,
|
||||||
|
PosX: 131069,
|
||||||
|
PosY: 131070,
|
||||||
|
PosZ: 131071,
|
||||||
|
Zoom: 66051,
|
||||||
|
Focus: 263430,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
|
got, err := packetEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("freed.decode processing failed: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO(jwetzell): work out better way to compare the any/any
|
||||||
|
if !reflect.DeepEqual(got.Payload, test.expected) {
|
||||||
|
t.Fatalf("freed.decode got %+v (%T), expected %+v (%T)", got.Payload, got.Payload, test.expected, test.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadFreeDDecode(t *testing.T) {
|
||||||
|
packetEncoder := processor.FreeDDecode{}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
payload any
|
||||||
|
errorString string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "not a byte slice",
|
||||||
|
payload: "test",
|
||||||
|
errorString: "freed.decode processor only accepts a []byte",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
|
got, err := packetEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("freed.decode expected to fail but succeeded, got: %v", got)
|
||||||
|
|
||||||
|
}
|
||||||
|
if err.Error() != test.errorString {
|
||||||
|
t.Fatalf("freed.decode got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package processor_test
|
package processor_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
freeD "github.com/jwetzell/free-d-go"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
)
|
)
|
||||||
@@ -25,3 +28,77 @@ func TestFreeDEncodeFromRegistry(t *testing.T) {
|
|||||||
t.Fatalf("freed.encode processor has wrong type: %s", processorInstance.Type())
|
t.Fatalf("freed.encode processor has wrong type: %s", processorInstance.Type())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGoodFreeDEncode(t *testing.T) {
|
||||||
|
packetEncoder := processor.FreeDEncode{}
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
expected []byte
|
||||||
|
payload any
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "basic freed",
|
||||||
|
expected: []byte{0xd1, 0x01, 0x5a, 0x00, 0x00, 0x2d, 0x00, 0x00, 0xa6, 0x00, 0x00, 0x7f, 0xff, 0x40, 0x7f, 0xff, 0x80, 0x7f, 0xff,
|
||||||
|
0xc0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x00, 0x00, 50,
|
||||||
|
},
|
||||||
|
payload: freeD.FreeDPosition{
|
||||||
|
ID: 1,
|
||||||
|
Pan: 180,
|
||||||
|
Tilt: 90,
|
||||||
|
Roll: -180,
|
||||||
|
PosX: 131069,
|
||||||
|
PosY: 131070,
|
||||||
|
PosZ: 131071,
|
||||||
|
Zoom: 66051,
|
||||||
|
Focus: 263430,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
|
got, err := packetEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("freed.encode processing failed: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO(jwetzell): work out better way to compare the any/any
|
||||||
|
if !reflect.DeepEqual(got.Payload, test.expected) {
|
||||||
|
t.Fatalf("freed.encode got %+v (%T), expected %+v (%T)", got.Payload, got.Payload, test.expected, test.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadFreeDEncode(t *testing.T) {
|
||||||
|
packetEncoder := processor.FreeDEncode{}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
payload any
|
||||||
|
errorString string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "not a FreeD packet",
|
||||||
|
payload: "test",
|
||||||
|
errorString: "freed.encode processor only accepts a FreeDPosition",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
|
got, err := packetEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("freed.encode expected to fail but succeeded, got: %v", got)
|
||||||
|
|
||||||
|
}
|
||||||
|
if err.Error() != test.errorString {
|
||||||
|
t.Fatalf("freed.encode got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -1,8 +1,10 @@
|
|||||||
package processor_test
|
package processor_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
)
|
)
|
||||||
@@ -29,3 +31,133 @@ func TestHTTPRequestCreateFromRegistry(t *testing.T) {
|
|||||||
t.Fatalf("http.request.do processor has wrong type: %s", processorInstance.Type())
|
t.Fatalf("http.request.do processor has wrong type: %s", processorInstance.Type())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGoodHTTPRequestDo(t *testing.T) {
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
expected processor.NATSMessage
|
||||||
|
params map[string]any
|
||||||
|
payload any
|
||||||
|
}{}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
|
registration, ok := processor.ProcessorRegistry["http.request.do"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("http.request.do processor not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||||
|
Type: "http.request.do",
|
||||||
|
Params: test.params,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("http.request.do failed to create processor: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("http.request.do processing failed: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(got.Payload, test.expected) {
|
||||||
|
t.Fatalf("http.request.do got %+v (%T), expected %+v (%T)", got.Payload, got.Payload, test.expected, test.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadHTTPRequestDo(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
params map[string]any
|
||||||
|
payload any
|
||||||
|
errorString string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "missing method",
|
||||||
|
params: map[string]any{"url": "http://example.com"},
|
||||||
|
payload: nil,
|
||||||
|
errorString: "http.request.do method error: not found",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "method not a string",
|
||||||
|
params: map[string]any{
|
||||||
|
"method": 123,
|
||||||
|
"url": "http://example.com",
|
||||||
|
},
|
||||||
|
payload: nil,
|
||||||
|
errorString: "http.request.do method error: not a string",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "missing url",
|
||||||
|
params: map[string]any{
|
||||||
|
"method": "GET",
|
||||||
|
},
|
||||||
|
payload: nil,
|
||||||
|
errorString: "http.request.do url error: not found",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "url not a string",
|
||||||
|
params: map[string]any{
|
||||||
|
"method": "GET",
|
||||||
|
"url": 123,
|
||||||
|
},
|
||||||
|
payload: nil,
|
||||||
|
errorString: "http.request.do url error: not a string",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "url template error",
|
||||||
|
params: map[string]any{
|
||||||
|
"method": "GET",
|
||||||
|
"url": "http://example.com/{{.Unknown}}",
|
||||||
|
},
|
||||||
|
payload: nil,
|
||||||
|
errorString: "template: url:1:21: executing \"url\" at <.Unknown>: can't evaluate field Unknown in type common.WrappedPayload",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "url template syntax error",
|
||||||
|
params: map[string]any{
|
||||||
|
"method": "GET",
|
||||||
|
"url": "http://example.com/{{.MissingEndBrace",
|
||||||
|
},
|
||||||
|
payload: nil,
|
||||||
|
errorString: "template: url:1: unclosed action",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
|
registration, ok := processor.ProcessorRegistry["http.request.do"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("http.request.do processor not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||||
|
Type: "http.request.do",
|
||||||
|
Params: test.params,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
if test.errorString != err.Error() {
|
||||||
|
t.Fatalf("http.request.do got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("http.request.do expected to fail but succeeded, got: %v", got)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err.Error() != test.errorString {
|
||||||
|
t.Fatalf("http.request.do got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package processor_test
|
package processor_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
)
|
)
|
||||||
@@ -29,3 +31,129 @@ func TestHTTPResponseCreateFromRegistry(t *testing.T) {
|
|||||||
t.Fatalf("http.response.create processor has wrong type: %s", processorInstance.Type())
|
t.Fatalf("http.response.create processor has wrong type: %s", processorInstance.Type())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGoodHTTPResponseCreate(t *testing.T) {
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
expected processor.HTTPResponse
|
||||||
|
params map[string]any
|
||||||
|
payload any
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "simple template",
|
||||||
|
expected: processor.HTTPResponse{
|
||||||
|
Status: 200,
|
||||||
|
Body: []byte("Hello, World!"),
|
||||||
|
},
|
||||||
|
params: map[string]any{"status": 200, "bodyTemplate": "Hello, World!"},
|
||||||
|
payload: nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
|
registration, ok := processor.ProcessorRegistry["http.response.create"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("http.response.create processor not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||||
|
Type: "http.response.create",
|
||||||
|
Params: test.params,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("http.response.create failed to create processor: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("http.response.create processing failed: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(got.Payload, test.expected) {
|
||||||
|
t.Fatalf("http.response.create got %+v (%T), expected %+v (%T)", got.Payload, got.Payload, test.expected, test.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadHTTPResponseCreate(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
params map[string]any
|
||||||
|
payload any
|
||||||
|
errorString string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "missing status",
|
||||||
|
params: map[string]any{"bodyTemplate": "Hello, World!"},
|
||||||
|
payload: nil,
|
||||||
|
errorString: "http.response.create status error: not found",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "non-number status",
|
||||||
|
params: map[string]any{"status": "200", "bodyTemplate": "Hello, World!"},
|
||||||
|
payload: nil,
|
||||||
|
errorString: "http.response.create status error: not a number",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "missing bodyTemplate",
|
||||||
|
params: map[string]any{"status": 200},
|
||||||
|
payload: nil,
|
||||||
|
errorString: "http.response.create bodyTemplate error: not found",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "non-string bodyTemplate",
|
||||||
|
params: map[string]any{"status": 200, "bodyTemplate": 123},
|
||||||
|
payload: nil,
|
||||||
|
errorString: "http.response.create bodyTemplate error: not a string",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "bodyTemplate template error",
|
||||||
|
params: map[string]any{"status": 200, "bodyTemplate": "{{.MissingField}}"},
|
||||||
|
payload: nil,
|
||||||
|
errorString: "template: body:1:2: executing \"body\" at <.MissingField>: can't evaluate field MissingField in type common.WrappedPayload",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "bodyTemplate template syntax error",
|
||||||
|
params: map[string]any{"status": 200, "bodyTemplate": "{{.MissingField"},
|
||||||
|
payload: nil,
|
||||||
|
errorString: "template: body:1: unclosed action",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
|
registration, ok := processor.ProcessorRegistry["http.response.create"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("http.response.create processor not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||||
|
Type: "http.response.create",
|
||||||
|
Params: test.params,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
if test.errorString != err.Error() {
|
||||||
|
t.Fatalf("http.response.create got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("http.response.create expected to fail but succeeded, got: %v", got)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err.Error() != test.errorString {
|
||||||
|
t.Fatalf("http.response.create got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package processor_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
)
|
)
|
||||||
@@ -96,14 +97,14 @@ func TestGoodIntParse(t *testing.T) {
|
|||||||
t.Fatalf("int.parse failed to create processor: %s", err)
|
t.Fatalf("int.parse failed to create processor: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("int.parse processing failed: %s", err)
|
t.Fatalf("int.parse processing failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gotInt, ok := got.(int64)
|
gotInt, ok := got.Payload.(int64)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("int.parse returned a %T payload: %s", got, got)
|
t.Fatalf("int.parse returned a %T payload: %+v", got, got)
|
||||||
}
|
}
|
||||||
if gotInt != test.expected {
|
if gotInt != test.expected {
|
||||||
t.Fatalf("int.parse got %d, expected %d", gotInt, test.expected)
|
t.Fatalf("int.parse got %d, expected %d", gotInt, test.expected)
|
||||||
@@ -185,7 +186,7 @@ func TestBadIntParse(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("int.parse expected to fail but succeeded, got: %v", got)
|
t.Fatalf("int.parse expected to fail but succeeded, got: %v", got)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package processor_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
)
|
)
|
||||||
@@ -50,14 +51,14 @@ func TestIntRandomGoodConfig(t *testing.T) {
|
|||||||
|
|
||||||
payload := "12345"
|
payload := "12345"
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), payload))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("int.random processing failed: %s", err)
|
t.Fatalf("int.random processing failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gotInt, ok := got.(int)
|
gotInt, ok := got.Payload.(int)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("int.random returned a %T payload: %s", got, got)
|
t.Fatalf("int.random returned a %T payload: %+v", got, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
if gotInt < 1 || gotInt > 10 {
|
if gotInt < 1 || gotInt > 10 {
|
||||||
@@ -97,14 +98,14 @@ func TestGoodIntRandom(t *testing.T) {
|
|||||||
t.Fatalf("int.random failed to create processor: %s", err)
|
t.Fatalf("int.random failed to create processor: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("int.random processing failed: %s", err)
|
t.Fatalf("int.random processing failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gotInt, ok := got.(int)
|
gotInt, ok := got.Payload.(int)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("int.random returned a %T payload: %s", got, got)
|
t.Fatalf("int.random returned a %T payload: %+v", got, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
minNum, ok := test.params["min"].(int)
|
minNum, ok := test.params["min"].(int)
|
||||||
@@ -182,10 +183,10 @@ func TestBadIntRandom(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("int.random expected to fail but got payload: %s", got)
|
t.Fatalf("int.random expected to fail but got payload: %+v", got)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err.Error() != test.errorString {
|
if err.Error() != test.errorString {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package processor_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
)
|
)
|
||||||
@@ -68,14 +69,14 @@ func TestGoodIntScale(t *testing.T) {
|
|||||||
t.Fatalf("int.scale failed to create processor: %s", err)
|
t.Fatalf("int.scale failed to create processor: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("int.scale processing failed: %s", err)
|
t.Fatalf("int.scale processing failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gotInt, ok := got.(int)
|
gotInt, ok := got.Payload.(int)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("int.scale returned a %T payload: %s", got, got)
|
t.Fatalf("int.scale returned a %T payload: %+v", got, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
if gotInt != test.expected {
|
if gotInt != test.expected {
|
||||||
@@ -156,10 +157,10 @@ func TestBadIntScale(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("int.scale expected to fail but got payload: %s", got)
|
t.Fatalf("int.scale expected to fail but got payload: %+v", got)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err.Error() != test.errorString {
|
if err.Error() != test.errorString {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
)
|
)
|
||||||
@@ -31,12 +32,12 @@ func TestJsonDecodeFromRegistry(t *testing.T) {
|
|||||||
"property": "hello",
|
"property": "hello",
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), payload))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("json.decode processing failed: %s", err)
|
t.Fatalf("json.decode processing failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gotMap, ok := got.(map[string]any)
|
gotMap, ok := got.Payload.(map[string]any)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("json.decode should return byte slice")
|
t.Fatalf("json.decode should return byte slice")
|
||||||
@@ -74,18 +75,18 @@ func TestGoodJsonDecode(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
got, err := jsonDecoder.Process(t.Context(), test.payload)
|
got, err := jsonDecoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("json.decode processing failed: %s", err)
|
t.Fatalf("json.decode processing failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gotMap, ok := got.(map[string]any)
|
gotMap, ok := got.Payload.(map[string]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("json.decode returned a %T payload: %s", got, got)
|
t.Fatalf("json.decode returned a %T payload: %+v", got, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(gotMap, test.expected) {
|
if !reflect.DeepEqual(gotMap, test.expected) {
|
||||||
t.Fatalf("json.decode got %x, expected %s", got, test.expected)
|
t.Fatalf("json.decode got %+v, expected %s", got, test.expected)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -112,7 +113,7 @@ func TestBadJsonDecode(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
got, err := stringEncoder.Process(t.Context(), test.payload)
|
got, err := stringEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("json.decode expected to fail but got payload: %+v", got)
|
t.Fatalf("json.decode expected to fail but got payload: %+v", got)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/jwetzell/osc-go"
|
"github.com/jwetzell/osc-go"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
)
|
)
|
||||||
@@ -34,15 +35,15 @@ func TestJsonEncodeFromRegistry(t *testing.T) {
|
|||||||
|
|
||||||
expected := []byte("{\"property\":\"hello\"}")
|
expected := []byte("{\"property\":\"hello\"}")
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), payload))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("json.encode processing failed: %s", err)
|
t.Fatalf("json.encode processing failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gotBytes, ok := got.([]byte)
|
gotBytes, ok := got.Payload.([]byte)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("json.encode should return byte slice")
|
t.Fatalf("json.encode should return byte slice got %T: %+v", got.Payload, got.Payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !slices.Equal(gotBytes, expected) {
|
if !slices.Equal(gotBytes, expected) {
|
||||||
@@ -68,18 +69,18 @@ func TestGoodJsonEncode(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
got, err := jsonEncoder.Process(t.Context(), test.payload)
|
got, err := jsonEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("json.encode processing failed: %s", err)
|
t.Fatalf("json.encode processing failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gotBytes, ok := got.([]byte)
|
gotBytes, ok := got.Payload.([]byte)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("json.encode returned a %T payload: %s", got, got)
|
t.Fatalf("json.encode returned a %T payload: %+v", got.Payload, got.Payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !slices.Equal(gotBytes, test.expected) {
|
if !slices.Equal(gotBytes, test.expected) {
|
||||||
t.Fatalf("json.encode got %x, expected %s", got, test.expected)
|
t.Fatalf("json.encode got %+v, expected %s", got, test.expected)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -101,7 +102,7 @@ func TestBadJsonEncode(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
got, err := stringEncoder.Process(t.Context(), test.payload)
|
got, err := stringEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("json.encode expected to fail but got payload: %+v", got)
|
t.Fatalf("json.encode expected to fail but got payload: %+v", got)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
"gitlab.com/gomidi/midi/v2"
|
"gitlab.com/gomidi/midi/v2"
|
||||||
@@ -103,14 +104,14 @@ func TestGoodMIDIMessageCreate(t *testing.T) {
|
|||||||
t.Fatalf("midi.message.create failed to create processor: %s", err)
|
t.Fatalf("midi.message.create failed to create processor: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("midi.message.create processing failed: %s", err)
|
t.Fatalf("midi.message.create processing failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gotMessage, ok := got.(midi.Message)
|
gotMessage, ok := got.Payload.(midi.Message)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("midi.message.create returned a %T payload: %s", got, got)
|
t.Fatalf("midi.message.create returned a %T payload: %+v", got, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(gotMessage, test.expected) {
|
if !reflect.DeepEqual(gotMessage, test.expected) {
|
||||||
@@ -274,12 +275,12 @@ func TestBadMIDIMessageCreate(t *testing.T) {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if test.errorString != err.Error() {
|
if test.errorString != err.Error() {
|
||||||
t.Fatalf("string.create got error '%s', expected '%s'", err.Error(), test.errorString)
|
t.Fatalf("midi.message.create got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("midi.message.create expected to fail but succeeded, got: %v", got)
|
t.Fatalf("midi.message.create expected to fail but succeeded, got: %v", got)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
"gitlab.com/gomidi/midi/v2"
|
"gitlab.com/gomidi/midi/v2"
|
||||||
@@ -44,14 +45,14 @@ func TestGoodMIDIMessageDecode(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("midi.message.decode processing failed: %s", err)
|
t.Fatalf("midi.message.decode processing failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gotMessage, ok := got.(midi.Message)
|
gotMessage, ok := got.Payload.(midi.Message)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("midi.message.decode returned a %T payload: %s", got, got)
|
t.Fatalf("midi.message.decode returned a %T payload: %+v", got, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(gotMessage, test.expected) {
|
if !reflect.DeepEqual(gotMessage, test.expected) {
|
||||||
@@ -78,7 +79,7 @@ func TestBadMIDIMessageDecode(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("midi.message.decode expected to fail but succeeded, got: %v", got)
|
t.Fatalf("midi.message.decode expected to fail but succeeded, got: %v", got)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"slices"
|
"slices"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
"gitlab.com/gomidi/midi/v2"
|
"gitlab.com/gomidi/midi/v2"
|
||||||
@@ -44,14 +45,14 @@ func TestGoodMIDIMessageEncode(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
got, err := midiMessageEncoder.Process(t.Context(), test.payload)
|
got, err := midiMessageEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("midi.message.encode processing failed: %s", err)
|
t.Fatalf("midi.message.encode processing failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gotBytes, ok := got.([]byte)
|
gotBytes, ok := got.Payload.([]byte)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("midi.message.encode returned a %T payload: %s", got, got)
|
t.Fatalf("midi.message.encode returned a %T payload: %+v", got, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !slices.Equal(gotBytes, test.expected) {
|
if !slices.Equal(gotBytes, test.expected) {
|
||||||
@@ -77,10 +78,10 @@ func TestBadMIDIMessageEncode(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
got, err := midiMessageEncoder.Process(t.Context(), test.payload)
|
got, err := midiMessageEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("midi.message.encode expected to fail but got payload: %s", got)
|
t.Fatalf("midi.message.encode expected to fail but got payload: %+v", got)
|
||||||
}
|
}
|
||||||
if err.Error() != test.errorString {
|
if err.Error() != test.errorString {
|
||||||
t.Fatalf("midi.message.encode got error '%s', expected '%s'", err.Error(), test.errorString)
|
t.Fatalf("midi.message.encode got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package processor_test
|
package processor_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
|
"gitlab.com/gomidi/midi/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMIDIMessageUnpackFromRegistry(t *testing.T) {
|
func TestMIDIMessageUnpackFromRegistry(t *testing.T) {
|
||||||
@@ -25,3 +28,125 @@ func TestMIDIMessageUnpackFromRegistry(t *testing.T) {
|
|||||||
t.Fatalf("midi.message.unpack processor has wrong type: %s", processorInstance.Type())
|
t.Fatalf("midi.message.unpack processor has wrong type: %s", processorInstance.Type())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGoodMIDIMessageUnpack(t *testing.T) {
|
||||||
|
processorInstance := &processor.MIDIMessageUnpack{}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
expected any
|
||||||
|
params map[string]any
|
||||||
|
payload any
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "note on",
|
||||||
|
payload: midi.NoteOn(1, 60, 127),
|
||||||
|
expected: processor.MIDINoteOn{
|
||||||
|
Channel: 1,
|
||||||
|
Note: 60,
|
||||||
|
Velocity: 127,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "note off",
|
||||||
|
payload: midi.NoteOffVelocity(1, 60, 127),
|
||||||
|
expected: processor.MIDINoteOff{
|
||||||
|
Channel: 1,
|
||||||
|
Note: 60,
|
||||||
|
Velocity: 127,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "control change",
|
||||||
|
payload: midi.ControlChange(1, 64, 127),
|
||||||
|
expected: processor.MIDIControlChange{
|
||||||
|
Channel: 1,
|
||||||
|
Control: 64,
|
||||||
|
Value: 127,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "program change",
|
||||||
|
payload: midi.ProgramChange(1, 10),
|
||||||
|
expected: processor.MIDIProgramChange{
|
||||||
|
Channel: 1,
|
||||||
|
Program: 10,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "pitch bend",
|
||||||
|
payload: midi.Message{0xE1, 0x00, 0x40},
|
||||||
|
expected: processor.MIDIPitchBend{
|
||||||
|
Channel: 1,
|
||||||
|
Relative: 0,
|
||||||
|
Absolute: 8192,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("midi.message.unpack processing failed: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(got.Payload, test.expected) {
|
||||||
|
t.Fatalf("midi.message.unpack got %+v (%T), expected %+v (%T)", got.Payload, got.Payload, test.expected, test.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadMIDIMessageUnpack(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
params map[string]any
|
||||||
|
payload any
|
||||||
|
errorString string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "payload not a MIDI message",
|
||||||
|
payload: "not a MIDI message",
|
||||||
|
errorString: "midi.message.unpack processor only accepts a midi.Message",
|
||||||
|
params: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "unsupported MIDI message type",
|
||||||
|
payload: midi.Message{0x00, 0x00, 0x00},
|
||||||
|
errorString: "midi.message.unpack message type not supported UnknownType",
|
||||||
|
params: nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
|
registration, ok := processor.ProcessorRegistry["midi.message.unpack"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("midi.message.unpack processor not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||||
|
Type: "midi.message.unpack",
|
||||||
|
Params: test.params,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
if test.errorString != err.Error() {
|
||||||
|
t.Fatalf("midi.message.unpack got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("midi.message.unpack expected to fail but succeeded, got: %v", got)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err.Error() != test.errorString {
|
||||||
|
t.Fatalf("midi.message.unpack got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
)
|
)
|
||||||
@@ -103,22 +104,22 @@ func TestGoodMQTTMessageCreate(t *testing.T) {
|
|||||||
t.Fatalf("mqtt.message.create failed to create processor: %s", err)
|
t.Fatalf("mqtt.message.create failed to create processor: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("mqtt.message.create processing failed: %s", err)
|
t.Fatalf("mqtt.message.create processing failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if test.expected == nil {
|
if test.expected == nil {
|
||||||
if got != nil {
|
if got.Payload != nil {
|
||||||
t.Fatalf("mqtt.message.create got %+v, expected nil", got)
|
t.Fatalf("mqtt.message.create got %+v, expected nil", got)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
gotMessage, ok := got.(mqtt.Message)
|
gotMessage, ok := got.Payload.(mqtt.Message)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("mqtt.message.create returned a %T payload: %s", got, got)
|
t.Fatalf("mqtt.message.create returned a %T payload: %+v", got, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(gotMessage, test.expected) {
|
if !reflect.DeepEqual(gotMessage, test.expected) {
|
||||||
@@ -227,7 +228,7 @@ func TestBadMQTTMessageCreate(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("mqtt.message.create expected to fail but succeeded, got: %v", got)
|
t.Fatalf("mqtt.message.create expected to fail but succeeded, got: %v", got)
|
||||||
|
|||||||
@@ -1,90 +0,0 @@
|
|||||||
package processor_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"slices"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestMQTTMessageEncodeFromRegistry(t *testing.T) {
|
|
||||||
registration, ok := processor.ProcessorRegistry["mqtt.message.encode"]
|
|
||||||
if !ok {
|
|
||||||
t.Fatalf("mqtt.message.encode processor not registered")
|
|
||||||
}
|
|
||||||
|
|
||||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
|
||||||
Type: "mqtt.message.encode",
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to create mqtt.message.encode processor: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if processorInstance.Type() != "mqtt.message.encode" {
|
|
||||||
t.Fatalf("mqtt.message.encode processor has wrong type: %s", processorInstance.Type())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGoodMQTTMessageEncode(t *testing.T) {
|
|
||||||
stringEncoder := processor.MQTTMessageEncode{}
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
payload mqtt.Message
|
|
||||||
expected []byte
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "basic string",
|
|
||||||
payload: processor.NewMQTTMessage("test/topic", 1, true, []byte("hello")),
|
|
||||||
expected: []byte{0x68, 0x65, 0x6c, 0x6c, 0x6f},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, test := range tests {
|
|
||||||
t.Run(test.name, func(t *testing.T) {
|
|
||||||
got, err := stringEncoder.Process(t.Context(), test.payload)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("mqtt.message.encode processing failed: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
gotBytes, ok := got.([]byte)
|
|
||||||
if !ok {
|
|
||||||
t.Fatalf("mqtt.message.encode returned a %T payload: %s", got, got)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !slices.Equal(gotBytes, test.expected) {
|
|
||||||
t.Fatalf("mqtt.message.encode got %s, expected %s", got, test.expected)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBadMQTTMessageEncode(t *testing.T) {
|
|
||||||
stringEncoder := processor.MQTTMessageEncode{}
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
payload any
|
|
||||||
errorString string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "non-mqtt message input",
|
|
||||||
payload: []byte{0x68, 0x65, 0x6c, 0x6c, 0x6f},
|
|
||||||
errorString: "mqtt.message.encode processor only accepts an mqtt.Message",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, test := range tests {
|
|
||||||
t.Run(test.name, func(t *testing.T) {
|
|
||||||
got, err := stringEncoder.Process(t.Context(), test.payload)
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
t.Fatalf("mqtt.message.encode expected to fail but got payload: %s", got)
|
|
||||||
}
|
|
||||||
if err.Error() != test.errorString {
|
|
||||||
t.Fatalf("mqtt.message.encode got error '%s', expected '%s'", err.Error(), test.errorString)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
package processor_test
|
package processor_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
)
|
)
|
||||||
@@ -29,3 +31,180 @@ func TestNATSMessageCreateFromRegistry(t *testing.T) {
|
|||||||
t.Fatalf("nats.message.create processor has wrong type: %s", processorInstance.Type())
|
t.Fatalf("nats.message.create processor has wrong type: %s", processorInstance.Type())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGoodNATSMessageCreate(t *testing.T) {
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
expected processor.NATSMessage
|
||||||
|
params map[string]any
|
||||||
|
payload any
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "simple payload",
|
||||||
|
params: map[string]any{
|
||||||
|
"subject": "test",
|
||||||
|
"payload": "Hello, World!",
|
||||||
|
},
|
||||||
|
payload: nil,
|
||||||
|
expected: processor.NATSMessage{
|
||||||
|
Subject: "test",
|
||||||
|
Payload: []byte("Hello, World!"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "payload with template",
|
||||||
|
params: map[string]any{
|
||||||
|
"subject": "test",
|
||||||
|
"payload": "Hello, {{.Payload.Name}}!",
|
||||||
|
},
|
||||||
|
payload: map[string]any{
|
||||||
|
"Name": "Alice",
|
||||||
|
},
|
||||||
|
expected: processor.NATSMessage{
|
||||||
|
Subject: "test",
|
||||||
|
Payload: []byte("Hello, Alice!"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
|
registration, ok := processor.ProcessorRegistry["nats.message.create"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("nats.message.create processor not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||||
|
Type: "nats.message.create",
|
||||||
|
Params: test.params,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("nats.message.create failed to create processor: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("nats.message.create processing failed: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(got.Payload, test.expected) {
|
||||||
|
t.Fatalf("nats.message.create got %+v (%T), expected %+v (%T)", got.Payload, got.Payload, test.expected, test.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadNATSMessageCreate(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
params map[string]any
|
||||||
|
payload any
|
||||||
|
errorString string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "missing subject param",
|
||||||
|
params: map[string]any{
|
||||||
|
"payload": "Hello, World!",
|
||||||
|
},
|
||||||
|
payload: nil,
|
||||||
|
errorString: "nats.message.create subject error: not found",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "subject param not a string",
|
||||||
|
params: map[string]any{
|
||||||
|
"subject": 123,
|
||||||
|
"payload": "Hello, World!",
|
||||||
|
},
|
||||||
|
payload: nil,
|
||||||
|
errorString: "nats.message.create subject error: not a string",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "missing payload param",
|
||||||
|
params: map[string]any{
|
||||||
|
"subject": "test",
|
||||||
|
},
|
||||||
|
payload: nil,
|
||||||
|
errorString: "nats.message.create payload error: not found",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "payload param not a string",
|
||||||
|
params: map[string]any{
|
||||||
|
"subject": "test",
|
||||||
|
"payload": 123,
|
||||||
|
},
|
||||||
|
payload: nil,
|
||||||
|
errorString: "nats.message.create payload error: not a string",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "payload template error",
|
||||||
|
params: map[string]any{
|
||||||
|
"subject": "test",
|
||||||
|
"payload": "Hello, {{.Payload.Name}}!",
|
||||||
|
},
|
||||||
|
payload: nil,
|
||||||
|
errorString: "template: payload:1:17: executing \"payload\" at <.Payload.Name>: nil pointer evaluating interface {}.Name",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "subject template error",
|
||||||
|
params: map[string]any{
|
||||||
|
"subject": "test.{{.Payload.Name}}",
|
||||||
|
"payload": "Hello, World!",
|
||||||
|
},
|
||||||
|
payload: nil,
|
||||||
|
errorString: "template: subject:1:15: executing \"subject\" at <.Payload.Name>: nil pointer evaluating interface {}.Name",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "subject template syntax error",
|
||||||
|
params: map[string]any{
|
||||||
|
"subject": "{{.Payload.Name",
|
||||||
|
"payload": "Hello, World!",
|
||||||
|
},
|
||||||
|
payload: nil,
|
||||||
|
errorString: "template: subject:1: unclosed action",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "payload template syntax error",
|
||||||
|
params: map[string]any{
|
||||||
|
"subject": "test",
|
||||||
|
"payload": "Hello, {{.Payload.Name",
|
||||||
|
},
|
||||||
|
payload: nil,
|
||||||
|
errorString: "template: payload:1: unclosed action",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
|
registration, ok := processor.ProcessorRegistry["nats.message.create"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("nats.message.create processor not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||||
|
Type: "nats.message.create",
|
||||||
|
Params: test.params,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
if test.errorString != err.Error() {
|
||||||
|
t.Fatalf("nats.message.create got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("nats.message.create expected to fail but succeeded, got: %v", got)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err.Error() != test.errorString {
|
||||||
|
t.Fatalf("nats.message.create got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/jwetzell/osc-go"
|
"github.com/jwetzell/osc-go"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
)
|
)
|
||||||
@@ -149,22 +150,22 @@ func TestGoodOSCMessageCreate(t *testing.T) {
|
|||||||
t.Fatalf("osc.message.create failed to create processor: %s", err)
|
t.Fatalf("osc.message.create failed to create processor: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("osc.message.create processing failed: %s", err)
|
t.Fatalf("osc.message.create processing failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if test.expected == nil {
|
if test.expected == nil {
|
||||||
if got != nil {
|
if got.Payload != nil {
|
||||||
t.Fatalf("osc.message.create got %+v, expected nil", got)
|
t.Fatalf("osc.message.create got %+v, expected nil", got)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
gotMessage, ok := got.(*osc.OSCMessage)
|
gotMessage, ok := got.Payload.(*osc.OSCMessage)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("osc.message.create returned a %T payload: %s", got, got)
|
t.Fatalf("osc.message.create returned a %T payload: %+v", got, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(gotMessage, test.expected) {
|
if !reflect.DeepEqual(gotMessage, test.expected) {
|
||||||
@@ -286,7 +287,7 @@ func TestBadOSCMessageCreate(t *testing.T) {
|
|||||||
"address": "/test/{{.missing}}",
|
"address": "/test/{{.missing}}",
|
||||||
},
|
},
|
||||||
payload: "test",
|
payload: "test",
|
||||||
errorString: "template: address:1:8: executing \"address\" at <.missing>: can't evaluate field missing in type processor.TemplateData",
|
errorString: "template: address:1:8: executing \"address\" at <.missing>: can't evaluate field missing in type common.WrappedPayload",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "address doesn't start with slash",
|
name: "address doesn't start with slash",
|
||||||
@@ -304,7 +305,7 @@ func TestBadOSCMessageCreate(t *testing.T) {
|
|||||||
"types": "s",
|
"types": "s",
|
||||||
},
|
},
|
||||||
payload: "test",
|
payload: "test",
|
||||||
errorString: "template: arg:1:2: executing \"arg\" at <.missing>: can't evaluate field missing in type processor.TemplateData",
|
errorString: "template: arg:1:2: executing \"arg\" at <.missing>: can't evaluate field missing in type common.WrappedPayload",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,7 +328,7 @@ func TestBadOSCMessageCreate(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("osc.message.create expected to fail but succeeded, got: %v", got)
|
t.Fatalf("osc.message.create expected to fail but succeeded, got: %v", got)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/jwetzell/osc-go"
|
"github.com/jwetzell/osc-go"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
)
|
)
|
||||||
@@ -60,15 +61,15 @@ func TestGoodOSCMessageDecode(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("osc.message.decode processing failed: %s", err)
|
t.Fatalf("osc.message.decode processing failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gotMessage, ok := got.(*osc.OSCMessage)
|
gotMessage, ok := got.Payload.(*osc.OSCMessage)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("osc.message.decode returned a %T payload: %s", got, got)
|
t.Fatalf("osc.message.decode returned a %T payload: %+v", got, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(gotMessage, test.expected) {
|
if !reflect.DeepEqual(gotMessage, test.expected) {
|
||||||
@@ -109,10 +110,10 @@ func TestBadOSCMessageDecode(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("osc.message.decode expected to fail but got payload: %s", got)
|
t.Fatalf("osc.message.decode expected to fail but got payload: %+v", got)
|
||||||
}
|
}
|
||||||
if err.Error() != test.errorString {
|
if err.Error() != test.errorString {
|
||||||
t.Fatalf("osc.message.decode got error '%s', expected '%s'", err.Error(), test.errorString)
|
t.Fatalf("osc.message.decode got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/jwetzell/osc-go"
|
"github.com/jwetzell/osc-go"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
)
|
)
|
||||||
@@ -59,14 +60,14 @@ func TestGoodOSCMessageEncode(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("osc.message.encode processing failed: %s", err)
|
t.Fatalf("osc.message.encode processing failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gotBytes, ok := got.([]byte)
|
gotBytes, ok := got.Payload.([]byte)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("osc.message.encode returned a %T payload: %s", got, got)
|
t.Fatalf("osc.message.encode returned a %T payload: %+v", got, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !slices.Equal(gotBytes, test.expected) {
|
if !slices.Equal(gotBytes, test.expected) {
|
||||||
@@ -92,10 +93,10 @@ func TestBadOSCMessageEncode(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("osc.message.encode expected to fail but got payload: %s", got)
|
t.Fatalf("osc.message.encode expected to fail but got payload: %+v", got)
|
||||||
}
|
}
|
||||||
if err.Error() != test.errorString {
|
if err.Error() != test.errorString {
|
||||||
t.Fatalf("osc.message.encode got error '%s', expected '%s'", err.Error(), test.errorString)
|
t.Fatalf("osc.message.encode got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user