Compare commits

..

91 Commits

Author SHA1 Message Date
Joel Wetzell
66f170047a remove arm images for now 2026-02-08 22:02:33 -06:00
Joel Wetzell
7ff20e0136 add more tests for string.split 2026-02-08 21:50:31 -06:00
Joel Wetzell
b53494fddc add more error tests for string.filter 2026-02-08 21:49:30 -06:00
Joel Wetzell
3688510ded fix test names 2026-02-08 21:49:12 -06:00
Joel Wetzell
d0bdc44c30 add test for string.filter 2026-02-08 21:40:53 -06:00
Joel Wetzell
1c49548a4c test cleanup 2026-02-08 21:38:44 -06:00
Joel Wetzell
4ea6c8f11f test cleanup 2026-02-08 21:31:08 -06:00
Joel Wetzell
0ef512eb28 add registry test for json.decode 2026-02-08 21:23:21 -06:00
Joel Wetzell
ebbce3261c add registry test for json.encode 2026-02-08 21:21:28 -06:00
Joel Wetzell
79fa925823 clean up json.encode test 2026-02-08 21:21:14 -06:00
Joel Wetzell
659c95102b Merge pull request #57 from jwetzell/feat/json-decode-processor
add json.decode processor
2026-02-08 21:15:55 -06:00
Joel Wetzell
e06c4195c7 add json.decode processor 2026-02-08 21:13:34 -06:00
Joel Wetzell
28e3c99ad8 add test loading from registry for time.sleep 2026-02-08 15:56:33 -06:00
Joel Wetzell
7312bfec20 add error tests for random processors 2026-02-08 15:56:14 -06:00
Joel Wetzell
4bbf69e644 add test for artnet.packet.filter 2026-02-08 15:55:48 -06:00
Joel Wetzell
1ba51446ad fix error messages in test 2026-02-08 15:55:32 -06:00
Joel Wetzell
2266d6a9b8 Merge pull request #56 from jwetzell/feat/json-schema
add json schema definitions for config
2026-02-08 15:04:25 -06:00
Joel Wetzell
f1f340f963 add schema for rest of processors 2026-02-08 13:34:40 -06:00
Joel Wetzell
4ca989280c switch interval and timer to new namespace 2026-02-08 09:45:22 -06:00
Joel Wetzell
ef83e84e84 add schema for time.sleep processor 2026-02-08 09:45:22 -06:00
Joel Wetzell
b8ad912855 add JSON schema for config file 2026-02-08 09:45:22 -06:00
Joel Wetzell
f766d0e2a4 Merge pull request #55 from jwetzell/feat/router-reload
reload router config on SIGHUP
2026-02-08 09:44:49 -06:00
Joel Wetzell
725e8ad670 add mutex for router operations 2026-02-07 17:07:18 -06:00
Joel Wetzell
7fa3b6d33d TODO 2026-02-07 16:29:49 -06:00
Joel Wetzell
5e957d7d03 expose running config from router 2026-02-07 16:28:06 -06:00
Joel Wetzell
bd89df3da2 create app struct 2026-02-07 14:15:24 -06:00
Joel Wetzell
914f6aa833 mess around with being able to reload router 2026-02-07 13:42:55 -06:00
Joel Wetzell
2104d9f1a9 change to start/stop not run/stop 2026-02-07 12:51:01 -06:00
Joel Wetzell
457ff83c23 add more convenience methods for start/stopping modules on router 2026-02-07 12:48:27 -06:00
Joel Wetzell
37c7a23063 add debug log at beginning of running 2026-02-07 12:40:30 -06:00
Joel Wetzell
9ba3a88e8c add removeModule function to router 2026-02-07 09:53:48 -06:00
Joel Wetzell
33ecc94097 add Stop function to module 2026-02-07 09:53:38 -06:00
Joel Wetzell
8f5091cf9b load router from context in mock module 2026-02-05 20:20:00 -06:00
Joel Wetzell
b095419b6e switch module instances to map on id 2026-02-05 20:02:03 -06:00
Joel Wetzell
1e872ba0b9 fix RouteIO interface 2026-02-05 19:51:09 -06:00
Joel Wetzell
b959b88527 split out module and route creation in router and router output only does one module 2026-02-05 19:31:31 -06:00
Joel Wetzell
0dfbf30fa7 Merge pull request #54 from jwetzell/feat/opentelemetry
add option to export open telemetry tracing
2026-02-04 19:22:15 -06:00
Joel Wetzell
abff674a75 fix router test 2026-02-04 19:17:57 -06:00
Joel Wetzell
a920f34926 rework route and processing spans 2026-02-04 19:01:18 -06:00
Joel Wetzell
4dac1faae0 add basic opentelemetry 2026-02-04 19:01:18 -06:00
Joel Wetzell
ab5b40ee72 remove osc.message.transform 2026-02-04 18:39:16 -06:00
Joel Wetzell
5a29139e63 Merge pull request #53 from jwetzell/chore/testing
add more testing
2026-02-04 18:38:18 -06:00
Joel Wetzell
1587f84981 add test for uint.random processor 2026-02-04 18:30:51 -06:00
Joel Wetzell
0cb13a30f9 add test for int.random processor 2026-02-04 18:30:41 -06:00
Joel Wetzell
8212d15a70 add test for module with no id 2026-02-04 18:30:25 -06:00
Joel Wetzell
eee356225f Merge pull request #52 from jwetzell/fix/debug-log-payload-string
more compatible printing of payload in debug.log
2026-02-03 22:52:20 -06:00
Joel Wetzell
5cd02f9e3a more compatible printing of payload in debug.log 2026-02-03 22:50:30 -06:00
Joel Wetzell
100edab869 Merge pull request #51 from jwetzell/fix/no-default-framing-method
don't default framing method
2026-02-03 22:28:47 -06:00
Joel Wetzell
fd4c2cb59b make framing parameter required in net.tcp.client 2026-02-03 22:27:58 -06:00
Joel Wetzell
b6ee3c68f1 don't default framing method 2026-02-03 22:26:16 -06:00
Joel Wetzell
7e0c2b2560 Merge pull request #48 from jwetzell/dependabot/github_actions/docker/login-action-3.7.0
Bump docker/login-action from 3.6.0 to 3.7.0
2026-02-03 11:35:37 -06:00
Joel Wetzell
c9a3eb80bc Merge pull request #50 from jwetzell/dependabot/go_modules/github.com/emiago/diago-0.26.2
Bump github.com/emiago/diago from 0.25.0 to 0.26.2
2026-02-03 11:35:13 -06:00
dependabot[bot]
2a5feec07a Bump github.com/emiago/diago from 0.25.0 to 0.26.2
Bumps [github.com/emiago/diago](https://github.com/emiago/diago) from 0.25.0 to 0.26.2.
- [Release notes](https://github.com/emiago/diago/releases)
- [Commits](https://github.com/emiago/diago/compare/v0.25.0...v0.26.2)

---
updated-dependencies:
- dependency-name: github.com/emiago/diago
  dependency-version: 0.26.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-02 23:54:12 +00:00
dependabot[bot]
ced4bc839e Bump docker/login-action from 3.6.0 to 3.7.0
Bumps [docker/login-action](https://github.com/docker/login-action) from 3.6.0 to 3.7.0.
- [Release notes](https://github.com/docker/login-action/releases)
- [Commits](5e57cd1181...c94ce9fb46)

---
updated-dependencies:
- dependency-name: docker/login-action
  dependency-version: 3.7.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-02 23:53:47 +00:00
Joel Wetzell
ce6a9ff4a8 update labeler 2026-02-02 13:14:11 -06:00
Joel Wetzell
bd3b8a19d5 Merge pull request #47 from jwetzell/fix/module-id-required
add check to prevent empty module Id
2026-02-02 13:00:36 -06:00
Joel Wetzell
cb738a9b8e combine route and router labels 2026-02-02 12:59:50 -06:00
Joel Wetzell
1b59dbc1e5 add router to labeler 2026-02-02 12:55:23 -06:00
Joel Wetzell
c75a2327d5 add check to prevent empty module Id 2026-02-02 12:51:56 -06:00
Joel Wetzell
a17be985e6 todo 2026-02-01 20:52:58 -06:00
Joel Wetzell
78737f57af Merge pull request #46 from jwetzell/chore/upgrade-artnet
update artnet dependency
2026-01-31 19:32:12 -06:00
Joel Wetzell
720c0cd52a update artnet dependency 2026-01-31 19:29:30 -06:00
Joel Wetzell
3e1d4f07f9 Merge pull request #43 from jwetzell/dependabot/go_modules/github.com/emiago/diago-0.25.0
Bump github.com/emiago/diago from 0.24.0 to 0.25.0
2026-01-20 11:47:43 -06:00
dependabot[bot]
452e308f8f Bump github.com/emiago/diago from 0.24.0 to 0.25.0
Bumps [github.com/emiago/diago](https://github.com/emiago/diago) from 0.24.0 to 0.25.0.
- [Release notes](https://github.com/emiago/diago/releases)
- [Commits](https://github.com/emiago/diago/compare/v0.24.0...v0.25.0)

---
updated-dependencies:
- dependency-name: github.com/emiago/diago
  dependency-version: 0.25.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-01-20 17:38:15 +00:00
Joel Wetzell
d16d833520 Merge pull request #44 from jwetzell/dependabot/go_modules/github.com/emiago/sipgo-1.1.1
Bump github.com/emiago/sipgo from 1.1.0 to 1.1.1
2026-01-20 11:37:02 -06:00
Joel Wetzell
f203b32261 Merge pull request #45 from jwetzell/dependabot/go_modules/github.com/urfave/cli/v3-3.6.2
Bump github.com/urfave/cli/v3 from 3.6.1 to 3.6.2
2026-01-20 11:36:51 -06:00
dependabot[bot]
361c4f4499 Bump github.com/urfave/cli/v3 from 3.6.1 to 3.6.2
Bumps [github.com/urfave/cli/v3](https://github.com/urfave/cli) from 3.6.1 to 3.6.2.
- [Release notes](https://github.com/urfave/cli/releases)
- [Changelog](https://github.com/urfave/cli/blob/main/docs/CHANGELOG.md)
- [Commits](https://github.com/urfave/cli/compare/v3.6.1...v3.6.2)

---
updated-dependencies:
- dependency-name: github.com/urfave/cli/v3
  dependency-version: 3.6.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-01-19 19:15:13 +00:00
dependabot[bot]
a76d12d799 Bump github.com/emiago/sipgo from 1.1.0 to 1.1.1
Bumps [github.com/emiago/sipgo](https://github.com/emiago/sipgo) from 1.1.0 to 1.1.1.
- [Release notes](https://github.com/emiago/sipgo/releases)
- [Commits](https://github.com/emiago/sipgo/compare/v1.1.0...v1.1.1)

---
updated-dependencies:
- dependency-name: github.com/emiago/sipgo
  dependency-version: 1.1.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-01-19 19:14:56 +00:00
Joel Wetzell
7d91e64ec4 add complete test coverage for string processors 2026-01-17 20:42:37 -06:00
Joel Wetzell
589c59c693 fix label for cli 2026-01-17 20:02:50 -06:00
Joel Wetzell
56c67c5445 Merge pull request #42 from jwetzell/feat/nats-message-create-subject-template
allow subject to be a template in nats.message.create
2026-01-17 19:31:53 -06:00
Joel Wetzell
13229215a6 allow subject to be a template in nats.message.create 2026-01-17 19:27:40 -06:00
Joel Wetzell
909b4d2337 add TODO 2026-01-17 19:24:21 -06:00
Joel Wetzell
3bcb9a6608 Merge pull request #41 from jwetzell/fix/dtmf-create-rune-check
return error if DTMF create results in invalid characters
2026-01-17 18:40:53 -06:00
Joel Wetzell
17dcffc09b return error if dtmf create results in invalid characters 2026-01-17 18:39:54 -06:00
Joel Wetzell
8318645eef Merge pull request #40 from jwetzell/chore/router-context-handling
move router context to run methods
2026-01-16 19:04:21 -06:00
Joel Wetzell
0c777a8874 move router context to run methods 2026-01-16 18:50:40 -06:00
Joel Wetzell
a8f9894ff0 Merge pull request #39 from jwetzell/feat/wasm-module
add WASM processor
2026-01-14 17:56:33 -06:00
Joel Wetzell
f0f74f50e5 allow specifying function name to call 2026-01-14 17:53:37 -06:00
Joel Wetzell
bb3a8b982b add script.wasm via extism plugins 2026-01-14 17:50:16 -06:00
Joel Wetzell
be9ce5a8aa update to versioned artnet library 2026-01-14 17:35:31 -06:00
Joel Wetzell
ac2cf078a4 Remove debug print statement from SIPCallServer 2026-01-14 09:38:57 -06:00
Joel Wetzell
0fc264d0e9 Merge pull request #38 from jwetzell/dependabot/go_modules/github.com/emiago/sipgo-1.0.2
Bump github.com/emiago/sipgo from 1.0.1 to 1.0.2
2026-01-14 09:02:28 -06:00
dependabot[bot]
3c99eef999 Bump github.com/emiago/sipgo from 1.0.1 to 1.0.2
Bumps [github.com/emiago/sipgo](https://github.com/emiago/sipgo) from 1.0.1 to 1.0.2.
- [Release notes](https://github.com/emiago/sipgo/releases)
- [Commits](https://github.com/emiago/sipgo/compare/v1.0.1...v1.0.2)

---
updated-dependencies:
- dependency-name: github.com/emiago/sipgo
  dependency-version: 1.0.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-01-14 15:01:01 +00:00
Joel Wetzell
f7c3a85649 Merge pull request #37 from jwetzell/dependabot/go_modules/github.com/emiago/diago-0.24.0
Bump github.com/emiago/diago from 0.23.1-0.20251211215055-e1d875617111 to 0.24.0
2026-01-14 08:59:30 -06:00
dependabot[bot]
76caccd9f8 Bump github.com/emiago/diago
Bumps [github.com/emiago/diago](https://github.com/emiago/diago) from 0.23.1-0.20251211215055-e1d875617111 to 0.24.0.
- [Release notes](https://github.com/emiago/diago/releases)
- [Commits](https://github.com/emiago/diago/commits/v0.24.0)

---
updated-dependencies:
- dependency-name: github.com/emiago/diago
  dependency-version: 0.24.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-01-12 21:31:51 +00:00
Joel Wetzell
e8c71562a6 update artnet-go 2025-12-30 11:58:48 -06:00
Joel Wetzell
42551127ba Merge pull request #36 from jwetzell/dependabot/go_modules/modernc.org/quickjs-0.17.1
Bump modernc.org/quickjs from 0.17.0 to 0.17.1
2025-12-29 16:11:25 -06:00
Joel Wetzell
a99fef9389 Merge pull request #35 from jwetzell/dependabot/github_actions/docker/setup-buildx-action-3.12.0
Bump docker/setup-buildx-action from 3.11.1 to 3.12.0
2025-12-29 16:11:16 -06:00
dependabot[bot]
ac83b339a6 Bump modernc.org/quickjs from 0.17.0 to 0.17.1
Bumps [modernc.org/quickjs](https://gitlab.com/cznic/quickjs) from 0.17.0 to 0.17.1.
- [Commits](https://gitlab.com/cznic/quickjs/compare/v0.17.0...v0.17.1)

---
updated-dependencies:
- dependency-name: modernc.org/quickjs
  dependency-version: 0.17.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-12-29 17:28:41 +00:00
dependabot[bot]
cb06e2dbb5 Bump docker/setup-buildx-action from 3.11.1 to 3.12.0
Bumps [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) from 3.11.1 to 3.12.0.
- [Release notes](https://github.com/docker/setup-buildx-action/releases)
- [Commits](e468171a9d...8d2750c68a)

---
updated-dependencies:
- dependency-name: docker/setup-buildx-action
  dependency-version: 3.12.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-12-29 17:28:19 +00:00
49 changed files with 3565 additions and 506 deletions

4
.github/labeler.yml vendored
View File

@@ -14,6 +14,10 @@ processor:
- changed-files:
- any-glob-to-any-file: 'internal/processor/**'
router:
- changed-files:
- any-glob-to-any-file: 'router*'
route:
- changed-files:
- any-glob-to-any-file: 'internal/route/**'

5
.github/release.yml vendored
View File

@@ -17,12 +17,13 @@ changelog:
- title: Processor 🏭
labels:
- processor
- title: Route 🛣️
- title: Routing 🛣️
labels:
- router
- route
- title: CLI ⌨️
labels:
- cmd
- cli
- title: Other Changes
labels:
- '*'

View File

@@ -40,10 +40,10 @@ jobs:
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
- name: Login to Docker Hub
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
@@ -65,4 +65,4 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64,linux/arm/v7
platforms: linux/amd64

View File

@@ -9,15 +9,23 @@ import (
"os/signal"
"slices"
"sync"
"syscall"
"github.com/jwetzell/showbridge-go"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/urfave/cli/v3"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.39.0"
"go.opentelemetry.io/otel/trace"
"sigs.k8s.io/yaml"
)
var (
version = "dev"
version = "dev"
sigHangup = make(chan os.Signal, 1)
)
func main() {
@@ -55,11 +63,18 @@ func main() {
return nil
},
},
&cli.BoolFlag{
Name: "trace",
Value: false,
Usage: "enable OpenTelemetry tracing",
},
},
Action: run,
}
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
signal.Notify(sigHangup, syscall.SIGHUP)
defer cancel()
err := cmd.Run(ctx, os.Args)
@@ -69,6 +84,16 @@ func main() {
}
type showbridgeApp struct {
ctx context.Context
configPath string
logger *slog.Logger
router *showbridge.Router
routerRunner *sync.WaitGroup
tracer trace.Tracer
routerMutex sync.Mutex
}
func readConfig(configPath string) (config.Config, error) {
cfg := config.Config{}
@@ -89,12 +114,7 @@ func readConfig(configPath string) (config.Config, error) {
func run(ctx context.Context, c *cli.Command) error {
configPath := c.String("config")
if configPath == "" {
return errors.New("config value cannot be empty")
}
config, err := readConfig(configPath)
if err != nil {
return err
return errors.New("config path cannot be empty")
}
logLevel := slog.LevelInfo
@@ -135,28 +155,117 @@ func run(ctx context.Context, c *cli.Command) error {
slog.SetDefault(slog.New(logHandler))
commandLogger := slog.Default().With("component", "cmd")
var tracer trace.Tracer
if c.Bool("trace") {
exporter, err := otlptracehttp.New(ctx)
if err != nil {
return fmt.Errorf("failed to create trace exporter: %w", err)
}
router, moduleErrors, routeErrors := showbridge.NewRouter(context.Background(), config)
tracerProvider := newTracerProvider(exporter)
otel.SetTracerProvider(tracerProvider)
defer tracerProvider.Shutdown(ctx)
tracer = tracerProvider.Tracer("showbridge")
} else {
tracer = otel.Tracer("showbridge")
}
showbridgeApp := &showbridgeApp{
ctx: ctx,
configPath: configPath,
logger: slog.Default().With("component", "cmd"),
routerRunner: &sync.WaitGroup{},
tracer: tracer,
}
router, err := showbridgeApp.getNewRouter()
if err != nil {
return fmt.Errorf("failed to initialize router: %w", err)
}
showbridgeApp.routerMutex.Lock()
showbridgeApp.router = router
showbridgeApp.routerRunner.Go(func() {
router.Start(context.Background())
})
showbridgeApp.routerMutex.Unlock()
go showbridgeApp.handleHangup()
<-showbridgeApp.ctx.Done()
showbridgeApp.logger.Debug("shutting down router")
showbridgeApp.router.Stop()
showbridgeApp.logger.Debug("waiting for router to exit")
showbridgeApp.routerRunner.Wait()
return nil
}
func (app *showbridgeApp) handleHangup() {
for {
select {
case <-sigHangup:
app.logger.Info("received SIGHUP, reloading configuration")
newRouter, err := app.getNewRouter()
if err != nil {
app.logger.Error("failed to reload configuration", "error", err)
continue
}
app.routerMutex.Lock()
app.router.Stop()
app.routerRunner.Wait()
app.router = newRouter
app.routerRunner.Go(func() {
app.router.Start(context.Background())
})
app.logger.Info("configuration reloaded successfully")
app.routerMutex.Unlock()
case <-app.ctx.Done():
return
}
}
}
func (app *showbridgeApp) getNewRouter() (*showbridge.Router, error) {
// TODO(jwetzell): what should happen when the config file is unchanged?
config, err := readConfig(app.configPath)
if err != nil {
return nil, err
}
router, moduleErrors, routeErrors := showbridge.NewRouter(config, app.tracer)
for _, moduleError := range moduleErrors {
commandLogger.Error("problem initializing module", "index", moduleError.Index, "error", moduleError.Error)
app.logger.Error("problem initializing module", "index", moduleError.Index, "error", moduleError.Error)
}
for _, routeError := range routeErrors {
commandLogger.Error("problem initializing route", "index", routeError.Index, "error", routeError.Error)
app.logger.Error("problem initializing route", "index", routeError.Index, "error", routeError.Error)
}
routerRunner := sync.WaitGroup{}
if moduleErrors != nil || routeErrors != nil {
return nil, fmt.Errorf("errors initializing modules or routes")
}
routerRunner.Go(func() {
router.Run()
})
<-ctx.Done()
commandLogger.Debug("shutting down router")
router.Stop()
commandLogger.Debug("waiting for router to exit")
routerRunner.Wait()
return nil
return router, nil
}
func newTracerProvider(exp sdktrace.SpanExporter) *sdktrace.TracerProvider {
r, err := resource.Merge(
resource.Default(),
resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceName("showbridge"),
semconv.ServiceVersion(version),
),
)
if err != nil {
panic(err)
}
return sdktrace.NewTracerProvider(
sdktrace.WithBatcher(exp),
sdktrace.WithResource(r),
)
}

46
go.mod
View File

@@ -4,53 +4,79 @@ go 1.25.5
require (
github.com/eclipse/paho.mqtt.golang v1.5.1
github.com/emiago/diago v0.23.1-0.20251211215055-e1d875617111
github.com/emiago/sipgo v1.0.1
github.com/emiago/diago v0.26.2
github.com/emiago/sipgo v1.1.2
github.com/expr-lang/expr v1.17.7
github.com/jwetzell/artnet-go v0.0.0-20251223201031-5097901aa9db
github.com/extism/go-sdk v1.7.1
github.com/jwetzell/artnet-go v0.2.1
github.com/jwetzell/free-d-go v0.1.0
github.com/jwetzell/osc-go v0.1.0
github.com/jwetzell/psn-go v0.3.0
github.com/nats-io/nats.go v1.48.0
github.com/urfave/cli/v3 v3.6.1
github.com/urfave/cli/v3 v3.6.2
gitlab.com/gomidi/midi/v2 v2.3.18
go.bug.st/serial v1.6.4
modernc.org/quickjs v0.17.0
go.opentelemetry.io/otel v1.40.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0
go.opentelemetry.io/otel/sdk v1.40.0
go.opentelemetry.io/otel/trace v1.40.0
modernc.org/quickjs v0.17.1
sigs.k8s.io/yaml v1.6.0
)
require (
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/creack/goselect v0.1.2 // indirect
github.com/dustin/go-humanize v1.0.1 // 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/go-audio/riff v1.0.0 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect
github.com/gobwas/ws v1.4.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.21.0 // indirect
github.com/ianlancetaylor/demangle v0.0.0-20240805132620-81f5be970eca // indirect
github.com/icholy/digest v1.1.0 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/nats-io/nkeys v0.4.11 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/ncruces/go-strftime v1.0.0 // indirect
github.com/pion/logging v0.2.4 // indirect
github.com/pion/randutil v0.1.0 // indirect
github.com/pion/rtcp v1.2.16 // indirect
github.com/pion/rtp v1.8.26 // indirect
github.com/pion/srtp/v3 v3.0.9 // indirect
github.com/pion/transport/v3 v3.1.1 // indirect
github.com/pion/transport/v4 v4.0.1 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834 // indirect
github.com/tetratelabs/wazero v1.9.0 // indirect
github.com/zaf/g711 v1.4.0 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.40.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
golang.org/x/crypto v0.42.0 // indirect
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect
golang.org/x/net v0.44.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.39.0 // indirect
golang.org/x/sys v0.40.0 // indirect
golang.org/x/text v0.29.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/hraban/opus.v2 v2.0.0-20230925203106-0188a62cb302 // indirect
modernc.org/libc v1.66.10 // indirect
modernc.org/libquickjs v0.12.2 // indirect
modernc.org/libc v1.67.1 // indirect
modernc.org/libquickjs v0.12.3 // indirect
modernc.org/mathutil v1.7.1 // indirect
modernc.org/memory v1.11.0 // indirect
)

109
go.sum
View File

@@ -1,19 +1,36 @@
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/creack/goselect v0.1.2 h1:2DNy14+JPjRBgPzAd1thbQp4BSIihxcBf0IXhQXDRa0=
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/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/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/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/emiago/diago v0.23.1-0.20251211215055-e1d875617111 h1:jqhOZbH40pf2jiUhGaBNk334wOtNYvAaXg/mHOXhy/Y=
github.com/emiago/diago v0.23.1-0.20251211215055-e1d875617111/go.mod h1:3vLCCq8/G/Ei5I64IHtrmBTag+nPLcgXcKeN1KkLtuc=
github.com/emiago/sipgo v1.0.1 h1:8eCZ6L/VX3isyByyv1RrBoQ5GyBoRXBHkNMYjwacRfk=
github.com/emiago/sipgo v1.0.1/go.mod h1:DuwAxBZhKMqIzQFPGZb1MVAGU6Wuxj64oTOhd5dx/FY=
github.com/emiago/diago v0.26.2 h1:3QL03V0drX96eIBFBpfueNcywydRgYqffKihluGL0gA=
github.com/emiago/diago v0.26.2/go.mod h1:jZ+7EnKcmgqKnLjCHPqfbP4Y/9Q/JLSLxMflDrp2J1M=
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/sipgo v1.1.2 h1:JvLqEvqNSQm2mBX40qZ7O0WC3Ee67Z0UrfmBI7y6Beo=
github.com/emiago/sipgo v1.1.2/go.mod h1:DuwAxBZhKMqIzQFPGZb1MVAGU6Wuxj64oTOhd5dx/FY=
github.com/expr-lang/expr v1.17.7 h1:Q0xY/e/2aCIp8g9s/LGvMDCC5PxYlvHgDZRQ4y16JX8=
github.com/expr-lang/expr v1.17.7/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
github.com/extism/go-sdk v1.7.1 h1:lWJos6uY+tRFdlIHR+SJjwFDApY7OypS/2nMhiVQ9Sw=
github.com/extism/go-sdk v1.7.1/go.mod h1:IT+Xdg5AZM9hVtpFUA+uZCJMge/hbvshl8bwzLtFyKA=
github.com/go-audio/riff v1.0.0 h1:d8iCGbDvox9BfLagY94fBynxSPHO80LmZCaOsmKxokA=
github.com/go-audio/riff v1.0.0/go.mod h1:l3cQwc85y79NQFCRB7TiPoNiaijp6q8Z0Uv38rVG498=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
@@ -26,12 +43,16 @@ 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/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.21.0 h1:CWyXh/jylQWp2dtiV33mY4iSSp6yf4lmn+c7/tN+ObI=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.21.0/go.mod h1:nCLIt0w3Ept2NwF8ThLmrppXsfT07oC8k0XNDxd8sVU=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/ianlancetaylor/demangle v0.0.0-20240805132620-81f5be970eca h1:T54Ema1DU8ngI+aef9ZhAhNGQhcRTrWxVeG07F+c/Rw=
github.com/ianlancetaylor/demangle v0.0.0-20240805132620-81f5be970eca/go.mod h1:gx7rwoVhcfuVKG5uya9Hs3Sxj7EIvldVofAWIUtGouw=
github.com/icholy/digest v1.1.0 h1:HfGg9Irj7i+IX1o1QAmPfIBNu/Q5A5Tu3n/MED9k9H4=
github.com/icholy/digest v1.1.0/go.mod h1:QNrsSGQ5v7v9cReDI0+eyjsXGUoRSUZQHeQ5C4XLa0Y=
github.com/jwetzell/artnet-go v0.0.0-20251223201031-5097901aa9db h1:PR9sdDEWBufi8/3yiQHRXncLNKUHBMKiEBDtdNWsK/E=
github.com/jwetzell/artnet-go v0.0.0-20251223201031-5097901aa9db/go.mod h1:gli97Z32a0kMkZ6taoTiK7/lqHcF/dhiGjGJdx/PxqA=
github.com/jwetzell/artnet-go v0.2.1 h1:iYTKWcwYrF5kBkYfkw2UbWvoueeA23iKEn7fR27mWZE=
github.com/jwetzell/artnet-go v0.2.1/go.mod h1:gli97Z32a0kMkZ6taoTiK7/lqHcF/dhiGjGJdx/PxqA=
github.com/jwetzell/free-d-go v0.1.0 h1:xHt6dvyit98X+OC3jVzV0aLidxbyzi3vI9QiYkteEtA=
github.com/jwetzell/free-d-go v0.1.0/go.mod h1:KmrkooRARRaxJTBSPvwt/6IMAIaHH1R8bSA8cwbbELw=
github.com/jwetzell/osc-go v0.1.0 h1:EXxup5VWBErHot2Ri4MFToPf6KCzLDTbCt2x6GLfw8I=
@@ -52,8 +73,8 @@ github.com/nats-io/nkeys v0.4.11 h1:q44qGV008kYd9W1b1nEBkNzvnWxtRSQ7A8BoqRrcfa0=
github.com/nats-io/nkeys v0.4.11/go.mod h1:szDimtgmfOi9n25JpfIdGw12tZFYXqhGxjhVxsatHVE=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/pion/logging v0.2.4 h1:tTew+7cmQ+Mc1pTBLKH2puKsOvhm32dROumOZ655zB8=
github.com/pion/logging v0.2.4/go.mod h1:DffhXTKYdNZU+KtJ5pyQDjvOAh/GsNSyv1lbkFbe3so=
github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA=
@@ -66,41 +87,77 @@ github.com/pion/srtp/v3 v3.0.9 h1:lRGF4G61xxj+m/YluB3ZnBpiALSri2lTzba0kGZMrQY=
github.com/pion/srtp/v3 v3.0.9/go.mod h1:E+AuWd7Ug2Fp5u38MKnhduvpVkveXJX6J4Lq4rxUYt8=
github.com/pion/transport/v3 v3.1.1 h1:Tr684+fnnKlhPceU+ICdrw6KKkTms+5qHMgw6bIkYOM=
github.com/pion/transport/v3 v3.1.1/go.mod h1:+c2eewC5WJQHiAA46fkMMzoYZSuGzA/7E2FPrOYHctQ=
github.com/pion/transport/v4 v4.0.1 h1:sdROELU6BZ63Ab7FrOLn13M6YdJLY20wldXW2Cu2k8o=
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/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
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/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/urfave/cli/v3 v3.6.1 h1:j8Qq8NyUawj/7rTYdBGrxcH7A/j7/G8Q5LhWEW4G3Mo=
github.com/urfave/cli/v3 v3.6.1/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834 h1:ZF+QBjOI+tILZjBaFj3HgFonKXUcwgJ4djLb6i42S3Q=
github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834/go.mod h1:m9ymHTgNSEjuxvw8E7WWe4Pl4hZQHXONY8wE6dMLaRk=
github.com/tetratelabs/wazero v1.9.0 h1:IcZ56OuxrtaEz8UYNRHBrUa9bYeX9oVY93KspZZBf/I=
github.com/tetratelabs/wazero v1.9.0/go.mod h1:TSbcXCfFP0L2FGkRPxHphadXPjo1T6W+CseNNY7EkjM=
github.com/urfave/cli/v3 v3.6.2 h1:lQuqiPrZ1cIz8hz+HcrG0TNZFxU70dPZ3Yl+pSrH9A8=
github.com/urfave/cli/v3 v3.6.2/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
github.com/zaf/g711 v1.4.0 h1:XZYkjjiAg9QTBnHqEg37m2I9q3IIDv5JRYXs2N8ma7c=
github.com/zaf/g711 v1.4.0/go.mod h1:eCDXt3dSp/kYYAoooba7ukD/Q75jvAaS4WOMr0l1Roo=
gitlab.com/gomidi/midi/v2 v2.3.18 h1:sj2fOhtvOe+zI8YJe8qTxLw5zv0ntULLUDwcFOaZQbI=
gitlab.com/gomidi/midi/v2 v2.3.18/go.mod h1:jDpP4O4skYi+7iVwt6Zyp18bd2M4hkjtMuw2cmgKgfw=
go.bug.st/serial v1.6.4 h1:7FmqNPgVp3pu2Jz5PoPtbZ9jJO5gnEnZIvnI1lzve8A=
go.bug.st/serial v1.6.4/go.mod h1:nofMJxTeNVny/m6+KaafC6vJGj3miwQZ6vW4BZUGJPI=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
go.opentelemetry.io/otel v1.40.0 h1:oA5YeOcpRTXq6NN7frwmwFR0Cn3RhTVZvXsP4duvCms=
go.opentelemetry.io/otel v1.40.0/go.mod h1:IMb+uXZUKkMXdPddhwAHm6UfOwJyh4ct1ybIlV14J0g=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 h1:3Q/xZUyC1BBkualc9ROb4G8qkH90LXEIICcs5zv1OYY=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0/go.mod h1:s75jGIWA9OfCMzF0xr+ZgfrB5FEbbV7UuYo32ahUiFI=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0 h1:j9+03ymgYhPKmeXGk5Zu+cIZOlVzd9Zv7QIiyItjFBU=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0/go.mod h1:Y5+XiUG4Emn1hTfciPzGPJaSI+RpDts6BnCIir0SLqk=
go.opentelemetry.io/otel/metric v1.40.0 h1:rcZe317KPftE2rstWIBitCdVp89A2HqjkxR3c11+p9g=
go.opentelemetry.io/otel/metric v1.40.0/go.mod h1:ib/crwQH7N3r5kfiBZQbwrTge743UDc7DTFVZrrXnqc=
go.opentelemetry.io/otel/sdk v1.40.0 h1:KHW/jUzgo6wsPh9At46+h4upjtccTmuZCFAc9OJ71f8=
go.opentelemetry.io/otel/sdk v1.40.0/go.mod h1:Ph7EFdYvxq72Y8Li9q8KebuYUr2KoeyHx0DRMKrYBUE=
go.opentelemetry.io/otel/sdk/metric v1.40.0 h1:mtmdVqgQkeRxHgRv4qhyJduP3fYJRMX4AtAlbuWdCYw=
go.opentelemetry.io/otel/sdk/metric v1.40.0/go.mod h1:4Z2bGMf0KSK3uRjlczMOeMhKU2rhUqdWNoKcYrtcBPg=
go.opentelemetry.io/otel/trace v1.40.0 h1:WA4etStDttCSYuhwvEa8OP8I5EWu24lkOzp+ZYblVjw=
go.opentelemetry.io/otel/trace v1.40.0/go.mod h1:zeAhriXecNGP/s2SEG3+Y8X9ujcJOTqQ5RgdEJcawiA=
go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0=
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
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/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
go.yaml.in/yaml/v3 v3.0.3 h1:bXOww4E/J3f66rav3pX3m8w6jDE4knZjGOw8b5Y6iNE=
go.yaml.in/yaml/v3 v3.0.3/go.mod h1:tBHosrYAkRZjRAOREWbDnBXUf08JOwYq++0QNwQiWzI=
golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI=
golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8=
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b h1:M2rDM6z3Fhozi9O7NWsxAkg/yqS/lQJ6PmkyIV3YP+o=
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8=
golang.org/x/mod v0.29.0 h1:HV8lRxZC4l2cr3Zq1LvtOsi/ThTgWnUk/y64QSs8GwA=
golang.org/x/mod v0.29.0/go.mod h1:NyhrlYXJ2H4eJiRy/WDBO6HMqZQ6q9nk4JzS3NuCK+w=
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 h1:mgKeJMpvi0yx/sU5GsxQ7p6s2wtOnGAHZWCHUM4KGzY=
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70=
golang.org/x/mod v0.30.0 h1:fDEXFVZ/fmCKProc/yAXXUijritrDzahmwwefnjoPFk=
golang.org/x/mod v0.30.0/go.mod h1:lAsf5O2EvJeSFMiBxXDki7sCgAxEUcZHXoXMKT4GJKc=
golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I=
golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/tools v0.37.0 h1:DVSRzp7FwePZW356yEAChSdNcQo6Nsp+fex1SUW09lE=
golang.org/x/tools v0.37.0/go.mod h1:MBN5QPQtLMHVdvsbtarmTNukZDdgwdwlO5qGacAzF0w=
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
golang.org/x/tools v0.38.0 h1:Hx2Xv8hISq8Lm16jvBZ2VQf+RLmbd7wVUsALibYI/IQ=
golang.org/x/tools v0.38.0/go.mod h1:yEsQ/d/YK8cjh0L6rZlY8tgtlKiBNTL14pGDJPJpYQs=
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 h1:wKguEg1hsxI2/L3hUYrpo1RVi48K+uTyzKqprwLXsb8=
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142/go.mod h1:d6be+8HhtEtucleCbxpPW9PA9XwISACu8nvpPqF0BVo=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:e7S5W7MGGLaSu8j3YjdezkZ+m1/Nm0uRVRMEMGk26Xs=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
@@ -122,18 +179,18 @@ modernc.org/gc/v3 v3.1.1 h1:k8T3gkXWY9sEiytKhcgyiZ2L0DTyCQ/nvX+LoCljoRE=
modernc.org/gc/v3 v3.1.1/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY=
modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks=
modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
modernc.org/libc v1.66.10 h1:yZkb3YeLx4oynyR+iUsXsybsX4Ubx7MQlSYEw4yj59A=
modernc.org/libc v1.66.10/go.mod h1:8vGSEwvoUoltr4dlywvHqjtAqHBaw0j1jI7iFBTAr2I=
modernc.org/libquickjs v0.12.2 h1:XtF6iD+aoN/pEz1MAQjg1wMZT412pzmOlO11UGLW/wQ=
modernc.org/libquickjs v0.12.2/go.mod h1:n+vyuJ4mXh1pQYt1bJttvoCE+2t+MqCM8BFlcSDg/70=
modernc.org/libc v1.67.1 h1:bFaqOaa5/zbWYJo8aW0tXPX21hXsngG2M7mckCnFSVk=
modernc.org/libc v1.67.1/go.mod h1:QvvnnJ5P7aitu0ReNpVIEyesuhmDLQ8kaEoyMjIFZJA=
modernc.org/libquickjs v0.12.3 h1:2IU9B6njBmce2PuYttJDkXeoLRV9WnvgP+eU5HAC8YI=
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/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
modernc.org/opt v0.1.4 h1:2kNGMRiUjrp4LcaPuLY2PzUfqM/w9N23quVwhKt5Qm8=
modernc.org/opt v0.1.4/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
modernc.org/quickjs v0.17.0 h1:gYZRSCKVokyOiHhZEKwran/NoBaGjAaWk+xJq52SWfQ=
modernc.org/quickjs v0.17.0/go.mod h1:TE+wpAYX4V7Nvi/sHRUrd9l5L176ZIiS0as3MMObvC0=
modernc.org/quickjs v0.17.1 h1:CbYnbTf7ksZk9YZ1rRM2Ab1Zfi+X6s50kXiOhpd2NIg=
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/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=

View File

@@ -17,20 +17,15 @@ type HTTPClient struct {
client *http.Client
router route.RouteIO
logger *slog.Logger
cancel context.CancelFunc
}
func init() {
RegisterModule(ModuleRegistration{
Type: "http.client",
New: func(ctx context.Context, config config.ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return nil, errors.New("http.client unable to get router from context")
}
return &HTTPClient{config: config, ctx: ctx, router: router, logger: CreateLogger(config)}, nil
return &HTTPClient{config: config, logger: CreateLogger(config)}, nil
},
})
}
@@ -43,7 +38,17 @@ func (hc *HTTPClient) Type() string {
return hc.config.Type
}
func (hc *HTTPClient) Run() error {
func (hc *HTTPClient) Start(ctx context.Context) error {
hc.logger.Debug("running")
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return errors.New("http.client unable to get router from context")
}
hc.router = router
moduleContext, cancel := context.WithCancel(ctx)
hc.ctx = moduleContext
hc.cancel = cancel
hc.client = &http.Client{
Timeout: 10 * time.Second,
@@ -78,3 +83,7 @@ func (hc *HTTPClient) Output(ctx context.Context, payload any) error {
return nil
}
func (hc *HTTPClient) Stop() {
hc.cancel()
}

View File

@@ -19,13 +19,14 @@ type HTTPServer struct {
ctx context.Context
router route.RouteIO
logger *slog.Logger
cancel context.CancelFunc
}
type ResponseIOError struct {
Index int `json:"index"`
OutputErrors []string `json:"outputErrors"`
ProcessError *string `json:"processError"`
InputError *string `json:"inputError"`
Index int `json:"index"`
OutputError *string `json:"outputError"`
ProcessError *string `json:"processError"`
InputError *string `json:"inputError"`
}
type IOResponseData struct {
@@ -54,7 +55,7 @@ func (hsrw *HTTPServerResponseWriter) Write(data []byte) (int, error) {
func init() {
RegisterModule(ModuleRegistration{
Type: "http.server",
New: func(ctx context.Context, config config.ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
port, ok := params["port"]
if !ok {
@@ -67,13 +68,7 @@ func init() {
return nil, errors.New("http.server port must be uint16")
}
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return nil, errors.New("http.server unable to get router from context")
}
return &HTTPServer{Port: uint16(portNum), config: config, ctx: ctx, router: router, logger: CreateLogger(config)}, nil
return &HTTPServer{Port: uint16(portNum), config: config, logger: CreateLogger(config)}, nil
},
})
}
@@ -119,14 +114,9 @@ func (hs *HTTPServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
errorToAdd.ProcessError = &errorMsg
}
if responseIOError.OutputErrors != nil {
outputErrorMsgs := []string{}
for _, outputError := range responseIOError.OutputErrors {
outputErrorMsgs = append(outputErrorMsgs, outputError.Error())
}
errorToAdd.OutputErrors = outputErrorMsgs
if responseIOError.OutputError != nil {
errorMsg := responseIOError.OutputError.Error()
errorToAdd.OutputError = &errorMsg
}
response.IOErrors = append(response.IOErrors, errorToAdd)
@@ -157,7 +147,18 @@ func (hs *HTTPServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
func (hs *HTTPServer) Run() error {
func (hs *HTTPServer) Start(ctx context.Context) error {
hs.logger.Debug("running")
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return errors.New("http.server unable to get router from context")
}
hs.router = router
moduleContext, cancel := context.WithCancel(ctx)
hs.ctx = moduleContext
hs.cancel = cancel
httpServer := &http.Server{
Addr: fmt.Sprintf(":%d", hs.Port),
Handler: hs,
@@ -202,3 +203,7 @@ func (hs *HTTPServer) Output(ctx context.Context, payload any) error {
responseWriter.Write(payloadResponse.Body)
return nil
}
func (hs *HTTPServer) Stop() {
hs.cancel()
}

View File

@@ -21,12 +21,13 @@ type MIDIInput struct {
Port string
SendFunc func(midi.Message) error
logger *slog.Logger
cancel context.CancelFunc
}
func init() {
RegisterModule(ModuleRegistration{
Type: "midi.input",
New: func(ctx context.Context, config config.ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
port, ok := params["port"]
@@ -40,13 +41,7 @@ func init() {
return nil, errors.New("midi.input port must be a string")
}
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return nil, errors.New("midi.input unable to get router from context")
}
return &MIDIInput{config: config, Port: portString, ctx: ctx, router: router, logger: CreateLogger(config)}, nil
return &MIDIInput{config: config, Port: portString, logger: CreateLogger(config)}, nil
},
})
}
@@ -59,8 +54,18 @@ func (mi *MIDIInput) Type() string {
return mi.config.Type
}
func (mi *MIDIInput) Run() error {
func (mi *MIDIInput) Start(ctx context.Context) error {
mi.logger.Debug("running")
defer midi.CloseDriver()
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return errors.New("midi.input unable to get router from context")
}
mi.router = router
moduleContext, cancel := context.WithCancel(ctx)
mi.ctx = moduleContext
mi.cancel = cancel
in, err := midi.FindInPort(mi.Port)
if err != nil {
@@ -87,3 +92,7 @@ func (mi *MIDIInput) Run() error {
func (mi *MIDIInput) Output(ctx context.Context, payload any) error {
return errors.New("midi.input output is not implemented")
}
func (mi *MIDIInput) Stop() {
mi.cancel()
}

View File

@@ -21,12 +21,13 @@ type MIDIOutput struct {
Port string
SendFunc func(midi.Message) error
logger *slog.Logger
cancel context.CancelFunc
}
func init() {
RegisterModule(ModuleRegistration{
Type: "midi.output",
New: func(ctx context.Context, config config.ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
port, ok := params["port"]
@@ -41,13 +42,7 @@ func init() {
return nil, errors.New("midi.output port must be a string")
}
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return nil, errors.New("midi.output unable to get router from context")
}
return &MIDIOutput{config: config, Port: portString, ctx: ctx, router: router, logger: CreateLogger(config)}, nil
return &MIDIOutput{config: config, Port: portString, logger: CreateLogger(config)}, nil
},
})
}
@@ -60,8 +55,18 @@ func (mo *MIDIOutput) Type() string {
return mo.config.Type
}
func (mo *MIDIOutput) Run() error {
func (mo *MIDIOutput) Start(ctx context.Context) error {
mo.logger.Debug("running")
defer midi.CloseDriver()
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return errors.New("midi.output unable to get router from context")
}
mo.router = router
moduleContext, cancel := context.WithCancel(ctx)
mo.ctx = moduleContext
mo.cancel = cancel
out, err := midi.FindOutPort(mo.Port)
@@ -94,3 +99,7 @@ func (mo *MIDIOutput) Output(ctx context.Context, payload any) error {
return mo.SendFunc(payloadMessage)
}
func (mo *MIDIOutput) Stop() {
mo.cancel()
}

View File

@@ -18,13 +18,14 @@ type ModuleError struct {
type Module interface {
Id() string
Type() string
Run() error
Start(context.Context) error
Stop()
Output(context.Context, any) error
}
type ModuleRegistration struct {
Type string `json:"type"`
New func(context.Context, config.ModuleConfig) (Module, error)
New func(config.ModuleConfig) (Module, error)
}
func RegisterModule(mod ModuleRegistration) {

View File

@@ -19,12 +19,13 @@ type MQTTClient struct {
Topic string
client mqtt.Client
logger *slog.Logger
cancel context.CancelFunc
}
func init() {
RegisterModule(ModuleRegistration{
Type: "mqtt.client",
New: func(ctx context.Context, config config.ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
broker, ok := params["broker"]
@@ -62,13 +63,7 @@ func init() {
return nil, errors.New("mqtt.client clientId must be string")
}
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return nil, errors.New("mqtt.client unable to get router from context")
}
return &MQTTClient{config: config, Broker: brokerString, Topic: topicString, ClientID: clientIdString, ctx: ctx, router: router, logger: CreateLogger(config)}, nil
return &MQTTClient{config: config, Broker: brokerString, Topic: topicString, ClientID: clientIdString, logger: CreateLogger(config)}, nil
},
})
}
@@ -81,7 +76,18 @@ func (mc *MQTTClient) Type() string {
return mc.config.Type
}
func (mc *MQTTClient) Run() error {
func (mc *MQTTClient) Start(ctx context.Context) error {
mc.logger.Debug("running")
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return errors.New("mqtt.client unable to get router from context")
}
mc.router = router
moduleContext, cancel := context.WithCancel(ctx)
mc.ctx = moduleContext
mc.cancel = cancel
opts := mqtt.NewClientOptions()
opts.AddBroker(mc.Broker)
opts.SetClientID(mc.ClientID)
@@ -96,6 +102,7 @@ func (mc *MQTTClient) Run() error {
}
mc.client = mqtt.NewClient(opts)
defer mc.client.Disconnect(250)
token := mc.client.Connect()
@@ -131,3 +138,7 @@ func (mc *MQTTClient) Output(ctx context.Context, payload any) error {
return token.Error()
}
func (mc *MQTTClient) Stop() {
mc.cancel()
}

View File

@@ -19,12 +19,13 @@ type NATSClient struct {
Subject string
client *nats.Conn
logger *slog.Logger
cancel context.CancelFunc
}
func init() {
RegisterModule(ModuleRegistration{
Type: "nats.client",
New: func(ctx context.Context, config config.ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
url, ok := params["url"]
@@ -50,13 +51,7 @@ func init() {
return nil, errors.New("nats.client subject must be string")
}
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return nil, errors.New("nats.client unable to get router from context")
}
return &NATSClient{config: config, URL: urlString, Subject: subjectString, ctx: ctx, router: router, logger: CreateLogger(config)}, nil
return &NATSClient{config: config, URL: urlString, Subject: subjectString, logger: CreateLogger(config)}, nil
},
})
}
@@ -69,7 +64,19 @@ func (nc *NATSClient) Type() string {
return nc.config.Type
}
func (nc *NATSClient) Run() error {
func (nc *NATSClient) Start(ctx context.Context) error {
nc.logger.Debug("running")
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return errors.New("nats.client unable to get router from context")
}
nc.router = router
moduleContext, cancel := context.WithCancel(ctx)
nc.ctx = moduleContext
nc.cancel = cancel
client, err := nats.Connect(nc.URL, nats.RetryOnFailedConnect(true))
if err != nil {
@@ -118,3 +125,7 @@ func (nc *NATSClient) Output(ctx context.Context, payload any) error {
return err
}
func (nc *NATSClient) Stop() {
nc.cancel()
}

View File

@@ -20,18 +20,15 @@ type PSNClient struct {
router route.RouteIO
decoder *psn.Decoder
logger *slog.Logger
cancel context.CancelFunc
}
func init() {
RegisterModule(ModuleRegistration{
Type: "psn.client",
New: func(ctx context.Context, config config.ModuleConfig) (Module, error) {
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
New: func(config config.ModuleConfig) (Module, error) {
if !ok {
return nil, errors.New("psn.client unable to get router from context")
}
return &PSNClient{config: config, decoder: psn.NewDecoder(), ctx: ctx, router: router, logger: CreateLogger(config)}, nil
return &PSNClient{config: config, decoder: psn.NewDecoder(), logger: CreateLogger(config)}, nil
},
})
}
@@ -44,7 +41,17 @@ func (pc *PSNClient) Type() string {
return pc.config.Type
}
func (pc *PSNClient) Run() error {
func (pc *PSNClient) Start(ctx context.Context) error {
pc.logger.Debug("running")
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return errors.New("psn.client unable to get router from context")
}
pc.router = router
moduleContext, cancel := context.WithCancel(ctx)
pc.ctx = moduleContext
pc.cancel = cancel
addr, err := net.ResolveUDPAddr("udp", "236.10.10.10:56565")
if err != nil {
@@ -86,6 +93,7 @@ func (pc *PSNClient) Run() error {
}
if pc.router != nil {
// TODO(jwetzell): better input handling
for _, tracker := range pc.decoder.Trackers {
pc.router.HandleInput(pc.ctx, pc.Id(), tracker)
}
@@ -100,3 +108,7 @@ func (pc *PSNClient) Run() error {
func (pc *PSNClient) Output(ctx context.Context, payload any) error {
return fmt.Errorf("psn.client output is not implemented")
}
func (pc *PSNClient) Stop() {
pc.cancel()
}

View File

@@ -24,12 +24,13 @@ type SerialClient struct {
Mode *serial.Mode
port serial.Port
logger *slog.Logger
cancel context.CancelFunc
}
func init() {
RegisterModule(ModuleRegistration{
Type: "serial.client",
New: func(ctx context.Context, config config.ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
port, ok := params["port"]
@@ -43,20 +44,19 @@ func init() {
return nil, errors.New("serial.client port must be a string")
}
framingMethod := "RAW"
framingMethod, ok := params["framing"]
framingMethodRaw, ok := params["framing"]
if ok {
framingMethodString, ok := framingMethodRaw.(string)
if !ok {
return nil, errors.New("serial.client framing method must be a string")
}
framingMethod = framingMethodString
if !ok {
return nil, errors.New("serial.client requires a framing parameter")
}
framer := framer.GetFramer(framingMethod)
framingMethodString, ok := framingMethod.(string)
if !ok {
return nil, errors.New("serial.client framing method must be a string")
}
framer := framer.GetFramer(framingMethodString)
if framer == nil {
return nil, fmt.Errorf("serial.client unknown framing method: %s", framingMethod)
@@ -76,13 +76,7 @@ func init() {
BaudRate: int(baudRateNum),
}
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return nil, errors.New("serial.client unable to get router from context")
}
return &SerialClient{config: config, Port: portString, Framer: framer, Mode: &mode, ctx: ctx, router: router, logger: CreateLogger(config)}, nil
return &SerialClient{config: config, Port: portString, Framer: framer, Mode: &mode, logger: CreateLogger(config)}, nil
},
})
}
@@ -107,7 +101,18 @@ func (sc *SerialClient) SetupPort() error {
return nil
}
func (sc *SerialClient) Run() error {
func (sc *SerialClient) Start(ctx context.Context) error {
sc.logger.Debug("running")
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return errors.New("serial.client unable to get router from context")
}
sc.router = router
moduleContext, cancel := context.WithCancel(ctx)
sc.ctx = moduleContext
sc.cancel = cancel
// TODO(jwetzell): shutdown with router.Context properly
go func() {
@@ -179,3 +184,7 @@ func (sc *SerialClient) Output(ctx context.Context, payload any) error {
_, err := sc.port.Write(sc.Framer.Encode(payloadBytes))
return err
}
func (sc *SerialClient) Stop() {
sc.cancel()
}

View File

@@ -29,6 +29,7 @@ type SIPCallServer struct {
UserAgent string
dg *diago.Diago
logger *slog.Logger
cancel context.CancelFunc
}
type SIPCallMessage struct {
@@ -45,7 +46,7 @@ type sipCallContextKey string
func init() {
RegisterModule(ModuleRegistration{
Type: "sip.call.server",
New: func(ctx context.Context, config config.ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
portNum := 5060
@@ -98,12 +99,7 @@ func init() {
userAgentString = specificTransportString
}
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return nil, errors.New("sip.call.server unable to get router from context")
}
return &SIPCallServer{config: config, ctx: ctx, router: router, IP: ipString, Port: int(portNum), Transport: transportString, UserAgent: userAgentString, logger: CreateLogger(config)}, nil
return &SIPCallServer{config: config, IP: ipString, Port: int(portNum), Transport: transportString, UserAgent: userAgentString, logger: CreateLogger(config)}, nil
},
})
}
@@ -116,7 +112,18 @@ func (scs *SIPCallServer) Type() string {
return scs.config.Type
}
func (scs *SIPCallServer) Run() error {
func (scs *SIPCallServer) Start(ctx context.Context) error {
scs.logger.Debug("running")
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return errors.New("sip.call.server unable to get router from context")
}
scs.router = router
moduleContext, cancel := context.WithCancel(ctx)
scs.ctx = moduleContext
scs.cancel = cancel
diagoLogger := slog.New(slog.NewJSONHandler(io.Discard, nil))
ua, _ := sipgo.NewUA(
@@ -160,7 +167,6 @@ func (scs *SIPCallServer) HandleCall(inDialog *diago.DialogServerSession) {
scs.router.HandleInput(dialogContext, scs.Id(), SIPCallMessage{
To: inDialog.ToUser(),
})
fmt.Println(inDialog.LoadState())
}
func (scs *SIPCallServer) Output(ctx context.Context, payload any) error {
@@ -226,3 +232,7 @@ func (scs *SIPCallServer) Output(ctx context.Context, payload any) error {
}
return errors.New("sip.dtmf.server can only output SipDTMFResponse or SipAudioFileResponse")
}
func (scs *SIPCallServer) Stop() {
scs.cancel()
}

View File

@@ -29,6 +29,7 @@ type SIPDTMFServer struct {
Transport string
Separator string
logger *slog.Logger
cancel context.CancelFunc
}
type SIPDTMFMessage struct {
@@ -44,7 +45,7 @@ type SIPDTMFCall struct {
func init() {
RegisterModule(ModuleRegistration{
Type: "sip.dtmf.server",
New: func(ctx context.Context, config config.ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
portNum := 5060
@@ -100,12 +101,7 @@ func init() {
if !strings.ContainsRune("0123456789*#ABCD", rune(separatorString[0])) {
return nil, errors.New("sip.dtmf.server separator must be a valid DTMF character")
}
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return nil, errors.New("sip.dtmf.server unable to get router from context")
}
return &SIPDTMFServer{config: config, ctx: ctx, router: router, IP: ipString, Port: int(portNum), Transport: transportString, Separator: separatorString, logger: CreateLogger(config)}, nil
return &SIPDTMFServer{config: config, IP: ipString, Port: int(portNum), Transport: transportString, Separator: separatorString, logger: CreateLogger(config)}, nil
},
})
}
@@ -118,7 +114,18 @@ func (sds *SIPDTMFServer) Type() string {
return sds.config.Type
}
func (sds *SIPDTMFServer) Run() error {
func (sds *SIPDTMFServer) Start(ctx context.Context) error {
sds.logger.Debug("running")
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return errors.New("sip.dtmf.server unable to get router from context")
}
sds.router = router
moduleContext, cancel := context.WithCancel(ctx)
sds.ctx = moduleContext
sds.cancel = cancel
diagoLogger := slog.New(slog.NewJSONHandler(io.Discard, nil))
ua, _ := sipgo.NewUA(
@@ -240,3 +247,7 @@ func (sds *SIPDTMFServer) Output(ctx context.Context, payload any) error {
return errors.New("sip.dtmf.server can only output SipDTMFResponse or SipAudioFileResponse")
}
func (sds *SIPDTMFServer) Stop() {
sds.cancel()
}

View File

@@ -21,12 +21,13 @@ type TCPClient struct {
router route.RouteIO
Addr *net.TCPAddr
logger *slog.Logger
cancel context.CancelFunc
}
func init() {
RegisterModule(ModuleRegistration{
Type: "net.tcp.client",
New: func(ctx context.Context, config config.ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
host, ok := params["host"]
@@ -56,32 +57,24 @@ func init() {
return nil, err
}
framingMethod := "RAW"
framingMethod, ok := params["framing"]
framingMethodRaw, ok := params["framing"]
if ok {
framingMethodString, ok := framingMethodRaw.(string)
if !ok {
return nil, errors.New("net.tcp.client framing method must be a string")
}
framingMethod = framingMethodString
if !ok {
return nil, errors.New("net.tcp.client requires a framing parameter")
}
framer := framer.GetFramer(framingMethod)
framingMethodString, ok := framingMethod.(string)
if !ok {
return nil, errors.New("net.tcp.client framing method must be a string")
}
framer := framer.GetFramer(framingMethodString)
if framer == nil {
return nil, fmt.Errorf("net.tcp.client unknown framing method: %s", framingMethod)
}
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return nil, errors.New("net.tcp.client unable to get router from context")
}
return &TCPClient{framer: framer, Addr: addr, config: config, ctx: ctx, router: router, logger: CreateLogger(config)}, nil
return &TCPClient{framer: framer, Addr: addr, config: config, logger: CreateLogger(config)}, nil
},
})
}
@@ -94,7 +87,17 @@ func (tc *TCPClient) Type() string {
return tc.config.Type
}
func (tc *TCPClient) Run() error {
func (tc *TCPClient) Start(ctx context.Context) error {
tc.logger.Debug("running")
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return errors.New("net.tcp.client unable to get router from context")
}
tc.router = router
moduleContext, cancel := context.WithCancel(ctx)
tc.ctx = moduleContext
tc.cancel = cancel
// TODO(jwetzell): shutdown with router.Context properly
go func() {
@@ -176,3 +179,7 @@ func (tc *TCPClient) Output(ctx context.Context, payload any) error {
_, err := tc.conn.Write(tc.framer.Encode(payloadBytes))
return err
}
func (tc *TCPClient) Stop() {
tc.cancel()
}

View File

@@ -27,12 +27,13 @@ type TCPServer struct {
connections []*net.TCPConn
connectionsMu sync.RWMutex
logger *slog.Logger
cancel context.CancelFunc
}
func init() {
RegisterModule(ModuleRegistration{
Type: "net.tcp.server",
New: func(ctx context.Context, config config.ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
port, ok := params["port"]
if !ok {
@@ -45,20 +46,19 @@ func init() {
return nil, errors.New("net.tcp.server port must be a number")
}
framingMethod := "RAW"
framingMethod, ok := params["framing"]
framingMethodRaw, ok := params["framing"]
if ok {
framingMethodString, ok := framingMethodRaw.(string)
if !ok {
return nil, errors.New("net.tcp.server framing method must be a string")
}
framingMethod = framingMethodString
if !ok {
return nil, errors.New("net.tcp.server requires a framing parameter")
}
framer := framer.GetFramer(framingMethod)
framingMethodString, ok := framingMethod.(string)
if !ok {
return nil, errors.New("net.tcp.server framing method must be a string")
}
framer := framer.GetFramer(framingMethodString)
if framer == nil {
return nil, fmt.Errorf("net.tcp.server unknown framing method: %s", framingMethod)
@@ -81,14 +81,7 @@ func init() {
if err != nil {
return nil, err
}
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return nil, errors.New("net.tcp.server unable to get router from context")
}
return &TCPServer{Framer: framer, Addr: addr, config: config, quit: make(chan interface{}), ctx: ctx, router: router, logger: CreateLogger(config)}, nil
return &TCPServer{Framer: framer, Addr: addr, config: config, quit: make(chan interface{}), logger: CreateLogger(config)}, nil
},
})
}
@@ -113,6 +106,15 @@ ClientRead:
for {
select {
case <-ts.quit:
client.Close()
ts.connectionsMu.Lock()
for i := 0; i < len(ts.connections); i++ {
if ts.connections[i] == client {
ts.connections = slices.Delete(ts.connections, i, i+1)
break
}
}
ts.connectionsMu.Unlock()
return
default:
client.SetDeadline(time.Now().Add(time.Millisecond * 200))
@@ -166,7 +168,18 @@ ClientRead:
}
}
func (ts *TCPServer) Run() error {
func (ts *TCPServer) Start(ctx context.Context) error {
ts.logger.Debug("running")
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return errors.New("net.tcp.server unable to get router from context")
}
ts.router = router
moduleContext, cancel := context.WithCancel(ctx)
ts.ctx = moduleContext
ts.cancel = cancel
listener, err := net.ListenTCP("tcp", ts.Addr)
if err != nil {
return err
@@ -225,3 +238,8 @@ func (ts *TCPServer) Output(ctx context.Context, payload any) error {
}
return fmt.Errorf("net.tcp.server error during output: %s", errorString)
}
func (ts *TCPServer) Stop() {
ts.cancel()
ts.wg.Wait()
}

View File

@@ -17,12 +17,13 @@ type TimeInterval struct {
router route.RouteIO
ticker *time.Ticker
logger *slog.Logger
cancel context.CancelFunc
}
func init() {
RegisterModule(ModuleRegistration{
Type: "time.interval",
New: func(ctx context.Context, config config.ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
duration, ok := params["duration"]
@@ -35,14 +36,7 @@ func init() {
if !ok {
return nil, errors.New("time.interval duration must be number")
}
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return nil, errors.New("time.interval unable to get router from context")
}
return &TimeInterval{Duration: uint32(durationNum), config: config, ctx: ctx, router: router, logger: CreateLogger(config)}, nil
return &TimeInterval{Duration: uint32(durationNum), config: config, logger: CreateLogger(config)}, nil
},
})
}
@@ -55,7 +49,18 @@ func (i *TimeInterval) Type() string {
return i.config.Type
}
func (i *TimeInterval) Run() error {
func (i *TimeInterval) Start(ctx context.Context) error {
i.logger.Debug("running")
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return errors.New("time.interval unable to get router from context")
}
i.router = router
moduleContext, cancel := context.WithCancel(ctx)
i.ctx = moduleContext
i.cancel = cancel
ticker := time.NewTicker(time.Millisecond * time.Duration(i.Duration))
i.ticker = ticker
defer ticker.Stop()
@@ -78,3 +83,7 @@ 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() {
i.cancel()
}

View File

@@ -17,12 +17,13 @@ type TimeTimer struct {
router route.RouteIO
timer *time.Timer
logger *slog.Logger
cancel context.CancelFunc
}
func init() {
RegisterModule(ModuleRegistration{
Type: "time.timer",
New: func(ctx context.Context, config config.ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
duration, ok := params["duration"]
@@ -36,13 +37,7 @@ func init() {
return nil, errors.New("time.timer duration must be a number")
}
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return nil, errors.New("net.tcp.client unable to get router from context")
}
return &TimeTimer{Duration: uint32(durationNum), config: config, ctx: ctx, router: router, logger: CreateLogger(config)}, nil
return &TimeTimer{Duration: uint32(durationNum), config: config, logger: CreateLogger(config)}, nil
},
})
}
@@ -55,7 +50,18 @@ func (t *TimeTimer) Type() string {
return t.config.Type
}
func (t *TimeTimer) Run() error {
func (t *TimeTimer) Start(ctx context.Context) error {
t.logger.Debug("running")
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return errors.New("net.tcp.client unable to get router from context")
}
t.router = router
moduleContext, cancel := context.WithCancel(ctx)
t.ctx = moduleContext
t.cancel = cancel
t.timer = time.NewTimer(time.Millisecond * time.Duration(t.Duration))
defer t.timer.Stop()
for {
@@ -76,3 +82,7 @@ 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() {
t.cancel()
}

View File

@@ -19,12 +19,13 @@ type UDPClient struct {
ctx context.Context
router route.RouteIO
logger *slog.Logger
cancel context.CancelFunc
}
func init() {
RegisterModule(ModuleRegistration{
Type: "net.udp.client",
New: func(ctx context.Context, config config.ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
host, ok := params["host"]
@@ -53,14 +54,7 @@ func init() {
if err != nil {
return nil, err
}
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return nil, errors.New("net.udp.client unable to get router from context")
}
return &UDPClient{Addr: addr, config: config, ctx: ctx, router: router, logger: CreateLogger(config)}, nil
return &UDPClient{Addr: addr, config: config, logger: CreateLogger(config)}, nil
},
})
}
@@ -79,7 +73,17 @@ func (uc *UDPClient) SetupConn() error {
return err
}
func (uc *UDPClient) Run() error {
func (uc *UDPClient) Start(ctx context.Context) error {
uc.logger.Debug("running")
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return errors.New("net.udp.client unable to get router from context")
}
uc.router = router
moduleContext, cancel := context.WithCancel(ctx)
uc.ctx = moduleContext
uc.cancel = cancel
err := uc.SetupConn()
if err != nil {
@@ -111,3 +115,7 @@ func (uc *UDPClient) Output(ctx context.Context, payload any) error {
}
return nil
}
func (uc *UDPClient) Stop() {
uc.cancel()
}

View File

@@ -19,12 +19,13 @@ type UDPMulticast struct {
router route.RouteIO
Addr *net.UDPAddr
logger *slog.Logger
cancel context.CancelFunc
}
func init() {
RegisterModule(ModuleRegistration{
Type: "net.udp.multicast",
New: func(ctx context.Context, config config.ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
ip, ok := params["ip"]
@@ -53,13 +54,7 @@ func init() {
if err != nil {
return nil, err
}
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return nil, errors.New("net.udp.multicast unable to get router from context")
}
return &UDPMulticast{config: config, Addr: addr, ctx: ctx, router: router, logger: CreateLogger(config)}, nil
return &UDPMulticast{config: config, Addr: addr, logger: CreateLogger(config)}, nil
},
})
}
@@ -72,7 +67,17 @@ func (um *UDPMulticast) Type() string {
return um.config.Type
}
func (um *UDPMulticast) Run() error {
func (um *UDPMulticast) Start(ctx context.Context) error {
um.logger.Debug("running")
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return errors.New("net.udp.multicast unable to get router from context")
}
um.router = router
moduleContext, cancel := context.WithCancel(ctx)
um.ctx = moduleContext
um.cancel = cancel
client, err := net.ListenMulticastUDP("udp", nil, um.Addr)
if err != nil {
@@ -128,3 +133,7 @@ func (um *UDPMulticast) Output(ctx context.Context, payload any) error {
_, err := um.conn.Write(payloadBytes)
return err
}
func (um *UDPMulticast) Stop() {
um.cancel()
}

View File

@@ -20,12 +20,13 @@ type UDPServer struct {
ctx context.Context
router route.RouteIO
logger *slog.Logger
cancel context.CancelFunc
}
func init() {
RegisterModule(ModuleRegistration{
Type: "net.udp.server",
New: func(ctx context.Context, config config.ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
port, ok := params["port"]
if !ok {
@@ -67,13 +68,7 @@ func init() {
}
bufferSizeNum = int(bufferSizeFloat)
}
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return nil, errors.New("net.udp.server unable to get router from context")
}
return &UDPServer{Addr: addr, BufferSize: bufferSizeNum, config: config, ctx: ctx, router: router, logger: CreateLogger(config)}, nil
return &UDPServer{Addr: addr, BufferSize: bufferSizeNum, config: config, logger: CreateLogger(config)}, nil
},
})
}
@@ -86,7 +81,17 @@ func (us *UDPServer) Type() string {
return us.config.Id
}
func (us *UDPServer) Run() error {
func (us *UDPServer) Start(ctx context.Context) error {
us.logger.Debug("running")
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return errors.New("net.udp.server unable to get router from context")
}
us.router = router
moduleContext, cancel := context.WithCancel(ctx)
us.ctx = moduleContext
us.cancel = cancel
listener, err := net.ListenUDP("udp", us.Addr)
if err != nil {
@@ -127,3 +132,7 @@ func (us *UDPServer) Run() error {
func (us *UDPServer) Output(ctx context.Context, payload any) error {
return errors.New("net.udp.server output is not implemented")
}
func (us *UDPServer) Stop() {
us.cancel()
}

View File

@@ -0,0 +1,239 @@
package processor_test
import (
"reflect"
"testing"
"github.com/jwetzell/artnet-go"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
func TestArtnetPacketFilterFromRegistry(t *testing.T) {
registration, ok := processor.ProcessorRegistry["artnet.packet.filter"]
if !ok {
t.Fatalf("artnet.packet.filter processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "artnet.packet.filter",
Params: map[string]any{
"opCode": float64(artnet.OpTimeCode),
},
})
if err != nil {
t.Fatalf("failed to create artnet.packet.filter processor: %s", err)
}
if processorInstance.Type() != "artnet.packet.filter" {
t.Fatalf("artnet.packet.filter processor has wrong type: %s", processorInstance.Type())
}
payload := &artnet.ArtTimeCode{
ID: []byte{'A', 'r', 't', '-', 'N', 'e', 't', 0x00},
OpCode: artnet.OpTimeCode,
ProtVerHi: 0,
ProtVerLo: 14,
Filler1: 0,
StreamId: 0,
Frames: 11,
Seconds: 17,
Minutes: 3,
Hours: 0,
Type: 0,
}
expected := &artnet.ArtTimeCode{
ID: []byte{'A', 'r', 't', '-', 'N', 'e', 't', 0x00},
OpCode: artnet.OpTimeCode,
ProtVerHi: 0,
ProtVerLo: 14,
Filler1: 0,
StreamId: 0,
Frames: 11,
Seconds: 17,
Minutes: 3,
Hours: 0,
Type: 0,
}
got, err := processorInstance.Process(t.Context(), payload)
if err != nil {
t.Fatalf("artnet.packet.filter processing failed: %s", err)
}
if !reflect.DeepEqual(got, expected) {
t.Fatalf("artnet.packet.filter got %+v, expected %+v", got, expected)
}
}
func TestGoodArtnetPacketFilter(t *testing.T) {
tests := []struct {
name string
payload any
opCode uint16
expected artnet.ArtNetPacket
}{
{
name: "tiemcode packet with matching opCode",
payload: &artnet.ArtTimeCode{
ID: []byte{'A', 'r', 't', '-', 'N', 'e', 't', 0x00},
OpCode: artnet.OpTimeCode,
ProtVerHi: 0,
ProtVerLo: 14,
Filler1: 0,
StreamId: 0,
Frames: 11,
Seconds: 17,
Minutes: 3,
Hours: 0,
Type: 0,
},
opCode: artnet.OpTimeCode,
expected: &artnet.ArtTimeCode{
ID: []byte{'A', 'r', 't', '-', 'N', 'e', 't', 0x00},
OpCode: artnet.OpTimeCode,
ProtVerHi: 0,
ProtVerLo: 14,
Filler1: 0,
StreamId: 0,
Frames: 11,
Seconds: 17,
Minutes: 3,
Hours: 0,
Type: 0,
},
},
{
name: "tiemcode packet with mismatching opCode",
payload: &artnet.ArtTimeCode{
ID: []byte{'A', 'r', 't', '-', 'N', 'e', 't', 0x00},
OpCode: artnet.OpTimeCode,
ProtVerHi: 0,
ProtVerLo: 14,
Filler1: 0,
StreamId: 0,
Frames: 11,
Seconds: 17,
Minutes: 3,
Hours: 0,
Type: 0,
},
opCode: artnet.OpDmx,
expected: nil,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
artnetPacketFilter := processor.ArtNetPacketFilter{
OpCode: test.opCode,
}
got, err := artnetPacketFilter.Process(t.Context(), test.payload)
if err != nil {
t.Fatalf("artnet.packet.filter failed: %s", err)
}
if test.expected == nil {
if got != nil {
t.Fatalf("artnet.packet.filter got %+v, expected nil", got)
}
return
}
gotPacket, ok := got.(artnet.ArtNetPacket)
if !ok {
t.Fatalf("artnet.packet.filter returned a %T payload: %s", got, got)
}
if !reflect.DeepEqual(gotPacket, test.expected) {
t.Fatalf("artnet.packet.filter got %+v, expected %+v", gotPacket, test.expected)
}
})
}
}
func TestBadArtnetPacketFilter(t *testing.T) {
tests := []struct {
name string
payload any
params map[string]any
errorString string
}{
{
name: "non-artnet input",
payload: []byte{0x01},
params: map[string]any{"opCode": float64(artnet.OpTimeCode)},
errorString: "artnet.packet.filter processor only accepts an ArtNetPacket",
},
{
name: "no opCode param",
payload: &artnet.ArtTimeCode{
ID: []byte{'A', 'r', 't', '-', 'N', 'e', 't', 0x00},
OpCode: artnet.OpTimeCode,
ProtVerHi: 0,
ProtVerLo: 14,
Filler1: 0,
StreamId: 0,
Frames: 11,
Seconds: 17,
Minutes: 3,
Hours: 0,
Type: 0,
},
params: map[string]any{},
errorString: "artnet.packet.filter requires an opCode parameter",
},
{
name: "opCode not a number",
payload: &artnet.ArtTimeCode{
ID: []byte{'A', 'r', 't', '-', 'N', 'e', 't', 0x00},
OpCode: artnet.OpTimeCode,
ProtVerHi: 0,
ProtVerLo: 14,
Filler1: 0,
StreamId: 0,
Frames: 11,
Seconds: 17,
Minutes: 3,
Hours: 0,
Type: 0,
},
params: map[string]any{"opCode": "100"},
errorString: "artnet.packet.filter opCode must be a number",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
registration, ok := processor.ProcessorRegistry["artnet.packet.filter"]
if !ok {
t.Fatalf("artnet.packet.filter processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "artnet.packet.filter",
Params: test.params,
})
if err != nil {
if test.errorString != err.Error() {
t.Fatalf("artnet.packet.filter got error '%s', expected '%s'", err.Error(), test.errorString)
}
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
if err == nil {
t.Fatalf("artnet.packet.filter expected to fail but got payload: %s", got)
}
if err.Error() != test.errorString {
t.Fatalf("artnet.packet.filter got error '%s', expected '%s'", err.Error(), test.errorString)
}
})
}
}

View File

@@ -14,7 +14,9 @@ type DebugLog struct {
}
func (dl *DebugLog) Process(ctx context.Context, payload any) (any, error) {
dl.logger.Debug("", "payload", payload, "payloadType", fmt.Sprintf("%T", payload))
payloadString := fmt.Sprintf("%+v", payload)
payloadType := fmt.Sprintf("%T", payload)
dl.logger.Debug("", "payload", payloadString, "payloadType", payloadType)
return payload, nil
}

View File

@@ -0,0 +1,175 @@
package processor_test
import (
"testing"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
func TestIntRandomFromRegistry(t *testing.T) {
registration, ok := processor.ProcessorRegistry["int.random"]
if !ok {
t.Fatalf("int.random processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "int.random",
Params: map[string]any{
"min": 1.0,
"max": 10.0,
},
})
if err != nil {
t.Fatalf("failed to create int.random processor: %s", err)
}
if processorInstance.Type() != "int.random" {
t.Fatalf("int.random processor has wrong type: %s", processorInstance.Type())
}
}
func TestIntRandomGoodConfig(t *testing.T) {
registration, ok := processor.ProcessorRegistry["int.random"]
if !ok {
t.Fatalf("int.random processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "int.random",
Params: map[string]any{
"min": 1.0,
"max": 10.0,
},
})
if err != nil {
t.Fatalf("int.random should have created processor but got error: %s", err)
}
payload := "12345"
got, err := processorInstance.Process(t.Context(), payload)
if err != nil {
t.Fatalf("int.random processing failed: %s", err)
}
gotInt, ok := got.(int)
if !ok {
t.Fatalf("int.random returned a %T payload: %s", got, got)
}
if gotInt < 1 || gotInt > 10 {
t.Fatalf("int.random got %d, expected between %d and %d", gotInt, 1, 10)
}
}
func TestGoodIntRandom(t *testing.T) {
tests := []struct {
processor processor.Processor
name string
payload any
min int
max int
}{
{
name: "1-10",
payload: "12345",
min: 1,
max: 10,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
intRandom := processor.IntRandom{
Min: test.min,
Max: test.max,
}
got, err := intRandom.Process(t.Context(), test.payload)
gotInt, ok := got.(int)
if !ok {
t.Fatalf("int.random returned a %T payload: %s", got, got)
}
if err != nil {
t.Fatalf("int.random failed: %s", err)
}
if gotInt < test.min || gotInt > test.max {
t.Fatalf("int.random got %d, expected between %d and %d", gotInt, test.min, test.max)
}
})
}
}
func TestBadIntRandom(t *testing.T) {
tests := []struct {
name string
params map[string]any
payload any
errorString string
}{
{
name: "no min param",
payload: "hello",
params: map[string]any{"max": 10.0},
errorString: "int.random requires a min parameter",
},
{
name: "no max param",
payload: "hello",
params: map[string]any{"min": 1.0},
errorString: "int.random requires a max parameter",
},
{
name: "min param not a number",
payload: "hello",
params: map[string]any{"min": "1", "max": 10.0},
errorString: "int.random min must be a number",
},
{
name: "max param not a number",
payload: "hello",
params: map[string]any{"min": 1.0, "max": "10"},
errorString: "int.random max must be a number",
},
{
name: "max less than min",
payload: "hello",
params: map[string]any{"min": 1.0, "max": 0.0},
errorString: "int.random max must be greater than min",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
registration, ok := processor.ProcessorRegistry["int.random"]
if !ok {
t.Fatalf("int.random processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "int.random",
Params: test.params,
})
if err != nil {
if test.errorString != err.Error() {
t.Fatalf("int.random got error '%s', expected '%s'", err.Error(), test.errorString)
}
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
if err == nil {
t.Fatalf("int.random expected to fail but got payload: %s", got)
}
if err.Error() != test.errorString {
t.Fatalf("int.random got error '%s', expected '%s'", err.Error(), test.errorString)
}
})
}
}

View File

@@ -0,0 +1,44 @@
package processor
import (
"context"
"encoding/json"
"errors"
"github.com/jwetzell/showbridge-go/internal/config"
)
type JsonDecode struct {
config config.ProcessorConfig
}
func (jd *JsonDecode) Process(ctx context.Context, payload any) (any, error) {
payloadString, ok := payload.(string)
if !ok {
return nil, errors.New("json.decode processor only accepts a string")
}
payloadJson := make(map[string]any)
err := json.Unmarshal([]byte(payloadString), &payloadJson)
if err != nil {
return nil, err
}
return payloadJson, nil
}
func (jd *JsonDecode) Type() string {
return jd.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "json.decode",
New: func(config config.ProcessorConfig) (Processor, error) {
return &JsonDecode{config: config}, nil
},
})
}

View File

@@ -0,0 +1,91 @@
package processor_test
import (
"reflect"
"testing"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
func TestJsonDecodeFromRegistry(t *testing.T) {
registration, ok := processor.ProcessorRegistry["json.decode"]
if !ok {
t.Fatalf("json.decode processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "json.decode",
})
if err != nil {
t.Fatalf("failed to create json.decode processor: %s", err)
}
if processorInstance.Type() != "json.decode" {
t.Fatalf("json.decode processor has wrong type: %s", processorInstance.Type())
}
payload := "{\"property\":\"hello\"}"
expected := map[string]any{
"property": "hello",
}
got, err := processorInstance.Process(t.Context(), payload)
if err != nil {
t.Fatalf("json.decode processing failed: %s", err)
}
gotMap, ok := got.(map[string]any)
if !ok {
t.Fatalf("json.decode should return byte slice")
}
if !reflect.DeepEqual(gotMap, expected) {
t.Fatalf("json.decode got %+v, expected %+v", got, expected)
}
}
func TestGoodJsonDecode(t *testing.T) {
jsonDecoder := processor.JsonDecode{}
tests := []struct {
name string
payload string
expected map[string]any
}{
{
name: "basic json",
payload: "{\"address\":\"/hello\",\"args\":null}",
expected: map[string]any{
"address": "/hello",
"args": nil,
},
},
{
name: "array",
payload: "{\"address\":\"/hello\",\"args\":[1,2,3]}",
expected: map[string]any{
"address": "/hello",
"args": []any{1.0, 2.0, 3.0},
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := jsonDecoder.Process(t.Context(), test.payload)
gotMap, ok := got.(map[string]any)
if !ok {
t.Fatalf("json.decode returned a %T payload: %s", got, got)
}
if err != nil {
t.Fatalf("json.decode failed: %s", err)
}
if !reflect.DeepEqual(gotMap, test.expected) {
t.Fatalf("json.decode got %x, expected %s", got, test.expected)
}
})
}
}

View File

@@ -5,20 +5,60 @@ import (
"testing"
"github.com/jwetzell/osc-go"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
func TestJsonEncodeFromRegistry(t *testing.T) {
registration, ok := processor.ProcessorRegistry["json.encode"]
if !ok {
t.Fatalf("json.encode processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "json.encode",
})
if err != nil {
t.Fatalf("failed to create json.encode processor: %s", err)
}
if processorInstance.Type() != "json.encode" {
t.Fatalf("json.encode processor has wrong type: %s", processorInstance.Type())
}
payload := struct {
Property string `json:"property"`
}{
Property: "hello",
}
expected := []byte("{\"property\":\"hello\"}")
got, err := processorInstance.Process(t.Context(), payload)
if err != nil {
t.Fatalf("json.encode processing failed: %s", err)
}
gotBytes, ok := got.([]byte)
if !ok {
t.Fatalf("json.encode should return byte slice")
}
if !slices.Equal(gotBytes, expected) {
t.Fatalf("json.encode got %+v, expected %+v", got, expected)
}
}
func TestGoodJsonEncode(t *testing.T) {
stringEncoder := processor.JsonEncode{}
jsonEncoder := processor.JsonEncode{}
tests := []struct {
processor processor.Processor
name string
payload any
expected []byte
name string
payload any
expected []byte
}{
{
processor: &stringEncoder,
name: "hello",
name: "basic struct",
payload: osc.OSCMessage{
Address: "/hello",
},
@@ -28,7 +68,7 @@ func TestGoodJsonEncode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := test.processor.Process(t.Context(), test.payload)
got, err := jsonEncoder.Process(t.Context(), test.payload)
gotBytes, ok := got.([]byte)
if !ok {

View File

@@ -51,6 +51,7 @@ func (mm MQTTMessage) Payload() []byte {
func (mm MQTTMessage) Ack() {}
func (mmc *MQTTMessageCreate) Process(ctx context.Context, payload any) (any, error) {
// TODO(jwetzell): support templating
message := MQTTMessage{
topic: mmc.Topic,

View File

@@ -16,7 +16,7 @@ type NATSMessage struct {
type NATSMessageCreate struct {
config config.ProcessorConfig
Subject string
Subject *template.Template
Payload *template.Template
}
@@ -31,8 +31,17 @@ func (nmc *NATSMessageCreate) Process(ctx context.Context, payload any) (any, er
payloadString := payloadBuffer.String()
var subjectBuffer bytes.Buffer
err = nmc.Subject.Execute(&subjectBuffer, payload)
if err != nil {
return nil, err
}
subjectString := subjectBuffer.String()
message := NATSMessage{
Subject: nmc.Subject,
Subject: subjectString,
Payload: []byte(payloadString),
}
@@ -48,7 +57,6 @@ func init() {
Type: "nats.message.create",
New: func(config config.ProcessorConfig) (Processor, error) {
params := config.Params
// TODO(jwetzell): support template for subject
subject, ok := params["subject"]
if !ok {
@@ -61,6 +69,12 @@ func init() {
return nil, errors.New("nats.message.create subject must be a string")
}
subjectTemplate, err := template.New("subject").Parse(subjectString)
if err != nil {
return nil, err
}
payload, ok := params["payload"]
if !ok {
@@ -79,7 +93,7 @@ func init() {
return nil, err
}
return &NATSMessageCreate{config: config, Subject: subjectString, Payload: payloadTemplate}, nil
return &NATSMessageCreate{config: config, Subject: subjectTemplate, Payload: payloadTemplate}, nil
},
})
}

View File

@@ -1,77 +0,0 @@
package processor
import (
"bytes"
"context"
"errors"
"text/template"
osc "github.com/jwetzell/osc-go"
"github.com/jwetzell/showbridge-go/internal/config"
)
type OSCMessageTransform struct {
config config.ProcessorConfig
Address *template.Template
}
func (omt *OSCMessageTransform) Process(ctx context.Context, payload any) (any, error) {
payloadMessage, ok := payload.(osc.OSCMessage)
if !ok {
return nil, errors.New("osc.message.transform processor only accepts an OSCMessage")
}
var addressBuffer bytes.Buffer
err := omt.Address.Execute(&addressBuffer, payloadMessage)
if err != nil {
return nil, err
}
addressString := addressBuffer.String()
if len(addressString) == 0 {
return nil, errors.New("osc.message.transform address must not be empty")
}
if addressString[0] != '/' {
return nil, errors.New("osc.message.transform address must start with '/'")
}
payloadMessage.Address = addressString
return payloadMessage, nil
}
func (omt *OSCMessageTransform) Type() string {
return omt.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "osc.message.transform",
New: func(config config.ProcessorConfig) (Processor, error) {
params := config.Params
address, ok := params["address"]
if !ok {
return nil, errors.New("osc.message.transform requires an address parameter")
}
addressString, ok := address.(string)
if !ok {
return nil, errors.New("osc.message.transform address must be a string")
}
addressTemplate, err := template.New("address").Parse(addressString)
if err != nil {
return nil, err
}
return &OSCMessageTransform{config: config, Address: addressTemplate}, nil
},
})
}

View File

@@ -0,0 +1,92 @@
package processor
import (
"context"
"fmt"
extism "github.com/extism/go-sdk"
"github.com/jwetzell/showbridge-go/internal/config"
)
type ScriptWASM struct {
config config.ProcessorConfig
Program *extism.CompiledPlugin
Function string
}
func (se *ScriptWASM) Process(ctx context.Context, payload any) (any, error) {
payloadBytes, ok := payload.([]byte)
if !ok {
return nil, fmt.Errorf("script.wasm can only operator on byte array")
}
program, err := se.Program.Instance(ctx, extism.PluginInstanceConfig{})
if err != nil {
return nil, err
}
_, output, err := program.Call(se.Function, payloadBytes)
if err != nil {
return nil, err
}
return output, nil
}
func (se *ScriptWASM) Type() string {
return se.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "script.wasm",
New: func(config config.ProcessorConfig) (Processor, error) {
params := config.Params
path, ok := params["path"]
if !ok {
return nil, fmt.Errorf("script.wasm requires a path parameter")
}
pathString, ok := path.(string)
if !ok {
return nil, fmt.Errorf("script.wasm path must be a string")
}
functionString := "process"
function, ok := params["function"]
if ok {
specificFunctionString, ok := function.(string)
if !ok {
return nil, fmt.Errorf("script.wasm function must be a string")
}
functionString = specificFunctionString
}
manifest := extism.Manifest{
Wasm: []extism.Wasm{
extism.WasmFile{
Path: pathString,
},
},
}
program, err := extism.NewCompiledPlugin(context.Background(), manifest, extism.PluginConfig{}, []extism.HostFunction{})
if err != nil {
return nil, err
}
return &ScriptWASM{config: config, Program: program, Function: functionString}, nil
},
})
}

View File

@@ -4,16 +4,18 @@ import (
"bytes"
"context"
"errors"
"regexp"
"text/template"
"github.com/jwetzell/showbridge-go/internal/config"
)
type SipResponseDTMFCreate struct {
config config.ProcessorConfig
PreWait int
PostWait int
Digits *template.Template
config config.ProcessorConfig
PreWait int
PostWait int
Digits *template.Template
validDTMF *regexp.Regexp
}
type SipDTMFResponse struct {
@@ -33,6 +35,10 @@ func (scc *SipResponseDTMFCreate) Process(ctx context.Context, payload any) (any
digitsString := digitsBuffer.String()
if !scc.validDTMF.MatchString(digitsString) {
return nil, errors.New("sip.response.dtmf.create result of digits template contains invalid characters")
}
return SipDTMFResponse{
PreWait: scc.PreWait,
PostWait: scc.PostWait,
@@ -91,7 +97,7 @@ func init() {
if err != nil {
return nil, err
}
return &SipResponseDTMFCreate{config: config, Digits: digitsTemplate, PreWait: int(preWaitNum), PostWait: int(postWaitNum)}, nil
return &SipResponseDTMFCreate{config: config, Digits: digitsTemplate, PreWait: int(preWaitNum), PostWait: int(postWaitNum), validDTMF: regexp.MustCompile(`^[0-9*#A-Da-d]+$`)}, nil
},
})
}

View File

@@ -4,6 +4,7 @@ import (
"testing"
"text/template"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -15,6 +16,39 @@ func (t TestStruct) GetData() string {
return t.Data
}
func TestStringCreateFromRegistry(t *testing.T) {
registration, ok := processor.ProcessorRegistry["string.create"]
if !ok {
t.Fatalf("string.create processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "string.create",
Params: map[string]any{
"template": "{{.}}",
},
})
if err != nil {
t.Fatalf("failed to create string.create processor: %s", err)
}
if processorInstance.Type() != "string.create" {
t.Fatalf("string.create processor has wrong type: %s", processorInstance.Type())
}
payload := "hello"
expected := "hello"
got, err := processorInstance.Process(t.Context(), payload)
if err != nil {
t.Fatalf("string.create processing failed: %s", err)
}
if got != expected {
t.Fatalf("string.create got %+v, expected %+v", got, expected)
}
}
func TestGoodStringCreate(t *testing.T) {
tests := []struct {
@@ -79,3 +113,75 @@ func TestGoodStringCreate(t *testing.T) {
})
}
}
func TestBadStringCreate(t *testing.T) {
tests := []struct {
name string
params map[string]any
payload any
errorString string
}{
{
name: "no template param",
payload: "hello",
params: map[string]any{},
errorString: "string.create requires a template parameter",
},
{
name: "non string template",
payload: "hello",
params: map[string]any{
"template": 1,
},
errorString: "string.create template must be a string",
},
{
name: "invalid template",
payload: "hello",
params: map[string]any{
"template": "{{.",
},
errorString: "template: template:1: illegal number syntax: \".\"",
},
{
name: "bad property in template",
payload: "hello",
params: map[string]any{
"template": "{{.Invalid}}",
},
errorString: "template: template:1:2: executing \"template\" at <.Invalid>: can't evaluate field Invalid in type string",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
registration, ok := processor.ProcessorRegistry["string.create"]
if !ok {
t.Fatalf("string.create processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "string.create",
Params: test.params,
})
if err != nil {
if test.errorString != err.Error() {
t.Fatalf("string.create got error '%s', expected '%s'", err.Error(), test.errorString)
}
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
if err == nil {
t.Fatalf("string.create expected to fail but got payload: %s", got)
}
if err.Error() != test.errorString {
t.Fatalf("string.create got error '%s', expected '%s'", err.Error(), test.errorString)
}
})
}
}

View File

@@ -3,28 +3,57 @@ package processor_test
import (
"testing"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
func TestStringDecodeFromRegistry(t *testing.T) {
registration, ok := processor.ProcessorRegistry["string.decode"]
if !ok {
t.Fatalf("string.decode processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "string.decode",
})
if err != nil {
t.Fatalf("failed to create string.decode processor: %s", err)
}
if processorInstance.Type() != "string.decode" {
t.Fatalf("string.decode processor has wrong type: %s", processorInstance.Type())
}
payload := []byte{'h', 'e', 'l', 'l', 'o'}
expected := "hello"
got, err := processorInstance.Process(t.Context(), payload)
if err != nil {
t.Fatalf("string.decode processing failed: %s", err)
}
if got != expected {
t.Fatalf("string.decode got %+v, expected %+v", got, expected)
}
}
func TestGoodStringDecode(t *testing.T) {
stringDecoder := processor.StringDecode{}
tests := []struct {
processor processor.Processor
name string
payload any
expected string
name string
payload any
expected string
}{
{
processor: &stringDecoder,
name: "hello",
payload: []byte{0x68, 0x65, 0x6c, 0x6c, 0x6f},
expected: "hello",
name: "basic string",
payload: []byte{0x68, 0x65, 0x6c, 0x6c, 0x6f},
expected: "hello",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := test.processor.Process(t.Context(), test.payload)
got, err := stringDecoder.Process(t.Context(), test.payload)
gotString, ok := got.(string)
if !ok {
@@ -43,13 +72,11 @@ func TestGoodStringDecode(t *testing.T) {
func TestBadStringDecode(t *testing.T) {
stringDecoder := processor.StringDecode{}
tests := []struct {
processor processor.Processor
name string
payload any
errorString string
}{
{
processor: &stringDecoder,
name: "non-[]byte input",
payload: "hello",
errorString: "string.decode processor only accepts a []byte",
@@ -58,7 +85,7 @@ func TestBadStringDecode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := test.processor.Process(t.Context(), test.payload)
got, err := stringDecoder.Process(t.Context(), test.payload)
if err == nil {
t.Fatalf("string.decode expected to fail but got payload: %s", got)

View File

@@ -4,28 +4,63 @@ import (
"slices"
"testing"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
func TestStringEncodeFromRegistry(t *testing.T) {
registration, ok := processor.ProcessorRegistry["string.encode"]
if !ok {
t.Fatalf("string.encode processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "string.encode",
})
if err != nil {
t.Fatalf("failed to create string.encode processor: %s", err)
}
if processorInstance.Type() != "string.encode" {
t.Fatalf("string.encode processor has wrong type: %s", processorInstance.Type())
}
payload := "hello"
expected := []byte{'h', 'e', 'l', 'l', 'o'}
got, err := processorInstance.Process(t.Context(), payload)
if err != nil {
t.Fatalf("string.encode processing failed: %s", err)
}
gotBytes, ok := got.([]byte)
if !ok {
t.Fatalf("string.encode should return byte slice")
}
if !slices.Equal(gotBytes, expected) {
t.Fatalf("string.encode got %+v, expected %+v", got, expected)
}
}
func TestGoodStringEncode(t *testing.T) {
stringEncoder := processor.StringEncode{}
tests := []struct {
processor processor.Processor
name string
payload any
expected []byte
name string
payload any
expected []byte
}{
{
processor: &stringEncoder,
name: "hello",
payload: "hello",
expected: []byte{0x68, 0x65, 0x6c, 0x6c, 0x6f},
name: "basic string",
payload: "hello",
expected: []byte{0x68, 0x65, 0x6c, 0x6c, 0x6f},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := test.processor.Process(t.Context(), test.payload)
got, err := stringEncoder.Process(t.Context(), test.payload)
gotBytes, ok := got.([]byte)
if !ok {
@@ -44,13 +79,11 @@ func TestGoodStringEncode(t *testing.T) {
func TestBadStringEncode(t *testing.T) {
stringEncoder := processor.StringEncode{}
tests := []struct {
processor processor.Processor
name string
payload any
errorString string
}{
{
processor: &stringEncoder,
name: "non-string input",
payload: []byte{0x68, 0x65, 0x6c, 0x6c, 0x6f},
errorString: "string.encode processor only accepts a string",
@@ -59,7 +92,7 @@ func TestBadStringEncode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := test.processor.Process(t.Context(), test.payload)
got, err := stringEncoder.Process(t.Context(), test.payload)
if err == nil {
t.Fatalf("string.encode expected to fail but got payload: %s", got)

View File

@@ -0,0 +1,187 @@
package processor_test
import (
"reflect"
"testing"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
func TestStringFilterFromRegistry(t *testing.T) {
registration, ok := processor.ProcessorRegistry["string.filter"]
if !ok {
t.Fatalf("string.filter processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "string.filter",
Params: map[string]any{
"pattern": "hello",
},
})
if err != nil {
t.Fatalf("failed to create string.filter processor: %s", err)
}
if processorInstance.Type() != "string.filter" {
t.Fatalf("string.filter processor has wrong type: %s", processorInstance.Type())
}
payload := "hello"
expected := "hello"
got, err := processorInstance.Process(t.Context(), payload)
if err != nil {
t.Fatalf("string.filter processing failed: %s", err)
}
gotString, ok := got.(string)
if !ok {
t.Fatalf("string.filter should return byte slice")
}
if gotString != expected {
t.Fatalf("string.filter got %+v, expected %+v", got, expected)
}
}
func TestGoodStringFilter(t *testing.T) {
tests := []struct {
name string
params map[string]any
payload string
expected any
}{
{
name: "matches pattern",
payload: "hello",
params: map[string]any{"pattern": "hello"},
expected: "hello",
},
{
name: "does not match pattern",
payload: "hello",
params: map[string]any{"pattern": "world"},
expected: nil,
},
{
name: "basic regex",
payload: "hello world",
params: map[string]any{"pattern": ".* world"},
expected: "hello world",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
registration, ok := processor.ProcessorRegistry["string.filter"]
if !ok {
t.Fatalf("string.filter processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "string.filter",
Params: test.params,
})
if err != nil {
t.Fatalf("string.filter failed to create processor: %s", err)
}
got, err := processorInstance.Process(t.Context(), test.payload)
if err != nil {
t.Fatalf("string.filter failed: %s", err)
}
if test.expected == nil {
if got != nil {
t.Fatalf("string.filter got %+v, expected nil", got)
}
return
}
gotString, ok := got.(string)
if !ok {
t.Fatalf("string.filter returned a %T payload: %s", got, got)
}
if !reflect.DeepEqual(gotString, test.expected) {
t.Fatalf("string.filter got %+v, expected %+v", gotString, test.expected)
}
})
}
}
func TestBadStringFilter(t *testing.T) {
tests := []struct {
name string
payload any
params map[string]any
errorString string
}{
{
name: "no pattern param",
payload: "hello",
params: map[string]any{},
errorString: "string.filter requires a pattern parameter",
},
{
name: "non-string input",
payload: []byte{0x68, 0x65, 0x6c, 0x6c, 0x6f},
params: map[string]any{
"pattern": "hello",
},
errorString: "string.filter processor only accepts a string",
},
{
name: "non-string pattern param",
payload: "hello",
params: map[string]any{
"pattern": 123,
},
errorString: "string.filter pattern must be a string",
},
{
name: "invalid regex pattern",
payload: "hello",
params: map[string]any{
"pattern": "*invalid",
},
errorString: "error parsing regexp: missing argument to repetition operator: `*`",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
registration, ok := processor.ProcessorRegistry["string.filter"]
if !ok {
t.Fatalf("string.filter processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "string.filter",
Params: test.params,
})
if err != nil {
if test.errorString != err.Error() {
t.Fatalf("string.filter got error '%s', expected '%s'", err.Error(), test.errorString)
}
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
if err == nil {
t.Fatalf("string.filter expected to fail but got payload: %s", got)
}
if err.Error() != test.errorString {
t.Fatalf("string.filter got error '%s', expected '%s'", err.Error(), test.errorString)
}
})
}
}

View File

@@ -4,9 +4,49 @@ import (
"slices"
"testing"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
func TestStringSplitFromRegistry(t *testing.T) {
registration, ok := processor.ProcessorRegistry["string.split"]
if !ok {
t.Fatalf("string.split processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "string.split",
Params: map[string]any{
"separator": ",",
},
})
if err != nil {
t.Fatalf("failed to create string.split processor: %s", err)
}
if processorInstance.Type() != "string.split" {
t.Fatalf("string.split processor has wrong type: %s", processorInstance.Type())
}
payload := "part1,part2,part3"
expected := []string{"part1", "part2", "part3"}
got, err := processorInstance.Process(t.Context(), payload)
if err != nil {
t.Fatalf("string.split processing failed: %s", err)
}
gotStrings, ok := got.([]string)
if !ok {
t.Fatalf("string.split should return a slice of strings")
}
if !slices.Equal(gotStrings, expected) {
t.Fatalf("string.split got %+v, expected %+v", got, expected)
}
}
func TestGoodStringSplit(t *testing.T) {
tests := []struct {
processor processor.Processor
@@ -42,22 +82,51 @@ func TestGoodStringSplit(t *testing.T) {
func TestBadStringSplit(t *testing.T) {
tests := []struct {
processor processor.Processor
name string
payload any
params map[string]any
errorString string
}{
{
processor: &processor.StringSplit{Separator: ","},
name: "hello",
name: "non-string input",
payload: []byte{0x68, 0x65, 0x6c, 0x6c, 0x6f},
params: map[string]any{"separator": ","},
errorString: "string.split only accepts a string",
},
{
name: "missing separator param",
payload: "part1,part2,part3",
params: map[string]any{},
errorString: "string.split requires a separator",
},
{
name: "non-string separator param",
payload: "part1,part2,part3",
params: map[string]any{"separator": 123},
errorString: "string.split separator must be a string",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := test.processor.Process(t.Context(), test.payload)
registration, ok := processor.ProcessorRegistry["string.split"]
if !ok {
t.Fatalf("string.split processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "string.split",
Params: test.params,
})
if err != nil {
if test.errorString != err.Error() {
t.Fatalf("string.split got error '%s', expected '%s'", err.Error(), test.errorString)
}
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
if err == nil {
t.Fatalf("string.split expected error but got none, payload: %s", got)

View File

@@ -0,0 +1,30 @@
package processor_test
import (
"testing"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
func TestTimeSleepFromRegistry(t *testing.T) {
registration, ok := processor.ProcessorRegistry["time.sleep"]
if !ok {
t.Fatalf("time.sleep processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "time.sleep",
Params: map[string]any{
"duration": 1000.0,
},
})
if err != nil {
t.Fatalf("failed to create time.sleep processor: %s", err)
}
if processorInstance.Type() != "time.sleep" {
t.Fatalf("time.sleep processor has wrong type: %s", processorInstance.Type())
}
}

View File

@@ -0,0 +1,177 @@
package processor_test
import (
"testing"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
func TestUintRandomFromRegistry(t *testing.T) {
registration, ok := processor.ProcessorRegistry["uint.random"]
if !ok {
t.Fatalf("uint.random processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "uint.random",
Params: map[string]any{
"min": 1.0,
"max": 10.0,
},
})
if err != nil {
t.Fatalf("failed to create uint.random processor: %s", err)
}
if processorInstance.Type() != "uint.random" {
t.Fatalf("uint.random processor has wrong type: %s", processorInstance.Type())
}
}
func TestUintRandomGoodConfig(t *testing.T) {
registration, ok := processor.ProcessorRegistry["uint.random"]
if !ok {
t.Fatalf("uint.random processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "uint.random",
Params: map[string]any{
"min": 1.0,
"max": 10.0,
},
})
if err != nil {
t.Fatalf("uint.random should have created processor but got error: %s", err)
}
payload := "12345"
got, err := processorInstance.Process(t.Context(), payload)
if err != nil {
t.Fatalf("uint.random processing failed: %s", err)
}
gotUint, ok := got.(uint)
if !ok {
t.Fatalf("uint.random returned a %T payload: %s", got, got)
}
if gotUint < 1 || gotUint > 10 {
t.Fatalf("uint.random got %d, expected between %d and %d", gotUint, 1, 10)
}
}
func TestGoodUintRandom(t *testing.T) {
tests := []struct {
processor processor.Processor
name string
payload any
min uint
max uint
}{
{
name: "1-10",
payload: "12345",
min: 1,
max: 10,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
uintRandom := processor.UintRandom{
Min: test.min,
Max: test.max,
}
got, err := uintRandom.Process(t.Context(), test.payload)
gotUint, ok := got.(uint)
if !ok {
t.Fatalf("uint.random returned a %T payload: %s", got, got)
}
if err != nil {
t.Fatalf("uint.random failed: %s", err)
}
if gotUint < test.min || gotUint > test.max {
t.Fatalf("uint.random got %d, expected between %d and %d", gotUint, test.min, test.max)
}
})
}
}
func TestBadUintRandom(t *testing.T) {
tests := []struct {
name string
params map[string]any
payload any
errorString string
}{
{
name: "no min param",
payload: "hello",
params: map[string]any{"max": 10.0},
errorString: "uint.random requires a min parameter",
},
{
name: "no max param",
payload: "hello",
params: map[string]any{"min": 1.0},
errorString: "uint.random requires a max parameter",
},
{
name: "min param not a number",
payload: "hello",
params: map[string]any{"min": "1", "max": 10.0},
errorString: "uint.random min must be a number",
},
{
name: "max param not a number",
payload: "hello",
params: map[string]any{"min": 1.0, "max": "10"},
errorString: "uint.random max must be a number",
},
{
name: "max less than min",
payload: "hello",
params: map[string]any{"min": 1.0, "max": 0.0},
errorString: "uint.random max must be greater than min",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
registration, ok := processor.ProcessorRegistry["uint.random"]
if !ok {
t.Fatalf("uint.random processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "uint.random",
Params: test.params,
})
if err != nil {
if test.errorString != err.Error() {
t.Fatalf("uint.random got error '%s', expected '%s'", err.Error(), test.errorString)
}
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
if err == nil {
t.Fatalf("uint.random expected to fail but got payload: %s", got)
}
if err.Error() != test.errorString {
t.Fatalf("uint.random got error '%s', expected '%s'", err.Error(), test.errorString)
}
})
}
}

View File

@@ -6,6 +6,9 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
)
type routeContextKey string
@@ -21,14 +24,14 @@ type RouteError struct {
type RouteIOError struct {
Index int
OutputErrors []error
OutputError error
ProcessError error
InputError error
}
type RouteIO interface {
HandleInput(ctx context.Context, sourceId string, payload any) (bool, []RouteIOError)
HandleOutput(ctx context.Context, destinationId string, payload any) []error
HandleOutput(ctx context.Context, destinationId string, payload any) error
}
type Route interface {
@@ -73,17 +76,32 @@ func (r *ProcessorRoute) Output() string {
}
func (r *ProcessorRoute) ProcessPayload(ctx context.Context, payload any) (any, error) {
for _, processor := range r.processors {
processedPayload, err := processor.Process(ctx, payload)
parentSpan := trace.SpanFromContext(ctx)
tracer := parentSpan.TracerProvider().Tracer("route.ProcessPayload")
processCtx, processSpan := tracer.Start(ctx, "route.process")
defer processSpan.End()
for processorIndex, processor := range r.processors {
processorCtx, processorSpan := tracer.Start(processCtx, "route.processor", trace.WithAttributes(attribute.Int("processor.index", processorIndex), attribute.String("processor.type", processor.Type())))
processedPayload, err := processor.Process(processorCtx, payload)
if err != nil {
processorSpan.SetStatus(codes.Error, "route processor error")
processorSpan.RecordError(err)
processorSpan.End()
processSpan.SetStatus(codes.Error, "route processing error")
processSpan.RecordError(err)
return nil, err
}
processorSpan.SetStatus(codes.Ok, "processor successful")
//NOTE(jwetzell) nil payload will result in the route being "terminated"
if processedPayload == nil {
processSpan.SetStatus(codes.Ok, "route processing terminated early due to nil payload")
processorSpan.End()
return nil, nil
}
payload = processedPayload
processorSpan.End()
}
processSpan.SetStatus(codes.Ok, "route processing successful")
return payload, nil
}

226
router.go
View File

@@ -9,87 +9,131 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/module"
"github.com/jwetzell/showbridge-go/internal/route"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
)
type Router struct {
contextCancel context.CancelFunc
Context context.Context
ModuleInstances []module.Module
RouteInstances []route.Route
moduleWait sync.WaitGroup
logger *slog.Logger
ModuleInstances map[string]module.Module
// TODO(jwetzell): change to something easier to lookup
RouteInstances []route.Route
moduleWait sync.WaitGroup
logger *slog.Logger
tracer trace.Tracer
runningConfig config.Config
}
func NewRouter(ctx context.Context, config config.Config) (*Router, []module.ModuleError, []route.RouteError) {
routerContext, cancel := context.WithCancel(ctx)
router := Router{
contextCancel: cancel,
ModuleInstances: []module.Module{},
RouteInstances: []route.Route{},
logger: slog.Default().With("component", "router"),
func (r *Router) addModule(moduleDecl config.ModuleConfig) error {
if moduleDecl.Id == "" {
return errors.New("module id cannot be empty")
}
moduleInfo, ok := module.ModuleRegistry[moduleDecl.Type]
if !ok {
return errors.New("module type not defined")
}
router.Context = context.WithValue(routerContext, route.RouterContextKey, &router)
_, ok = r.ModuleInstances[moduleDecl.Id]
if ok {
return errors.New("module id already exists")
}
moduleInstance, err := moduleInfo.New(moduleDecl)
if err != nil {
return err
}
r.ModuleInstances[moduleDecl.Id] = moduleInstance
return nil
}
func (r *Router) removeModule(moduleId string) error {
err := r.stopModule(moduleId)
if err != nil {
return err
}
delete(r.ModuleInstances, moduleId)
return nil
}
func (r *Router) startModule(ctx context.Context, moduleId string) error {
moduleInstance := r.getModule(moduleId)
if moduleInstance == nil {
return errors.New("module id not found")
}
r.moduleWait.Go(func() {
err := moduleInstance.Start(ctx)
if err != nil {
// TODO(jwetzell): propagate module run errors better
r.logger.Error("error encountered running module", "moduleId", moduleId, "error", err)
}
})
return nil
}
func (r *Router) stopModule(moduleId string) error {
moduleInstance := r.getModule(moduleId)
if moduleInstance == nil {
return errors.New("module id not found")
}
moduleInstance.Stop()
return nil
}
// TODO(jwetzell): support removing route
func (r *Router) addRoute(routeDecl config.RouteConfig) error {
routeInstance, err := route.NewRoute(routeDecl)
if err != nil {
return err
}
r.RouteInstances = append(r.RouteInstances, routeInstance)
return nil
}
func (r *Router) getModule(moduleId string) module.Module {
moduleInstance, ok := r.ModuleInstances[moduleId]
if !ok {
return nil
}
return moduleInstance
}
func NewRouter(config config.Config, tracer trace.Tracer) (*Router, []module.ModuleError, []route.RouteError) {
router := Router{
ModuleInstances: make(map[string]module.Module),
RouteInstances: []route.Route{},
logger: slog.Default().With("component", "router"),
tracer: tracer,
runningConfig: config,
}
router.logger.Debug("creating")
var moduleErrors []module.ModuleError
for moduleIndex, moduleDecl := range config.Modules {
moduleInfo, ok := module.ModuleRegistry[moduleDecl.Type]
if !ok {
err := router.addModule(moduleDecl)
if err != nil {
if moduleErrors == nil {
moduleErrors = []module.ModuleError{}
}
moduleErrors = append(moduleErrors, module.ModuleError{
Index: moduleIndex,
Config: moduleDecl,
Error: errors.New("module type not defined"),
Error: err,
})
continue
}
moduleInstanceExists := false
for _, moduleInstance := range router.ModuleInstances {
if moduleInstance.Id() == moduleDecl.Id {
moduleInstanceExists = true
if moduleErrors == nil {
moduleErrors = []module.ModuleError{}
}
moduleErrors = append(moduleErrors, module.ModuleError{
Index: moduleIndex,
Config: moduleDecl,
Error: errors.New("duplicate module id"),
})
break
}
}
if !moduleInstanceExists {
moduleInstance, err := moduleInfo.New(router.Context, moduleDecl)
if err != nil {
if moduleErrors == nil {
moduleErrors = []module.ModuleError{}
}
moduleErrors = append(moduleErrors, module.ModuleError{
Index: moduleIndex,
Config: moduleDecl,
Error: err,
})
continue
}
router.ModuleInstances = append(router.ModuleInstances, moduleInstance)
}
}
var routeErrors []route.RouteError
for routeIndex, routeDecl := range config.Routes {
routeInstance, err := route.NewRoute(routeDecl)
err := router.addRoute(routeDecl)
if err != nil {
if routeErrors == nil {
routeErrors = []route.RouteError{}
@@ -101,21 +145,21 @@ func NewRouter(ctx context.Context, config config.Config) (*Router, []module.Mod
})
continue
}
router.RouteInstances = append(router.RouteInstances, routeInstance)
}
return &router, moduleErrors, routeErrors
}
func (r *Router) Run() {
func (r *Router) Start(ctx context.Context) {
r.logger.Info("running")
for _, moduleInstance := range r.ModuleInstances {
r.moduleWait.Go(func() {
err := moduleInstance.Run()
if err != nil {
r.logger.Error("error encountered running module", "error", err)
}
})
routerContext, cancel := context.WithCancel(ctx)
r.Context = routerContext
r.contextCancel = cancel
contextWithRouter := context.WithValue(routerContext, route.RouterContextKey, r)
for moduleId := range r.ModuleInstances {
// TODO(jwetzell): handle module run errors
r.startModule(contextWithRouter, moduleId)
}
<-r.Context.Done()
r.logger.Debug("waiting for modules to exit")
@@ -124,11 +168,13 @@ func (r *Router) Run() {
}
func (r *Router) Stop() {
r.logger.Debug("stopping")
r.logger.Info("stopping")
r.contextCancel()
}
func (r *Router) HandleInput(ctx context.Context, sourceId string, payload any) (bool, []route.RouteIOError) {
spanCtx, span := r.tracer.Start(ctx, "router.input", trace.WithAttributes(attribute.String("source.id", sourceId)), trace.WithNewRoot())
defer span.End()
var routeIOErrors []route.RouteIOError
routeFound := false
@@ -139,9 +185,10 @@ func (r *Router) HandleInput(ctx context.Context, sourceId string, payload any)
routeWaitGroup.Go(func() {
routeFound = true
routeContext := context.WithValue(ctx, route.SourceContextKey, sourceId)
routeContext := context.WithValue(spanCtx, route.SourceContextKey, sourceId)
payload, err := routeInstance.ProcessPayload(routeContext, payload)
routeCtx, routeSpan := r.tracer.Start(routeContext, "route", trace.WithAttributes(attribute.Int("route.index", routeIndex), attribute.String("route.input", routeInstance.Input()), attribute.String("route.output", routeInstance.Output())))
payload, err := routeInstance.ProcessPayload(routeCtx, payload)
if err != nil {
if routeIOErrors == nil {
routeIOErrors = []route.RouteIOError{}
@@ -159,38 +206,53 @@ func (r *Router) HandleInput(ctx context.Context, sourceId string, payload any)
return
}
outputErrors := r.HandleOutput(routeContext, routeInstance.Output(), payload)
if outputErrors != nil {
outputError := r.HandleOutput(routeCtx, routeInstance.Output(), payload)
if outputError != nil {
if routeIOErrors == nil {
routeIOErrors = []route.RouteIOError{}
}
routeIOErrors = append(routeIOErrors, route.RouteIOError{
Index: routeIndex,
OutputErrors: outputErrors,
Index: routeIndex,
OutputError: outputError,
})
}
routeSpan.End()
})
}
}
routeWaitGroup.Wait()
return routeFound, routeIOErrors
}
func (r *Router) HandleOutput(ctx context.Context, destinationId string, payload any) []error {
func (r *Router) HandleOutput(ctx context.Context, destinationId string, payload any) error {
spanCtx, span := r.tracer.Start(ctx, "router.output", trace.WithAttributes(attribute.String("destination.id", destinationId)))
defer span.End()
var outputErrors []error
for _, moduleInstance := range r.ModuleInstances {
if moduleInstance.Id() == destinationId {
err := moduleInstance.Output(ctx, payload)
if err != nil {
if outputErrors == nil {
outputErrors = []error{}
}
outputErrors = append(outputErrors, err)
r.logger.Error("unable to route output", "module", moduleInstance.Id(), "error", err)
}
}
destinationModule := r.getModule(destinationId)
if destinationModule == nil {
err := errors.New("no module found for destination id")
span.SetStatus(codes.Error, err.Error())
span.RecordError(err)
r.logger.Error("no module found for destination id", "destinationId", destinationId)
return err
}
return outputErrors
moduleOutputCtx, moduleOutputSpan := r.tracer.Start(spanCtx, "module.output", trace.WithAttributes(attribute.String("module.id", destinationModule.Id()), attribute.String("module.type", destinationModule.Type())))
defer moduleOutputSpan.End()
err := destinationModule.Output(moduleOutputCtx, payload)
if err != nil {
moduleOutputSpan.SetStatus(codes.Error, err.Error())
moduleOutputSpan.RecordError(err)
r.logger.Error("module output encountered error", "module", destinationModule.Id(), "error", err)
return err
} else {
moduleOutputSpan.SetStatus(codes.Ok, "module output successful")
}
return nil
}
func (r *Router) RunningConfig() config.Config {
return r.runningConfig
}

View File

@@ -2,56 +2,68 @@ package showbridge_test
import (
"context"
"errors"
"fmt"
"log/slog"
"sync"
"testing"
"time"
"github.com/jwetzell/showbridge-go"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/module"
"github.com/jwetzell/showbridge-go/internal/route"
"go.opentelemetry.io/otel"
)
type MockModule struct {
var (
tracer = otel.Tracer("showbridge.test")
)
type MockCounterModule struct {
config config.ModuleConfig
ctx context.Context
outputCount int
router route.RouteIO
logger *slog.Logger
cancel context.CancelFunc
}
func (m *MockModule) Id() string {
return m.config.Id
func (mcm *MockCounterModule) Id() string {
return mcm.config.Id
}
func (m *MockModule) Output(context.Context, any) error {
m.outputCount += 1
func (mcm *MockCounterModule) Output(context.Context, any) error {
mcm.outputCount += 1
return nil
}
func (m *MockModule) Run() error {
<-m.ctx.Done()
func (mcm *MockCounterModule) Start(ctx context.Context) error {
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return fmt.Errorf("mock.counter could not get router from context")
}
mcm.router = router
moduleContext, cancel := context.WithCancel(ctx)
mcm.ctx = moduleContext
mcm.cancel = cancel
<-mcm.ctx.Done()
return nil
}
func (m *MockModule) Type() string {
return m.config.Type
func (mcm *MockCounterModule) Type() string {
return mcm.config.Type
}
func (mcm *MockCounterModule) Stop() {
mcm.cancel()
}
func init() {
module.RegisterModule(module.ModuleRegistration{
Type: "mock.counter",
New: func(ctx context.Context, config config.ModuleConfig) (module.Module, error) {
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
if !ok {
return nil, errors.New("mock.counter unable to get router from context")
}
return &MockModule{config: config, ctx: ctx, router: router, logger: slog.Default()}, nil
New: func(config config.ModuleConfig) (module.Module, error) {
return &MockCounterModule{config: config, logger: slog.Default()}, nil
},
})
}
@@ -66,7 +78,7 @@ func TestNewRouter(t *testing.T) {
},
}
_, moduleErrors, routeErrors := showbridge.NewRouter(t.Context(), routerConfig)
_, moduleErrors, routeErrors := showbridge.NewRouter(routerConfig, tracer)
if moduleErrors != nil {
t.Fatalf("router should not have returned any module errors: %v", moduleErrors)
@@ -77,6 +89,23 @@ func TestNewRouter(t *testing.T) {
}
}
func TestNewRouterNoModuleId(t *testing.T) {
routerConfig := config.Config{
Modules: []config.ModuleConfig{
{
Id: "",
Type: "mock.counter",
},
},
}
_, moduleErrors, _ := showbridge.NewRouter(routerConfig, tracer)
if moduleErrors == nil {
t.Fatalf("router should have returned 'unknown module' module errors")
}
}
func TestNewRouterUnknownModuleType(t *testing.T) {
routerConfig := config.Config{
Modules: []config.ModuleConfig{
@@ -87,7 +116,7 @@ func TestNewRouterUnknownModuleType(t *testing.T) {
},
}
_, moduleErrors, _ := showbridge.NewRouter(t.Context(), routerConfig)
_, moduleErrors, _ := showbridge.NewRouter(routerConfig, tracer)
if moduleErrors == nil {
t.Fatalf("router should have returned 'unknown module' module errors")
@@ -108,7 +137,7 @@ func TestNewRouterDuplicateModuleId(t *testing.T) {
},
}
_, moduleErrors, _ := showbridge.NewRouter(t.Context(), routerConfig)
_, moduleErrors, _ := showbridge.NewRouter(routerConfig, tracer)
if moduleErrors == nil {
t.Fatalf("router should have returned 'duplicate id' module error")
@@ -131,7 +160,7 @@ func TestRouterInputSingleRoute(t *testing.T) {
},
}
router, moduleErrors, routeErrors := showbridge.NewRouter(t.Context(), routerConfig)
router, moduleErrors, routeErrors := showbridge.NewRouter(routerConfig, tracer)
if moduleErrors != nil {
t.Fatalf("router should not have returned any module errors: %v", moduleErrors)
@@ -144,9 +173,12 @@ func TestRouterInputSingleRoute(t *testing.T) {
routerRunner := sync.WaitGroup{}
routerRunner.Go(func() {
router.Run()
router.Start(t.Context())
fmt.Println("router stopped")
})
time.Sleep(time.Second * 1)
defer router.Stop()
mockModuleInputCount := 3
@@ -164,7 +196,7 @@ func TestRouterInputSingleRoute(t *testing.T) {
for _, moduleInstance := range router.ModuleInstances {
if moduleInstance.Id() == "mock" {
mockModuleInstance, ok := moduleInstance.(*MockModule)
mockModuleInstance, ok := moduleInstance.(*MockCounterModule)
if !ok {
t.Fatalf("couldn't get mock module")
}
@@ -200,7 +232,7 @@ func TestRouterInputMultipleRoutes(t *testing.T) {
},
}
router, moduleErrors, routeErrors := showbridge.NewRouter(t.Context(), routerConfig)
router, moduleErrors, routeErrors := showbridge.NewRouter(routerConfig, tracer)
if moduleErrors != nil {
t.Fatalf("router should not have returned any module errors: %v", moduleErrors)
@@ -213,8 +245,9 @@ func TestRouterInputMultipleRoutes(t *testing.T) {
routerRunner := sync.WaitGroup{}
routerRunner.Go(func() {
router.Run()
router.Start(t.Context())
})
time.Sleep(time.Second * 1)
defer router.Stop()
@@ -233,7 +266,7 @@ func TestRouterInputMultipleRoutes(t *testing.T) {
for _, moduleInstance := range router.ModuleInstances {
if moduleInstance.Id() == "mock" {
mockModuleInstance, ok := moduleInstance.(*MockModule)
mockModuleInstance, ok := moduleInstance.(*MockCounterModule)
if !ok {
t.Fatalf("couldn't get mock module")
}
@@ -270,7 +303,7 @@ func TestRouterInputMultipleModules(t *testing.T) {
},
}
router, moduleErrors, routeErrors := showbridge.NewRouter(t.Context(), routerConfig)
router, moduleErrors, routeErrors := showbridge.NewRouter(routerConfig, tracer)
if moduleErrors != nil {
t.Fatalf("router should not have returned any module errors: %v", moduleErrors)
@@ -283,9 +316,11 @@ func TestRouterInputMultipleModules(t *testing.T) {
routerRunner := sync.WaitGroup{}
routerRunner.Go(func() {
router.Run()
router.Start(t.Context())
})
time.Sleep(time.Second * 1)
defer router.Stop()
mock1ModuleInputCount := 3
@@ -316,7 +351,7 @@ func TestRouterInputMultipleModules(t *testing.T) {
for _, moduleInstance := range router.ModuleInstances {
if moduleInstance.Id() == "mock1" {
mockModuleInstance, ok := moduleInstance.(*MockModule)
mockModuleInstance, ok := moduleInstance.(*MockCounterModule)
if !ok {
t.Fatalf("couldn't get mock module")
}
@@ -327,7 +362,7 @@ func TestRouterInputMultipleModules(t *testing.T) {
break
}
if moduleInstance.Id() == "mock2" {
mockModuleInstance, ok := moduleInstance.(*MockModule)
mockModuleInstance, ok := moduleInstance.(*MockCounterModule)
if !ok {
t.Fatalf("couldn't get mock module")
}

15
schema/config.schema.json Normal file
View File

@@ -0,0 +1,15 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://showbridge.io/config.schema.json",
"title": "Config",
"description": "showbridge config file",
"type": "object",
"properties": {
"modules": {
"$ref": "https://showbridge.io/modules.schema.json"
},
"routes": {
"$ref": "https://showbridge.io/routes.schema.json"
}
}
}

481
schema/modules.schema.json Normal file
View File

@@ -0,0 +1,481 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://showbridge.io/modules.schema.json",
"title": "Modules",
"description": "showbridge modules array",
"type": "array",
"items": {
"oneOf": [
{
"type": "object",
"title": "HTTPClientModule",
"properties": {
"id": {
"type": "string"
},
"type": {
"const": "http.client"
}
},
"required": ["id", "type"],
"additionalProperties": false
},
{
"type": "object",
"title": "HTTPServerModule",
"properties": {
"id": {
"type": "string"
},
"type": {
"const": "http.server"
},
"params": {
"type": "object",
"properties": {
"port": {
"type": "integer",
"minimum": 1,
"maximum": 65535
}
},
"required": ["port"],
"additionalProperties": false
}
},
"required": ["id", "type", "params"],
"additionalProperties": false
},
{
"type": "object",
"title": "TimeIntervalModule",
"properties": {
"id": {
"type": "string"
},
"type": {
"const": "time.interval"
},
"params": {
"type": "object",
"properties": {
"duration": {
"type": "integer"
}
},
"required": ["duration"],
"additionalProperties": false
}
},
"required": ["id", "type", "params"],
"additionalProperties": false
},
{
"type": "object",
"title": "TimeTimerModule",
"properties": {
"id": {
"type": "string"
},
"type": {
"const": "time.timer"
},
"params": {
"type": "object",
"properties": {
"duration": {
"type": "integer"
}
},
"required": ["duration"],
"additionalProperties": false
}
},
"required": ["id", "type", "params"],
"additionalProperties": false
},
{
"type": "object",
"title": "MIDIInputModule",
"properties": {
"id": {
"type": "string"
},
"type": {
"const": "midi.input"
},
"params": {
"type": "object",
"properties": {
"port": {
"type": "string"
}
},
"required": ["port"],
"additionalProperties": false
}
},
"required": ["id", "type", "params"],
"additionalProperties": false
},
{
"type": "object",
"title": "MIDIOutputModule",
"properties": {
"id": {
"type": "string"
},
"type": {
"const": "midi.output"
},
"params": {
"type": "object",
"properties": {
"port": {
"type": "string"
}
},
"required": ["port"],
"additionalProperties": false
}
},
"required": ["id", "type", "params"],
"additionalProperties": false
},
{
"type": "object",
"title": "MQTTClientModule",
"properties": {
"id": {
"type": "string"
},
"type": {
"const": "mqtt.client"
},
"params": {
"type": "object",
"properties": {
"broker": {
"type": "string"
},
"topic": {
"type": "string"
},
"clientId": {
"type": "string"
}
},
"required": ["broker", "topic", "clientId"],
"additionalProperties": false
}
},
"required": ["id", "type", "params"],
"additionalProperties": false
},
{
"type": "object",
"title": "NATSClientModule",
"properties": {
"id": {
"type": "string"
},
"type": {
"const": "nats.client"
},
"params": {
"type": "object",
"properties": {
"url": {
"type": "string"
},
"subject": {
"type": "string"
}
},
"required": ["url", "subject"],
"additionalProperties": false
}
},
"required": ["id", "type", "params"],
"additionalProperties": false
},
{
"type": "object",
"title": "PSNClientModule",
"properties": {
"id": {
"type": "string"
},
"type": {
"const": "psn.client"
}
},
"required": ["id", "type"],
"additionalProperties": false
},
{
"type": "object",
"title": "SerialClientModule",
"properties": {
"id": {
"type": "string"
},
"type": {
"const": "serial.client"
},
"params": {
"type": "object",
"properties": {
"port": {
"type": "string"
},
"baudRate": {
"type": "integer"
}
},
"required": ["port", "baudRate"],
"additionalProperties": false
}
},
"required": ["id", "type", "params"],
"additionalProperties": false
},
{
"type": "object",
"title": "SIPCallServerModule",
"properties": {
"id": {
"type": "string"
},
"type": {
"const": "sip.call.server"
},
"params": {
"type": "object",
"properties": {
"ip": {
"type": "string",
"default": "0.0.0.0"
},
"port": {
"type": "integer",
"minimum": 1,
"maximum": 65535,
"default": 5060
},
"transport": {
"type": "string",
"enum": ["udp", "tcp", "ws", "udp4", "tcp4"],
"default": "udp"
},
"userAgent": {
"type": "string",
"default": "showbridge"
}
},
"required": [],
"additionalProperties": false
}
},
"required": ["id", "type", "params"],
"additionalProperties": false
},
{
"type": "object",
"title": "SIPDTMFServerModule",
"properties": {
"id": {
"type": "string"
},
"type": {
"const": "sip.dtmf.server"
},
"params": {
"type": "object",
"properties": {
"ip": {
"type": "string",
"default": "0.0.0.0"
},
"port": {
"type": "integer",
"minimum": 1,
"maximum": 65535,
"default": 5060
},
"transport": {
"type": "string",
"enum": ["udp", "tcp", "ws", "udp4", "tcp4"],
"default": "udp"
},
"separator": {
"type": "string",
"minLength": 1,
"maxLength": 1
}
},
"required": ["separator"],
"additionalProperties": false
}
},
"required": ["id", "type", "params"],
"additionalProperties": false
},
{
"type": "object",
"title": "TCPClientModule",
"properties": {
"id": {
"type": "string"
},
"type": {
"const": "net.tcp.client"
},
"params": {
"type": "object",
"properties": {
"host": {
"type": "string"
},
"port": {
"type": "integer",
"minimum": 1,
"maximum": 65535
},
"framing": {
"type": "string",
"enum": ["LF", "CR", "CRLF", "SLIP", "RAW"]
}
},
"required": ["host", "port", "framing"],
"additionalProperties": false
}
},
"required": ["id", "type", "params"],
"additionalProperties": false
},
{
"type": "object",
"title": "TCPServerModule",
"properties": {
"id": {
"type": "string"
},
"type": {
"const": "net.tcp.server"
},
"params": {
"type": "object",
"properties": {
"ip": {
"type": "string",
"default": "0.0.0.0"
},
"port": {
"type": "integer",
"minimum": 1,
"maximum": 65535
},
"framing": {
"type": "string",
"enum": ["LF", "CR", "CRLF", "SLIP", "RAW"]
}
},
"required": ["port", "framing"],
"additionalProperties": false
}
},
"required": ["id", "type", "params"],
"additionalProperties": false
},
{
"type": "object",
"title": "UDPClientModule",
"properties": {
"id": {
"type": "string"
},
"type": {
"const": "net.udp.client"
},
"params": {
"type": "object",
"properties": {
"host": {
"type": "string"
},
"port": {
"type": "integer",
"minimum": 1,
"maximum": 65535
}
},
"required": ["host", "port"],
"additionalProperties": false
}
},
"required": ["id", "type", "params"],
"additionalProperties": false
},
{
"type": "object",
"title": "UDPMulticastModule",
"properties": {
"id": {
"type": "string"
},
"type": {
"const": "net.udp.multicast"
},
"params": {
"type": "object",
"properties": {
"ip": {
"type": "string"
},
"port": {
"type": "integer",
"minimum": 1,
"maximum": 65535
}
},
"required": ["ip", "port"],
"additionalProperties": false
}
},
"required": ["id", "type", "params"],
"additionalProperties": false
},
{
"type": "object",
"title": "UDPServerModule",
"properties": {
"id": {
"type": "string"
},
"type": {
"const": "net.udp.server"
},
"params": {
"type": "object",
"properties": {
"ip": {
"type": "string",
"default": "0.0.0.0"
},
"port": {
"type": "integer",
"minimum": 1,
"maximum": 65535
}
},
"required": ["port"],
"additionalProperties": false
}
},
"required": ["id", "type", "params"],
"additionalProperties": false
}
]
}
}

View File

@@ -0,0 +1,806 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://showbridge.io/processors.schema.json",
"title": "Processors",
"description": "showbridge processors array",
"type": "array",
"items": {
"oneOf": [
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "artnet.packet.decode"
}
},
"required": ["type"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "artnet.packet.encode"
}
},
"required": ["type"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "artnet.packet.filter"
},
"params": {
"type": "object",
"properties": {
"opCode": {
"type": "integer"
}
},
"required": ["opCode"],
"additionalProperties": false
}
},
"required": ["type", "params"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "debug.log"
}
},
"required": ["type"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "float.parse"
}
},
"required": ["type"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "freed.create"
},
"params": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"pan": {
"type": "string"
},
"tilt": {
"type": "string"
},
"roll": {
"type": "string"
},
"posX": {
"type": "string"
},
"posY": {
"type": "string"
},
"posZ": {
"type": "string"
},
"zoom": {
"type": "string"
},
"focus": {
"type": "string"
}
},
"required": [
"id",
"pan",
"tilt",
"roll",
"posX",
"posY",
"posZ",
"zoom",
"focus"
],
"additionalProperties": false
}
},
"required": ["type", "params"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "freed.decode"
}
},
"required": ["type"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "freed.encode"
}
},
"required": ["type"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "http.request.create"
},
"params": {
"type": "object",
"properties": {
"method": {
"type": "string",
"enum": ["GET", "POST"]
},
"url": {
"type": "string"
}
},
"required": ["method", "url"],
"additionalProperties": false
}
},
"required": ["type", "params"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "http.request.encode"
}
},
"required": ["type"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "http.request.filter"
},
"params": {
"type": "object",
"properties": {
"path": {
"type": "string"
},
"method": {
"type": "string",
"enum": ["GET", "POST"]
}
},
"required": ["path"],
"additionalProperties": false
}
},
"required": ["type", "params"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "http.response.create"
},
"params": {
"type": "object",
"properties": {
"status": {
"type": "integer"
},
"body": {
"type": "string"
}
},
"required": ["status", "body"],
"additionalProperties": false
}
},
"required": ["type", "params"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "http.response.encode"
}
},
"required": ["type"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "int.parse"
}
},
"required": ["type"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "int.random"
},
"params": {
"type": "object",
"properties": {
"min": {
"type": "integer"
},
"max": {
"type": "integer"
}
},
"required": ["min", "max"],
"additionalProperties": false
}
}
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "json.decode"
}
},
"required": ["type"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "json.encode"
}
},
"required": ["type"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "midi.message.create"
},
"params": {
"type": "object",
"oneOf": [
{
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["NoteOn", "noteon", "note_on"]
},
"channel": {
"type": "string"
},
"note": {
"type": "string"
},
"velocity": {
"type": "string"
}
},
"required": ["type", "channel", "note", "velocity"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["NoteOff", "noteoff", "note_off"]
},
"channel": {
"type": "string"
},
"note": {
"type": "string"
},
"velocity": {
"type": "string"
}
},
"required": ["type", "channel", "note", "velocity"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["ControlChange", "controlchange", "control_change"]
},
"channel": {
"type": "string"
},
"controller": {
"type": "string"
},
"value": {
"type": "string"
}
},
"required": ["type", "channel", "controller", "value"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["ProgramChange", "programchange", "program_change"]
},
"channel": {
"type": "string"
},
"program": {
"type": "string"
}
},
"required": ["type", "channel", "program"],
"additionalProperties": false
}
]
}
},
"required": ["type", "params"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "midi.message.decode"
}
},
"required": ["type"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "midi.message.encode"
}
},
"required": ["type"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "midi.message.filter"
},
"params": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["NoteOn", "NoteOff", "ControlChange", "ProgramChange"]
}
},
"required": ["type"],
"additionalProperties": false
}
},
"required": ["type", "params"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "midi.message.unpack"
}
},
"required": ["type"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "mqtt.message.create"
},
"params": {
"type": "object",
"properties": {
"topic": {
"type": "string"
},
"qos": {
"type": "number"
},
"retained": {
"type": "boolean"
},
"payload": {
"type": "string"
}
},
"required": ["topic", "qos", "retained", "payload"],
"additionalProperties": false
}
},
"required": ["type", "params"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "mqtt.message.encode"
}
},
"required": ["type"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "nats.message.create"
},
"params": {
"type": "object",
"properties": {
"subject": {
"type": "string"
},
"payload": {
"type": "string"
}
},
"required": ["subject", "payload"],
"additionalProperties": false
}
},
"required": ["type", "params"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "nats.message.encode"
}
},
"required": ["type"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "osc.message.create"
},
"params": {
"type": "object",
"properties": {
"address": {
"type": "string"
},
"args": {
"type": "array",
"items": {
"type": "string"
}
},
"types": {
"type": "string"
}
},
"required": ["address"],
"additionalProperties": false
}
},
"required": ["type", "params"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "osc.message.decode"
}
},
"required": ["type"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "osc.message.encode"
}
},
"required": ["type"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "osc.message.filter"
},
"params": {
"type": "object",
"properties": {
"address": {
"type": "string"
}
},
"required": ["address"],
"additionalProperties": false
}
},
"required": ["type", "params"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "script.expr"
},
"params": {
"type": "object",
"properties": {
"expression": {
"type": "string"
}
},
"required": ["expression"],
"additionalProperties": false
}
},
"required": ["type", "params"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "script.js"
},
"params": {
"type": "object",
"properties": {
"program": {
"type": "string"
}
},
"required": ["program"],
"additionalProperties": false
}
},
"required": ["type", "params"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "script.wasm"
},
"params": {
"type": "object",
"properties": {
"path": {
"type": "string"
},
"function": {
"type": "string",
"default": "process"
}
},
"required": ["path"],
"additionalProperties": false
}
},
"required": ["type", "params"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "string.create"
},
"params": {
"type": "object",
"properties": {
"template": {
"type": "string"
}
},
"required": ["template"]
}
},
"required": ["type", "params"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "string.decode"
}
},
"required": ["type"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "string.encode"
}
},
"required": ["type"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "string.filter"
},
"params": {
"type": "object",
"properties": {
"pattern": {
"type": "string"
}
},
"required": ["pattern"],
"additionalProperties": false
}
},
"required": ["type", "params"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "string.split"
},
"params": {
"type": "object",
"properties": {
"separator": {
"type": "string"
}
},
"required": ["separator"]
}
},
"required": ["type", "params"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "time.sleep"
},
"params": {
"type": "object",
"properties": {
"duration": {
"type": "integer"
}
},
"required": ["duration"]
}
},
"required": ["type", "params"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "uint.parse"
}
},
"required": ["type"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "uint.random"
},
"params": {
"type": "object",
"properties": {
"min": {
"type": "integer",
"minimum": 0
},
"max": {
"type": "integer",
"minimum": 0
}
},
"required": ["min", "max"],
"additionalProperties": false
}
}
}
]
}
}

22
schema/routes.schema.json Normal file
View File

@@ -0,0 +1,22 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://showbridge.io/routes.schema.json",
"title": "Routes",
"description": "showbridge routes array",
"type": "array",
"items": {
"type": "object",
"properties": {
"input": {
"type": "string"
},
"processors": {
"$ref": "https://showbridge.io/processors.schema.json"
},
"output": {
"type": "string"
}
},
"required": ["input", "output"]
}
}