mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-28 05:45:30 +00:00
Compare commits
238 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e1f1afb05a | ||
| d3b3021fd5 | |||
|
|
190c03f5dc | ||
|
|
c7d4af4747 | ||
|
|
094933a34b | ||
|
|
f40cd181e0 | ||
|
|
b1a35f71d2 | ||
|
|
fbb16cd243 | ||
|
|
6b9cabb976 | ||
|
|
4671d41a50 | ||
|
|
c773dd4293 | ||
|
|
f96957c235 | ||
|
|
1218da0091 | ||
|
|
f969d3484d | ||
|
|
36b085ef5c | ||
|
|
65f2259cf4 | ||
|
|
2b62c593e2 | ||
|
|
dbcbecbf11 | ||
|
|
9f9f941d13 | ||
|
|
7bb0b49459 | ||
|
|
91a89379c7 | ||
|
|
ebba7cd8fc | ||
|
|
5eab29b3b8 | ||
|
|
b5df389cb2 | ||
|
|
c1692b291e | ||
|
|
06d5dcf3e1 | ||
|
|
2222d09078 | ||
|
|
b2598ffede | ||
|
|
bab0c72d97 | ||
|
|
62d86bc79d | ||
|
|
5fe6a35b5b | ||
|
|
f57f9d8ce5 | ||
|
|
979addeff8 | ||
|
|
af92dbcce3 | ||
|
|
87947527d6 | ||
|
|
882af2948a | ||
|
|
e2e9fb5eb6 | ||
|
|
411888d8db | ||
|
|
e367d6eb5d | ||
|
|
7659f412fb | ||
|
|
85964f5e25 | ||
|
|
b9e8bb66c6 | ||
|
|
2f9ca82b81 | ||
|
|
25579cb941 | ||
|
|
9134f034c7 | ||
|
|
204ccab683 | ||
|
|
1361e16b28 | ||
|
|
6c9d1b317d | ||
|
|
53e5e7db9e | ||
|
|
13f7b9e927 | ||
|
|
9a50ca8cfe | ||
|
|
256eeac6a8 | ||
|
|
842495f010 | ||
|
|
0922ece656 | ||
|
|
4c7dd1b4d8 | ||
|
|
2fe2250a57 | ||
|
|
c91f14185a | ||
|
|
e32776b02c | ||
|
|
5bb3f08006 | ||
|
|
a0f3ee3b05 | ||
|
|
9843c116b2 | ||
|
|
71b6a6d4a8 | ||
|
|
bb3d939bcd | ||
|
|
97742d7e59 | ||
|
|
9646c3f2d3 | ||
|
|
26dc976565 | ||
|
|
70f64e83c7 | ||
|
|
13e5d4d85a | ||
|
|
bfd0d3a90a | ||
|
|
60e9253b51 | ||
|
|
5f056496ce | ||
|
|
279952f1ea | ||
|
|
94bc22928b | ||
|
|
e5e1ea9f63 | ||
|
|
1cdfe929b4 | ||
|
|
012c416432 | ||
|
|
0763b4d720 | ||
|
|
14f3ae74a7 | ||
|
|
c2b73ac710 | ||
|
|
57262c3377 | ||
|
|
1fb59cc947 | ||
|
|
2fbca6209e | ||
|
|
3fedb7ac92 | ||
|
|
3f4271b5ef | ||
|
|
1e3b2571fb | ||
|
|
4559c6efbd | ||
|
|
7e75fdb758 | ||
|
|
2127c6fd5b | ||
|
|
2a40fa561c | ||
|
|
1467d9de16 | ||
|
|
5fc7b7399f | ||
|
|
3d664fff67 | ||
|
|
9c03ad2c14 | ||
|
|
35262fd505 | ||
|
|
feccab91d5 | ||
|
|
b17e0489a5 | ||
|
|
97c1975c7f | ||
|
|
6336800641 | ||
|
|
d9ac6d1a85 | ||
|
|
be3b9e3d5a | ||
|
|
44cc2e322c | ||
|
|
5f9547fddb | ||
|
|
8d8c5d4073 | ||
|
|
6d382ecd20 | ||
|
|
f0aa5a9eb0 | ||
|
|
e84bd6ead4 | ||
|
|
3d54ac7a0d | ||
|
|
2eae266903 | ||
|
|
c7d407d507 | ||
|
|
2d74e14387 | ||
|
|
e2a0f4ef90 | ||
|
|
54307bc817 | ||
|
|
e95fb44064 | ||
|
|
36c0e9b23e | ||
|
|
b57faaccb9 | ||
|
|
814bb9c1dc | ||
|
|
6fa2c1a746 | ||
|
|
f273aedbc6 | ||
|
|
b6c1c5c600 | ||
|
|
b6ec615e40 | ||
|
|
216775c9c6 | ||
|
|
1bfee2186b | ||
|
|
fa612231fb | ||
|
|
c1161c5aa9 | ||
|
|
b1076ce1e4 | ||
|
|
7f5204aca0 | ||
|
|
f3d87e92f8 | ||
|
|
e50e269697 | ||
|
|
ca6aebadef | ||
|
|
818ddc18f4 | ||
|
|
3e7b245536 | ||
|
|
e996d84234 | ||
|
|
04c8ebbe06 | ||
|
|
0f57e123ce | ||
|
|
82ba1d5d10 | ||
|
|
20c53e4996 | ||
|
|
8132faaba6 | ||
|
|
5a0f21bd64 | ||
|
|
fd0f78733c | ||
|
|
65476d5ecc | ||
|
|
536bc2af4e | ||
|
|
b89d907759 | ||
|
|
a3c48de2ad | ||
|
|
8ca9d9940f | ||
|
|
53d0648774 | ||
|
|
cf2881e5c3 | ||
|
|
f437438dca | ||
|
|
6b3c470534 | ||
|
|
3bdff5309f | ||
|
|
3792d40bb1 | ||
|
|
0cca2e3be9 | ||
|
|
5447781232 | ||
|
|
c760b220c0 | ||
|
|
cb71b5c5b8 | ||
|
|
84fd7c1028 | ||
|
|
7bdf6e01b3 | ||
|
|
1b607f64cd | ||
|
|
28e9141cbc | ||
|
|
3b38110ffb | ||
|
|
25e8563cd1 | ||
|
|
80969ac1ff | ||
|
|
beb3664e3b | ||
|
|
6e53cbe8fd | ||
|
|
4ebaa48f93 | ||
|
|
79d535c283 | ||
|
|
85349f8540 | ||
|
|
e49900a3a7 | ||
|
|
1f706becdc | ||
|
|
13a494239e | ||
|
|
153de944a2 | ||
|
|
42c75074fe | ||
|
|
361b07ec00 | ||
|
|
8c4f0591e1 | ||
|
|
09ddc40f1f | ||
|
|
6382cf6944 | ||
|
|
0732113a02 | ||
|
|
e5db9a48a9 | ||
|
|
9502201261 | ||
|
|
9859aa8fd4 | ||
|
|
b7b05cbb77 | ||
|
|
7b1fe47039 | ||
|
|
0848d8ab6e | ||
|
|
c1bb2ff4cb | ||
|
|
50898b9130 | ||
|
|
05e68e90af | ||
|
|
cd4c3f59f2 | ||
|
|
50399fa811 | ||
|
|
2dd44a11fd | ||
|
|
b7a8b04a72 | ||
|
|
078e6ec68c | ||
|
|
b58187d6a9 | ||
|
|
38b8e44f04 | ||
|
|
dff33f722d | ||
|
|
572a54d3b2 | ||
|
|
6a21cc2639 | ||
|
|
0d4ec24a9b | ||
|
|
10c6e84682 | ||
|
|
7ac0ec7582 | ||
|
|
c25a36f09c | ||
|
|
8d2c022baf | ||
|
|
76318b4e10 | ||
|
|
633eaba0ec | ||
|
|
00b6f3660d | ||
|
|
a275cd2b78 | ||
|
|
5cb2f845a1 | ||
|
|
8f769f0a4a | ||
|
|
fdd4b341cb | ||
|
|
9a9bf10078 | ||
|
|
ea46885f70 | ||
|
|
fa8f0b7cfc | ||
|
|
d316147411 | ||
|
|
30564523d7 | ||
|
|
f7231e54c2 | ||
|
|
14de829e7a | ||
|
|
33a54eb24c | ||
|
|
3c6c50c914 | ||
|
|
da516f5102 | ||
|
|
1f88819428 | ||
|
|
df4f0f745d | ||
|
|
d86bff30cd | ||
|
|
22d8bbf88d | ||
|
|
925873a124 | ||
|
|
08308c1891 | ||
|
|
f68312ee84 | ||
|
|
cd1b5e1437 | ||
|
|
34af7d7aec | ||
|
|
df14024012 | ||
|
|
af39c16f30 | ||
|
|
7d2a3225a7 | ||
|
|
b5ffee022a | ||
|
|
cd264d9ed4 | ||
|
|
9d14e5929f | ||
|
|
8fe1463198 | ||
|
|
28a5d1ea90 | ||
|
|
e9d5931e9d | ||
|
|
d90f103d00 | ||
|
|
05b0de1dfd | ||
|
|
0d8dbab743 |
8
.github/dependabot.yml
vendored
8
.github/dependabot.yml
vendored
@@ -1,10 +1,10 @@
|
|||||||
version: 2
|
version: 2
|
||||||
updates:
|
updates:
|
||||||
- package-ecosystem: 'github-actions'
|
- package-ecosystem: "github-actions"
|
||||||
directory: '/'
|
directory: "/"
|
||||||
schedule:
|
schedule:
|
||||||
interval: 'weekly'
|
interval: "weekly"
|
||||||
- package-ecosystem: gomod
|
- package-ecosystem: gomod
|
||||||
directory: /
|
directory: /
|
||||||
schedule:
|
schedule:
|
||||||
interval: "weekly"
|
interval: "weekly"
|
||||||
|
|||||||
27
.github/labeler.yml
vendored
27
.github/labeler.yml
vendored
@@ -1,27 +0,0 @@
|
|||||||
config:
|
|
||||||
- changed-files:
|
|
||||||
- any-glob-to-any-file: 'internal/config/**'
|
|
||||||
|
|
||||||
framer:
|
|
||||||
- changed-files:
|
|
||||||
- any-glob-to-any-file: 'internal/framer/**'
|
|
||||||
|
|
||||||
module:
|
|
||||||
- changed-files:
|
|
||||||
- any-glob-to-any-file: 'internal/module/**'
|
|
||||||
|
|
||||||
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/**'
|
|
||||||
|
|
||||||
cli:
|
|
||||||
- changed-files:
|
|
||||||
- any-glob-to-any-file: 'cmd/showbridge/**'
|
|
||||||
2
.github/release.yml
vendored
2
.github/release.yml
vendored
@@ -26,4 +26,4 @@ changelog:
|
|||||||
- cli
|
- cli
|
||||||
- title: Other Changes
|
- title: Other Changes
|
||||||
labels:
|
labels:
|
||||||
- '*'
|
- "*"
|
||||||
|
|||||||
18
.github/workflows/label-pr.yaml
vendored
18
.github/workflows/label-pr.yaml
vendored
@@ -1,18 +0,0 @@
|
|||||||
# Taken from https://github.com/go-gitea/gitea
|
|
||||||
name: Add labels to PR
|
|
||||||
on:
|
|
||||||
pull_request_target:
|
|
||||||
types: [opened, synchronize, reopened]
|
|
||||||
concurrency:
|
|
||||||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
jobs:
|
|
||||||
labeler:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
pull-requests: write
|
|
||||||
steps:
|
|
||||||
- uses: actions/labeler@634933edcd8ababfe52f92936142cc22ac488b1b # v6.0.1
|
|
||||||
with:
|
|
||||||
sync-labels: true
|
|
||||||
12
.github/workflows/release-showbridge.yaml
vendored
12
.github/workflows/release-showbridge.yaml
vendored
@@ -19,7 +19,7 @@ jobs:
|
|||||||
- name: setup go
|
- name: setup go
|
||||||
uses: actions/setup-go@v6
|
uses: actions/setup-go@v6
|
||||||
with:
|
with:
|
||||||
go-version-file: 'go.mod'
|
go-version-file: "go.mod"
|
||||||
- name: release
|
- name: release
|
||||||
uses: goreleaser/goreleaser-action@v7
|
uses: goreleaser/goreleaser-action@v7
|
||||||
with:
|
with:
|
||||||
@@ -37,26 +37,26 @@ jobs:
|
|||||||
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
|
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
|
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
|
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
|
||||||
|
|
||||||
- name: Login to Docker Hub
|
- name: Login to Docker Hub
|
||||||
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
|
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Setup Docker metadata
|
- name: Setup Docker metadata
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
|
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0
|
||||||
with:
|
with:
|
||||||
images: |
|
images: |
|
||||||
jwetzell/showbridge
|
jwetzell/showbridge
|
||||||
|
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0
|
||||||
with:
|
with:
|
||||||
push: true
|
push: true
|
||||||
context: ./
|
context: ./
|
||||||
|
|||||||
20
.github/workflows/test-showbridge.yaml
vendored
20
.github/workflows/test-showbridge.yaml
vendored
@@ -5,16 +5,16 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
paths:
|
paths:
|
||||||
- '**/*.go'
|
- "**/*.go"
|
||||||
- 'go.mod'
|
- "go.mod"
|
||||||
- 'go.sum'
|
- "go.sum"
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
paths:
|
paths:
|
||||||
- '**/*.go'
|
- "**/*.go"
|
||||||
- 'go.mod'
|
- "go.mod"
|
||||||
- 'go.sum'
|
- "go.sum"
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
@@ -29,15 +29,15 @@ jobs:
|
|||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v6
|
||||||
- uses: actions/setup-go@v6
|
- uses: actions/setup-go@v6
|
||||||
with:
|
with:
|
||||||
go-version-file: 'go.mod'
|
go-version-file: "go.mod"
|
||||||
- name: mod tidy
|
- name: mod tidy
|
||||||
run: go mod tidy
|
run: go mod tidy
|
||||||
|
|
||||||
- name: run tests
|
- name: run tests
|
||||||
run: go test ./... -coverpkg "github.com/jwetzell/showbridge-go/..." -coverprofile coverage.out
|
run: go test ./... -count=1 -coverpkg "github.com/jwetzell/showbridge-go/..." -coverprofile coverage.out
|
||||||
|
|
||||||
- name: clean up coverage report
|
- name: clean up coverage report
|
||||||
run: cat coverage.out | grep -v "github.com/jwetzell/showbridge-go/cmd" > coverage.nocmd.out
|
run: cat coverage.out | grep -v "github.com/jwetzell/showbridge-go/cmd" > coverage.nocmd.out
|
||||||
- name: Update coverage report
|
- name: Update coverage report
|
||||||
uses: ncruces/go-coverage-report@v0.3.2
|
uses: ncruces/go-coverage-report@v0.3.2
|
||||||
with:
|
with:
|
||||||
@@ -45,5 +45,5 @@ jobs:
|
|||||||
report: true
|
report: true
|
||||||
chart: true
|
chart: true
|
||||||
amend: true
|
amend: true
|
||||||
if: github.event_name == 'push'
|
if: github.event_name == 'push'
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|||||||
33
.vscode/launch.json
vendored
33
.vscode/launch.json
vendored
@@ -1,18 +1,17 @@
|
|||||||
{
|
{
|
||||||
// Use IntelliSense to learn about possible attributes.
|
// Use IntelliSense to learn about possible attributes.
|
||||||
// Hover to view descriptions of existing attributes.
|
// Hover to view descriptions of existing attributes.
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
|
{
|
||||||
{
|
"name": "Launch showbridge",
|
||||||
"name": "Launch showbridge",
|
"type": "go",
|
||||||
"type": "go",
|
"request": "launch",
|
||||||
"request": "launch",
|
"mode": "auto",
|
||||||
"mode": "auto",
|
"program": "cmd/showbridge",
|
||||||
"program": "cmd/showbridge",
|
"args": ["--log-level", "debug"],
|
||||||
"args": ["--log-level", "debug"],
|
"cwd": "./"
|
||||||
"cwd": "./"
|
}
|
||||||
}
|
]
|
||||||
]
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
ARG GO_VERSION=1.25.5
|
ARG GO_VERSION=1.26.2
|
||||||
FROM golang:${GO_VERSION}-alpine AS build
|
FROM golang:${GO_VERSION}-alpine AS build
|
||||||
RUN apk --no-cache add ca-certificates tzdata
|
RUN apk --no-cache add ca-certificates tzdata git
|
||||||
WORKDIR /build
|
WORKDIR /build
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -3,7 +3,6 @@
|
|||||||
# showbridge (go edition)
|
# showbridge (go edition)
|
||||||
|
|
||||||
[](https://raw.githack.com/wiki/jwetzell/showbridge-go/coverage.html)
|
[](https://raw.githack.com/wiki/jwetzell/showbridge-go/coverage.html)
|
||||||
|
|
||||||
Simple protocol router _/s_
|
Simple protocol router _/s_
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@@ -14,6 +13,7 @@ Simple protocol router _/s_
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
### Supported Protocols
|
### Supported Protocols
|
||||||
|
|
||||||
- HTTP
|
- HTTP
|
||||||
- UDP
|
- UDP
|
||||||
- TCP
|
- TCP
|
||||||
@@ -25,7 +25,8 @@ Simple protocol router _/s_
|
|||||||
- [OSC](https://opensoundcontrol.stanford.edu/spec-1_0.html)
|
- [OSC](https://opensoundcontrol.stanford.edu/spec-1_0.html)
|
||||||
- [FreeD](https://ptzoptics.com/freed/)
|
- [FreeD](https://ptzoptics.com/freed/)
|
||||||
- [SIP](https://en.wikipedia.org/wiki/Session_Initiation_Protocol)
|
- [SIP](https://en.wikipedia.org/wiki/Session_Initiation_Protocol)
|
||||||
|
- [Redis](https://redis.io/)
|
||||||
|
|
||||||
### CLI Usage
|
### CLI Usage
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -36,9 +37,10 @@ USAGE:
|
|||||||
showbridge [global options]
|
showbridge [global options]
|
||||||
|
|
||||||
GLOBAL OPTIONS:
|
GLOBAL OPTIONS:
|
||||||
--config string path to config file (default: "./config.yaml")
|
--config string path to config file (default: "./config.yaml") [$SHOWBRIDGE_CONFIG]
|
||||||
--log-level string set log level (default: "info")
|
--log-level string set log level (default: "info") [$SHOWBRIDGE_LOG_LEVEL]
|
||||||
--log-format string log format to use (default: "text")
|
--log-format string log format to use (default: "text") [$SHOWBRIDGE_LOG_FORMAT]
|
||||||
|
--trace enable OpenTelemetry tracing [$SHOWBRIDGE_TRACE]
|
||||||
--help, -h show help
|
--help, -h show help
|
||||||
--version, -v print the version
|
--version, -v print the version
|
||||||
```
|
```
|
||||||
|
|||||||
255
api.go
Normal file
255
api.go
Normal file
@@ -0,0 +1,255 @@
|
|||||||
|
package showbridge
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
_ "embed"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/module"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/route"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (r *Router) startAPIServer(config config.ApiConfig) {
|
||||||
|
if !config.Enabled {
|
||||||
|
r.logger.Warn("API not enabled")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r.logger.Debug("starting API server", "port", config.Port)
|
||||||
|
mux := http.NewServeMux()
|
||||||
|
mux.HandleFunc("/ws", r.handleWebsocket)
|
||||||
|
mux.HandleFunc("/health", r.handleHealthHTTP)
|
||||||
|
mux.HandleFunc("/api/v1/config", r.handleConfigHTTP)
|
||||||
|
mux.HandleFunc("/schema/config.schema.json", handleConfigSchema)
|
||||||
|
mux.HandleFunc("/schema/routes.schema.json", handleRoutesSchema)
|
||||||
|
mux.HandleFunc("/schema/modules.schema.json", handleModulesSchema)
|
||||||
|
mux.HandleFunc("/schema/processors.schema.json", handleProcessorsSchema)
|
||||||
|
|
||||||
|
r.apiServerMu.Lock()
|
||||||
|
defer r.apiServerMu.Unlock()
|
||||||
|
r.apiServer = &http.Server{
|
||||||
|
Addr: fmt.Sprintf(":%d", config.Port),
|
||||||
|
Handler: mux,
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
r.apiServer.ListenAndServe()
|
||||||
|
r.apiServerShutdown()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Router) stopAPIServer() {
|
||||||
|
if r.apiServer == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r.logger.Debug("stopping API server")
|
||||||
|
r.apiServerMu.Lock()
|
||||||
|
defer r.apiServerMu.Unlock()
|
||||||
|
if r.apiServer != nil {
|
||||||
|
apiShutdownCtx, apiShutdownCancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
|
r.apiServerShutdown = apiShutdownCancel
|
||||||
|
r.apiServer.Shutdown(apiShutdownCtx)
|
||||||
|
<-apiShutdownCtx.Done()
|
||||||
|
r.apiServer = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Router) handleHealthHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
|
switch req.Method {
|
||||||
|
case http.MethodGet:
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
case http.MethodOptions:
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
|
||||||
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
default:
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Router) handleConfigHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
|
switch req.Method {
|
||||||
|
case http.MethodGet:
|
||||||
|
configJSON, err := json.Marshal(r.runningConfig)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.Write(configJSON)
|
||||||
|
case http.MethodPut:
|
||||||
|
if r.updatingConfig {
|
||||||
|
http.Error(w, "Config update in progress.", http.StatusConflict)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//TODO(jwetzell): again way too much marshaling
|
||||||
|
cfgBytes, err := io.ReadAll(req.Body)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Bad request", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cfgMap := make(map[string]any)
|
||||||
|
err = json.Unmarshal(cfgBytes, &cfgMap)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Bad request", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = schema.ApplyDefaults(&cfgMap)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = schema.ValidateConfig(cfgMap)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
validCfgBytes, err := json.Marshal(cfgMap)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var newConfig config.Config
|
||||||
|
err = json.Unmarshal(validCfgBytes, &newConfig)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Bad request", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
moduleErrors, routeErrors := r.UpdateConfig(newConfig)
|
||||||
|
if len(moduleErrors) > 0 || len(routeErrors) > 0 {
|
||||||
|
errorResponse := struct {
|
||||||
|
ModuleErrors []module.ModuleError `json:"moduleErrors,omitempty"`
|
||||||
|
RouteErrors []route.RouteError `json:"routeErrors,omitempty"`
|
||||||
|
}{
|
||||||
|
ModuleErrors: moduleErrors,
|
||||||
|
RouteErrors: routeErrors,
|
||||||
|
}
|
||||||
|
errorResponseJSON, err := json.Marshal(errorResponse)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
w.Write(errorResponseJSON)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
r.ConfigChange <- newConfig
|
||||||
|
case http.MethodOptions:
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Access-Control-Allow-Methods", "GET, PUT, OPTIONS")
|
||||||
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
default:
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleConfigSchema(w http.ResponseWriter, req *http.Request) {
|
||||||
|
switch req.Method {
|
||||||
|
case http.MethodGet:
|
||||||
|
schemaJSON, err := json.Marshal(schema.ConfigSchema)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.Write(schemaJSON)
|
||||||
|
case http.MethodOptions:
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
|
||||||
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
default:
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleRoutesSchema(w http.ResponseWriter, req *http.Request) {
|
||||||
|
switch req.Method {
|
||||||
|
case http.MethodGet:
|
||||||
|
schemaJSON, err := json.Marshal(schema.RoutesConfigSchema)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.Write(schemaJSON)
|
||||||
|
case http.MethodOptions:
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
|
||||||
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
default:
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleModulesSchema(w http.ResponseWriter, req *http.Request) {
|
||||||
|
switch req.Method {
|
||||||
|
case http.MethodGet:
|
||||||
|
schemaJSON, err := json.Marshal(schema.GetModulesSchema())
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.Write(schemaJSON)
|
||||||
|
case http.MethodOptions:
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
|
||||||
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
default:
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleProcessorsSchema(w http.ResponseWriter, req *http.Request) {
|
||||||
|
switch req.Method {
|
||||||
|
case http.MethodGet:
|
||||||
|
schemaJSON, err := json.Marshal(schema.GetProcessorsSchema())
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.Write(schemaJSON)
|
||||||
|
case http.MethodOptions:
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
|
||||||
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
default:
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,7 +15,7 @@ builds:
|
|||||||
- "amd64"
|
- "amd64"
|
||||||
- "arm64"
|
- "arm64"
|
||||||
ldflags:
|
ldflags:
|
||||||
- '-s -w -X main.version={{.RawVersion}}-{{.ShortCommit}}'
|
- "-s -w -X main.version={{.RawVersion}}-{{.ShortCommit}}"
|
||||||
|
|
||||||
archives:
|
archives:
|
||||||
- formats: [tar.gz]
|
- formats: [tar.gz]
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
@@ -13,12 +14,15 @@ import (
|
|||||||
|
|
||||||
"github.com/jwetzell/showbridge-go"
|
"github.com/jwetzell/showbridge-go"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/module"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/route"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/schema"
|
||||||
"github.com/urfave/cli/v3"
|
"github.com/urfave/cli/v3"
|
||||||
"go.opentelemetry.io/otel"
|
"go.opentelemetry.io/otel"
|
||||||
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
|
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
|
||||||
"go.opentelemetry.io/otel/sdk/resource"
|
"go.opentelemetry.io/otel/sdk/resource"
|
||||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||||
semconv "go.opentelemetry.io/otel/semconv/v1.39.0"
|
semconv "go.opentelemetry.io/otel/semconv/v1.40.0"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -34,9 +38,10 @@ func main() {
|
|||||||
Version: version,
|
Version: version,
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "config",
|
Name: "config",
|
||||||
Value: "./config.yaml",
|
Value: "./config.yaml",
|
||||||
Usage: "path to config file",
|
Usage: "path to config file",
|
||||||
|
Sources: cli.EnvVars("SHOWBRIDGE_CONFIG"),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "log-level",
|
Name: "log-level",
|
||||||
@@ -49,6 +54,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
Sources: cli.EnvVars("SHOWBRIDGE_LOG_LEVEL"),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "log-format",
|
Name: "log-format",
|
||||||
@@ -61,11 +67,13 @@ func main() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
Sources: cli.EnvVars("SHOWBRIDGE_LOG_FORMAT"),
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "trace",
|
Name: "trace",
|
||||||
Value: false,
|
Value: false,
|
||||||
Usage: "enable OpenTelemetry tracing",
|
Usage: "enable OpenTelemetry tracing",
|
||||||
|
Sources: cli.EnvVars("SHOWBRIDGE_TRACE"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: run,
|
Action: run,
|
||||||
@@ -101,7 +109,28 @@ func readConfig(configPath string) (config.Config, error) {
|
|||||||
return config.Config{}, err
|
return config.Config{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = yaml.Unmarshal(configBytes, &cfg)
|
//TODO(jwetzell): this is an annoying amount of marshaling
|
||||||
|
|
||||||
|
yamlMap := make(map[string]any)
|
||||||
|
|
||||||
|
err = yaml.Unmarshal(configBytes, &yamlMap)
|
||||||
|
if err != nil {
|
||||||
|
return config.Config{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = schema.ApplyDefaults(&yamlMap)
|
||||||
|
if err != nil {
|
||||||
|
return config.Config{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = schema.ValidateConfig(yamlMap)
|
||||||
|
if err != nil {
|
||||||
|
return config.Config{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
validatedConfigBytes, err := json.Marshal(yamlMap)
|
||||||
|
|
||||||
|
err = json.Unmarshal(validatedConfigBytes, &cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return config.Config{}, err
|
return config.Config{}, err
|
||||||
}
|
}
|
||||||
@@ -109,6 +138,20 @@ func readConfig(configPath string) (config.Config, error) {
|
|||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func writeConfig(configPath string, newConfig config.Config) error {
|
||||||
|
configBytes, err := yaml.Marshal(newConfig)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.WriteFile(configPath, configBytes, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func run(ctx context.Context, c *cli.Command) error {
|
func run(ctx context.Context, c *cli.Command) error {
|
||||||
configPath := c.String("config")
|
configPath := c.String("config")
|
||||||
if configPath == "" {
|
if configPath == "" {
|
||||||
@@ -173,7 +216,19 @@ func run(ctx context.Context, c *cli.Command) error {
|
|||||||
routerRunner: &sync.WaitGroup{},
|
routerRunner: &sync.WaitGroup{},
|
||||||
}
|
}
|
||||||
|
|
||||||
router, err := showbridgeApp.getNewRouter()
|
config, err := readConfig(showbridgeApp.configPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
router, moduleErrors, routeErrors := showbridge.NewRouter(config)
|
||||||
|
|
||||||
|
showbridgeApp.logConfigErrors(moduleErrors, routeErrors)
|
||||||
|
|
||||||
|
if moduleErrors != nil || routeErrors != nil {
|
||||||
|
return fmt.Errorf("errors initializing modules or routes")
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to initialize router: %w", err)
|
return fmt.Errorf("failed to initialize router: %w", err)
|
||||||
}
|
}
|
||||||
@@ -185,7 +240,7 @@ func run(ctx context.Context, c *cli.Command) error {
|
|||||||
})
|
})
|
||||||
showbridgeApp.routerMutex.Unlock()
|
showbridgeApp.routerMutex.Unlock()
|
||||||
|
|
||||||
go showbridgeApp.handleHangup()
|
go showbridgeApp.handleChannels()
|
||||||
|
|
||||||
<-showbridgeApp.ctx.Done()
|
<-showbridgeApp.ctx.Done()
|
||||||
showbridgeApp.logger.Debug("shutting down router")
|
showbridgeApp.logger.Debug("shutting down router")
|
||||||
@@ -195,40 +250,37 @@ func run(ctx context.Context, c *cli.Command) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *showbridgeApp) handleHangup() {
|
func (app *showbridgeApp) handleChannels() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-sigHangup:
|
case <-sigHangup:
|
||||||
app.logger.Info("received SIGHUP, reloading configuration")
|
app.logger.Info("received SIGHUP, reloading configuration")
|
||||||
newRouter, err := app.getNewRouter()
|
app.routerMutex.Lock()
|
||||||
|
config, err := readConfig(app.configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.logger.Error("failed to reload configuration", "error", err)
|
app.logger.Error("failed to read config file", "error", err)
|
||||||
|
app.routerMutex.Unlock()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
app.routerMutex.Lock()
|
moduleErrors, routeErrors := app.router.UpdateConfig(config)
|
||||||
app.router.Stop()
|
app.logConfigErrors(moduleErrors, routeErrors)
|
||||||
app.routerRunner.Wait()
|
|
||||||
app.router = newRouter
|
|
||||||
app.routerRunner.Go(func() {
|
|
||||||
app.router.Start(context.Background())
|
|
||||||
})
|
|
||||||
app.logger.Info("configuration reloaded successfully")
|
app.logger.Info("configuration reloaded successfully")
|
||||||
app.routerMutex.Unlock()
|
app.routerMutex.Unlock()
|
||||||
|
case config := <-app.router.ConfigChange:
|
||||||
|
app.logger.Info("router config changed updating config file")
|
||||||
|
err := writeConfig(app.configPath, config)
|
||||||
|
if err != nil {
|
||||||
|
app.logger.Error("failed to write config file", "error", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
app.logger.Info("config file updated successfully")
|
||||||
case <-app.ctx.Done():
|
case <-app.ctx.Done():
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *showbridgeApp) getNewRouter() (*showbridge.Router, error) {
|
func (app *showbridgeApp) logConfigErrors(moduleErrors []module.ModuleError, routeErrors []route.RouteError) {
|
||||||
// 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)
|
|
||||||
|
|
||||||
for _, moduleError := range moduleErrors {
|
for _, moduleError := range moduleErrors {
|
||||||
app.logger.Error("problem initializing module", "index", moduleError.Index, "error", moduleError.Error)
|
app.logger.Error("problem initializing module", "index", moduleError.Index, "error", moduleError.Error)
|
||||||
}
|
}
|
||||||
@@ -236,12 +288,6 @@ func (app *showbridgeApp) getNewRouter() (*showbridge.Router, error) {
|
|||||||
for _, routeError := range routeErrors {
|
for _, routeError := range routeErrors {
|
||||||
app.logger.Error("problem initializing route", "index", routeError.Index, "error", routeError.Error)
|
app.logger.Error("problem initializing route", "index", routeError.Index, "error", routeError.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
if moduleErrors != nil || routeErrors != nil {
|
|
||||||
return nil, fmt.Errorf("errors initializing modules or routes")
|
|
||||||
}
|
|
||||||
|
|
||||||
return router, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTracerProvider(exp sdktrace.SpanExporter) *sdktrace.TracerProvider {
|
func newTracerProvider(exp sdktrace.SpanExporter) *sdktrace.TracerProvider {
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
api:
|
||||||
|
enabled: true
|
||||||
|
port: 8080
|
||||||
modules:
|
modules:
|
||||||
- id: http
|
- id: http
|
||||||
type: http.server
|
type: http.server
|
||||||
@@ -13,6 +16,8 @@ routes:
|
|||||||
processors:
|
processors:
|
||||||
- type: osc.message.create
|
- type: osc.message.create
|
||||||
params:
|
params:
|
||||||
address: "{{.URL.Path}}"
|
address: "{{.Payload.URL.Path}}"
|
||||||
- type: osc.message.encode
|
- type: osc.message.encode
|
||||||
output: udp
|
- type: router.output
|
||||||
|
params:
|
||||||
|
module: udp
|
||||||
|
|||||||
64
events.go
Normal file
64
events.go
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
package showbridge
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/gorilla/websocket"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Event struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
Data any `json:"data,omitempty"`
|
||||||
|
Error string `json:"error,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e Event) toJSON() ([]byte, error) {
|
||||||
|
return json.Marshal(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Router) handleEvent(event Event, sender *websocket.Conn) {
|
||||||
|
switch event.Type {
|
||||||
|
case "ping":
|
||||||
|
r.unicastEvent(Event{Type: "pong"}, sender)
|
||||||
|
default:
|
||||||
|
r.logger.Warn("unknown event type", "eventType", event.Type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Router) unicastEvent(event Event, conn *websocket.Conn) {
|
||||||
|
eventJSON, err := event.toJSON()
|
||||||
|
if err != nil {
|
||||||
|
r.logger.Error("failed to marshal event to JSON", "error", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = conn.WriteMessage(websocket.TextMessage, eventJSON)
|
||||||
|
if err != nil {
|
||||||
|
r.logger.Error("failed to write message to websocket connection", "error", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Router) broadcastEvent(event Event, excluded ...*websocket.Conn) {
|
||||||
|
eventJSON, err := event.toJSON()
|
||||||
|
if err != nil {
|
||||||
|
r.logger.Error("failed to marshal event to JSON", "error", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r.wsConnsMu.Lock()
|
||||||
|
defer r.wsConnsMu.Unlock()
|
||||||
|
for _, conn := range r.wsConns {
|
||||||
|
exclude := false
|
||||||
|
for _, excludedConn := range excluded {
|
||||||
|
if conn == excludedConn {
|
||||||
|
exclude = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if exclude {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
err := conn.WriteMessage(websocket.TextMessage, eventJSON)
|
||||||
|
if err != nil {
|
||||||
|
r.logger.Error("failed to write message to websocket connection", "error", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
72
go.mod
72
go.mod
@@ -1,35 +1,40 @@
|
|||||||
module github.com/jwetzell/showbridge-go
|
module github.com/jwetzell/showbridge-go
|
||||||
|
|
||||||
go 1.25.5
|
go 1.26.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/eclipse/paho.mqtt.golang v1.5.1
|
github.com/eclipse/paho.mqtt.golang v1.5.1
|
||||||
github.com/emiago/diago v0.27.0
|
github.com/emiago/diago v0.28.0
|
||||||
github.com/emiago/sipgo v1.2.0
|
github.com/emiago/sipgo v1.3.0
|
||||||
github.com/expr-lang/expr v1.17.8
|
github.com/expr-lang/expr v1.17.8
|
||||||
github.com/extism/go-sdk v1.7.1
|
github.com/extism/go-sdk v1.7.1
|
||||||
|
github.com/google/jsonschema-go v0.4.2
|
||||||
|
github.com/gorilla/websocket v1.5.3
|
||||||
github.com/jwetzell/artnet-go v0.2.1
|
github.com/jwetzell/artnet-go v0.2.1
|
||||||
github.com/jwetzell/free-d-go v0.1.0
|
github.com/jwetzell/free-d-go v0.1.0
|
||||||
github.com/jwetzell/osc-go v0.1.0
|
github.com/jwetzell/osc-go v0.3.0
|
||||||
github.com/jwetzell/psn-go v0.3.0
|
github.com/jwetzell/psn-go v0.3.0
|
||||||
github.com/nats-io/nats-server/v2 v2.12.4
|
github.com/nats-io/nats-server/v2 v2.12.7
|
||||||
github.com/nats-io/nats.go v1.49.0
|
github.com/nats-io/nats.go v1.51.0
|
||||||
github.com/urfave/cli/v3 v3.6.2
|
github.com/redis/go-redis/v9 v9.18.0
|
||||||
gitlab.com/gomidi/midi/v2 v2.3.22
|
github.com/urfave/cli/v3 v3.8.0
|
||||||
|
gitlab.com/gomidi/midi/v2 v2.3.23
|
||||||
go.bug.st/serial v1.6.4
|
go.bug.st/serial v1.6.4
|
||||||
go.opentelemetry.io/otel v1.40.0
|
go.opentelemetry.io/otel v1.43.0
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.40.0
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.43.0
|
||||||
go.opentelemetry.io/otel/sdk v1.40.0
|
go.opentelemetry.io/otel/sdk v1.43.0
|
||||||
go.opentelemetry.io/otel/trace v1.40.0
|
go.opentelemetry.io/otel/trace v1.43.0
|
||||||
modernc.org/quickjs v0.17.1
|
modernc.org/quickjs v0.18.0
|
||||||
|
modernc.org/sqlite v1.49.1
|
||||||
sigs.k8s.io/yaml v1.6.0
|
sigs.k8s.io/yaml v1.6.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/antithesishq/antithesis-sdk-go v0.5.0-default-no-op // indirect
|
github.com/antithesishq/antithesis-sdk-go v0.6.0-default-no-op // indirect
|
||||||
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
|
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
github.com/creack/goselect v0.1.2 // indirect
|
github.com/creack/goselect v0.1.2 // indirect
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||||
github.com/dylibso/observe-sdk/go v0.0.0-20240819160327-2d926c5d788a // indirect
|
github.com/dylibso/observe-sdk/go v0.0.0-20240819160327-2d926c5d788a // indirect
|
||||||
github.com/emiago/dtls/v3 v3.0.0-20260122183559-8b8d23e359c0 // indirect
|
github.com/emiago/dtls/v3 v3.0.0-20260122183559-8b8d23e359c0 // indirect
|
||||||
@@ -42,15 +47,14 @@ require (
|
|||||||
github.com/gobwas/ws v1.4.0 // indirect
|
github.com/gobwas/ws v1.4.0 // indirect
|
||||||
github.com/google/go-tpm v0.9.8 // indirect
|
github.com/google/go-tpm v0.9.8 // indirect
|
||||||
github.com/google/uuid v1.6.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.28.0 // indirect
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.7 // indirect
|
|
||||||
github.com/ianlancetaylor/demangle v0.0.0-20240805132620-81f5be970eca // indirect
|
github.com/ianlancetaylor/demangle v0.0.0-20240805132620-81f5be970eca // indirect
|
||||||
github.com/icholy/digest v1.1.0 // indirect
|
github.com/icholy/digest v1.1.0 // indirect
|
||||||
github.com/klauspost/compress v1.18.3 // indirect
|
github.com/klauspost/compress v1.18.5 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/minio/highwayhash v1.0.4-0.20251030100505-070ab1a87a76 // indirect
|
github.com/minio/highwayhash v1.0.4-0.20251030100505-070ab1a87a76 // indirect
|
||||||
github.com/nats-io/jwt/v2 v2.8.0 // indirect
|
github.com/nats-io/jwt/v2 v2.8.1 // indirect
|
||||||
github.com/nats-io/nkeys v0.4.12 // indirect
|
github.com/nats-io/nkeys v0.4.15 // indirect
|
||||||
github.com/nats-io/nuid v1.0.1 // indirect
|
github.com/nats-io/nuid v1.0.1 // indirect
|
||||||
github.com/ncruces/go-strftime v1.0.0 // indirect
|
github.com/ncruces/go-strftime v1.0.0 // indirect
|
||||||
github.com/pion/logging v0.2.4 // indirect
|
github.com/pion/logging v0.2.4 // indirect
|
||||||
@@ -65,24 +69,24 @@ require (
|
|||||||
github.com/tetratelabs/wazero v1.9.0 // indirect
|
github.com/tetratelabs/wazero v1.9.0 // indirect
|
||||||
github.com/zaf/g711 v1.4.0 // indirect
|
github.com/zaf/g711 v1.4.0 // indirect
|
||||||
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.40.0 // indirect
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.43.0 // indirect
|
||||||
go.opentelemetry.io/otel/metric v1.40.0 // indirect
|
go.opentelemetry.io/otel/metric v1.43.0 // indirect
|
||||||
go.opentelemetry.io/proto/otlp v1.9.0 // indirect
|
go.opentelemetry.io/proto/otlp v1.10.0 // indirect
|
||||||
|
go.uber.org/atomic v1.11.0 // indirect
|
||||||
go.yaml.in/yaml/v2 v2.4.2 // indirect
|
go.yaml.in/yaml/v2 v2.4.2 // indirect
|
||||||
golang.org/x/crypto v0.47.0 // indirect
|
golang.org/x/crypto v0.49.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect
|
golang.org/x/net v0.52.0 // indirect
|
||||||
golang.org/x/net v0.49.0 // indirect
|
golang.org/x/sync v0.20.0 // indirect
|
||||||
golang.org/x/sync v0.19.0 // indirect
|
golang.org/x/sys v0.42.0 // indirect
|
||||||
golang.org/x/sys v0.40.0 // indirect
|
golang.org/x/text v0.35.0 // indirect
|
||||||
golang.org/x/text v0.33.0 // indirect
|
golang.org/x/time v0.15.0 // indirect
|
||||||
golang.org/x/time v0.14.0 // indirect
|
google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9 // indirect
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20260128011058-8636f8732409 // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9 // indirect
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409 // indirect
|
google.golang.org/grpc v1.80.0 // indirect
|
||||||
google.golang.org/grpc v1.78.0 // indirect
|
|
||||||
google.golang.org/protobuf v1.36.11 // indirect
|
google.golang.org/protobuf v1.36.11 // indirect
|
||||||
gopkg.in/hraban/opus.v2 v2.0.0-20230925203106-0188a62cb302 // indirect
|
gopkg.in/hraban/opus.v2 v2.0.0-20230925203106-0188a62cb302 // indirect
|
||||||
modernc.org/libc v1.67.1 // indirect
|
modernc.org/libc v1.72.0 // indirect
|
||||||
modernc.org/libquickjs v0.12.3 // indirect
|
modernc.org/libquickjs v0.12.4 // indirect
|
||||||
modernc.org/mathutil v1.7.1 // indirect
|
modernc.org/mathutil v1.7.1 // indirect
|
||||||
modernc.org/memory v1.11.0 // indirect
|
modernc.org/memory v1.11.0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
178
go.sum
178
go.sum
@@ -1,5 +1,9 @@
|
|||||||
github.com/antithesishq/antithesis-sdk-go v0.5.0-default-no-op h1:Ucf+QxEKMbPogRO5guBNe5cgd9uZgfoJLOYs8WWhtjM=
|
github.com/antithesishq/antithesis-sdk-go v0.6.0-default-no-op h1:kpBdlEPbRvff0mDD1gk7o9BhI16b9p5yYAXRlidpqJE=
|
||||||
github.com/antithesishq/antithesis-sdk-go v0.5.0-default-no-op/go.mod h1:IUpT2DPAKh6i/YhSbt6Gl3v2yvUZjmKncl7U91fup7E=
|
github.com/antithesishq/antithesis-sdk-go v0.6.0-default-no-op/go.mod h1:IUpT2DPAKh6i/YhSbt6Gl3v2yvUZjmKncl7U91fup7E=
|
||||||
|
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||||
|
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
||||||
|
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
||||||
|
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
|
||||||
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
||||||
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
|
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||||
@@ -8,18 +12,20 @@ github.com/creack/goselect v0.1.2 h1:2DNy14+JPjRBgPzAd1thbQp4BSIihxcBf0IXhQXDRa0
|
|||||||
github.com/creack/goselect v0.1.2/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY=
|
github.com/creack/goselect v0.1.2/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||||
github.com/dylibso/observe-sdk/go v0.0.0-20240819160327-2d926c5d788a h1:UwSIFv5g5lIvbGgtf3tVwC7Ky9rmMFBp0RMs+6f6YqE=
|
github.com/dylibso/observe-sdk/go v0.0.0-20240819160327-2d926c5d788a h1:UwSIFv5g5lIvbGgtf3tVwC7Ky9rmMFBp0RMs+6f6YqE=
|
||||||
github.com/dylibso/observe-sdk/go v0.0.0-20240819160327-2d926c5d788a/go.mod h1:C8DzXehI4zAbrdlbtOByKX6pfivJTBiV9Jjqv56Yd9Q=
|
github.com/dylibso/observe-sdk/go v0.0.0-20240819160327-2d926c5d788a/go.mod h1:C8DzXehI4zAbrdlbtOByKX6pfivJTBiV9Jjqv56Yd9Q=
|
||||||
github.com/eclipse/paho.mqtt.golang v1.5.1 h1:/VSOv3oDLlpqR2Epjn1Q7b2bSTplJIeV2ISgCl2W7nE=
|
github.com/eclipse/paho.mqtt.golang v1.5.1 h1:/VSOv3oDLlpqR2Epjn1Q7b2bSTplJIeV2ISgCl2W7nE=
|
||||||
github.com/eclipse/paho.mqtt.golang v1.5.1/go.mod h1:1/yJCneuyOoCOzKSsOTUc0AJfpsItBGWvYpBLimhArU=
|
github.com/eclipse/paho.mqtt.golang v1.5.1/go.mod h1:1/yJCneuyOoCOzKSsOTUc0AJfpsItBGWvYpBLimhArU=
|
||||||
github.com/emiago/diago v0.27.0 h1:5SQBbcLR9ooxhSMlTkU9QSuDv/2nhMO9lxuWJTd/7rE=
|
github.com/emiago/diago v0.28.0 h1:VCiimhFYLoBTsxH6WrufLSt6tKWG8Fv7LfCkZHqct2E=
|
||||||
github.com/emiago/diago v0.27.0/go.mod h1:8hUxCDPJY2p32hh+4ed7vHW/3yTMmEa3BjNctUPeGD0=
|
github.com/emiago/diago v0.28.0/go.mod h1:eQT6j9co9PMQ/25aUiM2jpvwxxWFXLWi2w5R3lZNmKg=
|
||||||
github.com/emiago/dtls/v3 v3.0.0-20260122183559-8b8d23e359c0 h1:o4LxpUnZ1zxiQ+Qjc9kLwXcjz31NGAHmnZ7xoJto3VM=
|
github.com/emiago/dtls/v3 v3.0.0-20260122183559-8b8d23e359c0 h1:o4LxpUnZ1zxiQ+Qjc9kLwXcjz31NGAHmnZ7xoJto3VM=
|
||||||
github.com/emiago/dtls/v3 v3.0.0-20260122183559-8b8d23e359c0/go.mod h1:ydcZ977eS1I6uOWodzMuw30BwvNAzT9su/xcNYSJqjA=
|
github.com/emiago/dtls/v3 v3.0.0-20260122183559-8b8d23e359c0/go.mod h1:ydcZ977eS1I6uOWodzMuw30BwvNAzT9su/xcNYSJqjA=
|
||||||
github.com/emiago/sipgo v1.2.0 h1:rmHFdCu9zu2Cabfd8+/eC9HQWyooqk8x+ti550z5lBw=
|
github.com/emiago/sipgo v1.3.0 h1:efxQln1wJqcIU9+N+4eTKNtTZ7YsRsg8yc+0XYqyuQU=
|
||||||
github.com/emiago/sipgo v1.2.0/go.mod h1:DuwAxBZhKMqIzQFPGZb1MVAGU6Wuxj64oTOhd5dx/FY=
|
github.com/emiago/sipgo v1.3.0/go.mod h1:DuwAxBZhKMqIzQFPGZb1MVAGU6Wuxj64oTOhd5dx/FY=
|
||||||
github.com/expr-lang/expr v1.17.8 h1:W1loDTT+0PQf5YteHSTpju2qfUfNoBt4yw9+wOEU9VM=
|
github.com/expr-lang/expr v1.17.8 h1:W1loDTT+0PQf5YteHSTpju2qfUfNoBt4yw9+wOEU9VM=
|
||||||
github.com/expr-lang/expr v1.17.8/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
|
github.com/expr-lang/expr v1.17.8/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 h1:lWJos6uY+tRFdlIHR+SJjwFDApY7OypS/2nMhiVQ9Sw=
|
||||||
@@ -45,12 +51,16 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
|||||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||||
github.com/google/go-tpm v0.9.8 h1:slArAR9Ft+1ybZu0lBwpSmpwhRXaa85hWtMinMyRAWo=
|
github.com/google/go-tpm v0.9.8 h1:slArAR9Ft+1ybZu0lBwpSmpwhRXaa85hWtMinMyRAWo=
|
||||||
github.com/google/go-tpm v0.9.8/go.mod h1:h9jEsEECg7gtLis0upRBQU+GhYVH6jMjrFxI8u6bVUY=
|
github.com/google/go-tpm v0.9.8/go.mod h1:h9jEsEECg7gtLis0upRBQU+GhYVH6jMjrFxI8u6bVUY=
|
||||||
|
github.com/google/jsonschema-go v0.4.2 h1:tmrUohrwoLZZS/P3x7ex0WAVknEkBZM46iALbcqoRA8=
|
||||||
|
github.com/google/jsonschema-go v0.4.2/go.mod h1:r5quNTdLOYEz95Ru18zA0ydNbBuYoo9tgaYcxEYhJVE=
|
||||||
|
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
|
||||||
|
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||||
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.7 h1:X+2YciYSxvMQK0UZ7sg45ZVabVZBeBuvMkmuI2V3Fak=
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 h1:HWRh5R2+9EifMyIHV7ZV+MIZqgz+PMpZ14Jynv3O2Zs=
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.7/go.mod h1:lW34nIZuQ8UDPdkon5fmfp2l3+ZkQ2me/+oecHYLOII=
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0/go.mod h1:JfhWUomR1baixubs02l85lZYYOm7LV6om4ceouMv45c=
|
||||||
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
|
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/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 h1:T54Ema1DU8ngI+aef9ZhAhNGQhcRTrWxVeG07F+c/Rw=
|
||||||
@@ -61,12 +71,14 @@ github.com/jwetzell/artnet-go v0.2.1 h1:iYTKWcwYrF5kBkYfkw2UbWvoueeA23iKEn7fR27m
|
|||||||
github.com/jwetzell/artnet-go v0.2.1/go.mod h1:gli97Z32a0kMkZ6taoTiK7/lqHcF/dhiGjGJdx/PxqA=
|
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 h1:xHt6dvyit98X+OC3jVzV0aLidxbyzi3vI9QiYkteEtA=
|
||||||
github.com/jwetzell/free-d-go v0.1.0/go.mod h1:KmrkooRARRaxJTBSPvwt/6IMAIaHH1R8bSA8cwbbELw=
|
github.com/jwetzell/free-d-go v0.1.0/go.mod h1:KmrkooRARRaxJTBSPvwt/6IMAIaHH1R8bSA8cwbbELw=
|
||||||
github.com/jwetzell/osc-go v0.1.0 h1:EXxup5VWBErHot2Ri4MFToPf6KCzLDTbCt2x6GLfw8I=
|
github.com/jwetzell/osc-go v0.3.0 h1:z75TxuQSEmdcmZ56OAepkDa3m88SdZh//3m4nBb/XZI=
|
||||||
github.com/jwetzell/osc-go v0.1.0/go.mod h1:xLz0jTwebSxtx1TkKN1YVdeRqvpFNweDhTut5TE393A=
|
github.com/jwetzell/osc-go v0.3.0/go.mod h1:kCs329JxY6Qjga08tRQ/Gl0PqhgQzLIMpOhm6uszvIc=
|
||||||
github.com/jwetzell/psn-go v0.3.0 h1:WVpCEmExYE8a+I5hQak5jNJJp2x35VdGX/VuMUKPmhY=
|
github.com/jwetzell/psn-go v0.3.0 h1:WVpCEmExYE8a+I5hQak5jNJJp2x35VdGX/VuMUKPmhY=
|
||||||
github.com/jwetzell/psn-go v0.3.0/go.mod h1:bcEAeti4sQM375buujb3mIfmUstD4Aby18gq3ENb6+o=
|
github.com/jwetzell/psn-go v0.3.0/go.mod h1:bcEAeti4sQM375buujb3mIfmUstD4Aby18gq3ENb6+o=
|
||||||
github.com/klauspost/compress v1.18.3 h1:9PJRvfbmTabkOX8moIpXPbMMbYN60bWImDDU7L+/6zw=
|
github.com/klauspost/compress v1.18.5 h1:/h1gH5Ce+VWNLSWqPzOVn6XBO+vJbCNGvjoaGBFW2IE=
|
||||||
github.com/klauspost/compress v1.18.3/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
|
github.com/klauspost/compress v1.18.5/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
|
||||||
|
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
|
||||||
|
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
@@ -75,14 +87,14 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
|
|||||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
github.com/minio/highwayhash v1.0.4-0.20251030100505-070ab1a87a76 h1:KGuD/pM2JpL9FAYvBrnBBeENKZNh6eNtjqytV6TYjnk=
|
github.com/minio/highwayhash v1.0.4-0.20251030100505-070ab1a87a76 h1:KGuD/pM2JpL9FAYvBrnBBeENKZNh6eNtjqytV6TYjnk=
|
||||||
github.com/minio/highwayhash v1.0.4-0.20251030100505-070ab1a87a76/go.mod h1:GGYsuwP/fPD6Y9hMiXuapVvlIUEhFhMTh0rxU3ik1LQ=
|
github.com/minio/highwayhash v1.0.4-0.20251030100505-070ab1a87a76/go.mod h1:GGYsuwP/fPD6Y9hMiXuapVvlIUEhFhMTh0rxU3ik1LQ=
|
||||||
github.com/nats-io/jwt/v2 v2.8.0 h1:K7uzyz50+yGZDO5o772eRE7atlcSEENpL7P+b74JV1g=
|
github.com/nats-io/jwt/v2 v2.8.1 h1:V0xpGuD/N8Mi+fQNDynXohVvp7ZztevW5io8CUWlPmU=
|
||||||
github.com/nats-io/jwt/v2 v2.8.0/go.mod h1:me11pOkwObtcBNR8AiMrUbtVOUGkqYjMQZ6jnSdVUIA=
|
github.com/nats-io/jwt/v2 v2.8.1/go.mod h1:nWnOEEiVMiKHQpnAy4eXlizVEtSfzacZ1Q43LIRavZg=
|
||||||
github.com/nats-io/nats-server/v2 v2.12.4 h1:ZnT10v2LU2Xcoiy8ek9X6Se4YG8EuMfIfvAEuFVx1Ts=
|
github.com/nats-io/nats-server/v2 v2.12.7 h1:prQ9cPiWHcnwfT81Wi5lU9LL8TLY+7pxDru6fQYLCQQ=
|
||||||
github.com/nats-io/nats-server/v2 v2.12.4/go.mod h1:5MCp/pqm5SEfsvVZ31ll1088ZTwEUdvRX1Hmh/mTTDg=
|
github.com/nats-io/nats-server/v2 v2.12.7/go.mod h1:dOnmkprKMluTmTF7/QHZioxlau3sKHUM/LBPy9AiBPw=
|
||||||
github.com/nats-io/nats.go v1.49.0 h1:yh/WvY59gXqYpgl33ZI+XoVPKyut/IcEaqtsiuTJpoE=
|
github.com/nats-io/nats.go v1.51.0 h1:ByW84XTz6W03GSSsygsZcA+xgKK8vPGaa/FCAAEHnAI=
|
||||||
github.com/nats-io/nats.go v1.49.0/go.mod h1:fDCn3mN5cY8HooHwE2ukiLb4p4G4ImmzvXyJt+tGwdw=
|
github.com/nats-io/nats.go v1.51.0/go.mod h1:26HypzazeOkyO3/mqd1zZd53STJN0EjCYF9Uy2ZOBno=
|
||||||
github.com/nats-io/nkeys v0.4.12 h1:nssm7JKOG9/x4J8II47VWCL1Ds29avyiQDRn0ckMvDc=
|
github.com/nats-io/nkeys v0.4.15 h1:JACV5jRVO9V856KOapQ7x+EY8Jo3qw1vJt/9Jpwzkk4=
|
||||||
github.com/nats-io/nkeys v0.4.12/go.mod h1:MT59A1HYcjIcyQDJStTfaOY6vhy9XTUjOFo+SVsvpBg=
|
github.com/nats-io/nkeys v0.4.15/go.mod h1:CpMchTXC9fxA5zrMo4KpySxNjiDVvr8ANOSZdiNfUrs=
|
||||||
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
|
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/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
||||||
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
|
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
|
||||||
@@ -103,6 +115,8 @@ github.com/pion/transport/v4 v4.0.1 h1:sdROELU6BZ63Ab7FrOLn13M6YdJLY20wldXW2Cu2k
|
|||||||
github.com/pion/transport/v4 v4.0.1/go.mod h1:nEuEA4AD5lPdcIegQDpVLgNoDGreqM/YqmEx3ovP4jM=
|
github.com/pion/transport/v4 v4.0.1/go.mod h1:nEuEA4AD5lPdcIegQDpVLgNoDGreqM/YqmEx3ovP4jM=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/redis/go-redis/v9 v9.18.0 h1:pMkxYPkEbMPwRdenAzUNyFNrDgHx9U+DrBabWNfSRQs=
|
||||||
|
github.com/redis/go-redis/v9 v9.18.0/go.mod h1:k3ufPphLU5YXwNTUcCRXGxUoF1fqxnhFQmscfkCoDA0=
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||||
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
|
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
|
||||||
@@ -113,66 +127,68 @@ github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834 h1:ZF+QBjOI+tILZ
|
|||||||
github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834/go.mod h1:m9ymHTgNSEjuxvw8E7WWe4Pl4hZQHXONY8wE6dMLaRk=
|
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 h1:IcZ56OuxrtaEz8UYNRHBrUa9bYeX9oVY93KspZZBf/I=
|
||||||
github.com/tetratelabs/wazero v1.9.0/go.mod h1:TSbcXCfFP0L2FGkRPxHphadXPjo1T6W+CseNNY7EkjM=
|
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.8.0 h1:XqKPrm0q4P0q5JpoclYoCAv0/MIvH/jZ2umzuf8pNTI=
|
||||||
github.com/urfave/cli/v3 v3.6.2/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
|
github.com/urfave/cli/v3 v3.8.0/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
|
||||||
github.com/zaf/g711 v1.4.0 h1:XZYkjjiAg9QTBnHqEg37m2I9q3IIDv5JRYXs2N8ma7c=
|
github.com/zaf/g711 v1.4.0 h1:XZYkjjiAg9QTBnHqEg37m2I9q3IIDv5JRYXs2N8ma7c=
|
||||||
github.com/zaf/g711 v1.4.0/go.mod h1:eCDXt3dSp/kYYAoooba7ukD/Q75jvAaS4WOMr0l1Roo=
|
github.com/zaf/g711 v1.4.0/go.mod h1:eCDXt3dSp/kYYAoooba7ukD/Q75jvAaS4WOMr0l1Roo=
|
||||||
gitlab.com/gomidi/midi/v2 v2.3.22 h1:4Q20o6q4BDo7i/KGvnwASeytOlrPI7MwsS7F2hA7fOM=
|
github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
|
||||||
gitlab.com/gomidi/midi/v2 v2.3.22/go.mod h1:jDpP4O4skYi+7iVwt6Zyp18bd2M4hkjtMuw2cmgKgfw=
|
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
|
||||||
|
gitlab.com/gomidi/midi/v2 v2.3.23 h1:P8NxV4EzV9c+BjpwTeB+G/qa+Xdq/UTazS2fKxY0O0g=
|
||||||
|
gitlab.com/gomidi/midi/v2 v2.3.23/go.mod h1:jDpP4O4skYi+7iVwt6Zyp18bd2M4hkjtMuw2cmgKgfw=
|
||||||
go.bug.st/serial v1.6.4 h1:7FmqNPgVp3pu2Jz5PoPtbZ9jJO5gnEnZIvnI1lzve8A=
|
go.bug.st/serial v1.6.4 h1:7FmqNPgVp3pu2Jz5PoPtbZ9jJO5gnEnZIvnI1lzve8A=
|
||||||
go.bug.st/serial v1.6.4/go.mod h1:nofMJxTeNVny/m6+KaafC6vJGj3miwQZ6vW4BZUGJPI=
|
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 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||||
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
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.43.0 h1:mYIM03dnh5zfN7HautFE4ieIig9amkNANT+xcVxAj9I=
|
||||||
go.opentelemetry.io/otel v1.40.0/go.mod h1:IMb+uXZUKkMXdPddhwAHm6UfOwJyh4ct1ybIlV14J0g=
|
go.opentelemetry.io/otel v1.43.0/go.mod h1:JuG+u74mvjvcm8vj8pI5XiHy1zDeoCS2LB1spIq7Ay0=
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.40.0 h1:QKdN8ly8zEMrByybbQgv8cWBcdAarwmIPZ6FThrWXJs=
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.43.0 h1:88Y4s2C8oTui1LGM6bTWkw0ICGcOLCAI5l6zsD1j20k=
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.40.0/go.mod h1:bTdK1nhqF76qiPoCCdyFIV+N/sRHYXYCTQc+3VCi3MI=
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.43.0/go.mod h1:Vl1/iaggsuRlrHf/hfPJPvVag77kKyvrLeD10kpMl+A=
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.40.0 h1:wVZXIWjQSeSmMoxF74LzAnpVQOAFDo3pPji9Y4SOFKc=
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.43.0 h1:3iZJKlCZufyRzPzlQhUIWVmfltrXuGyfjREgGP3UUjc=
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.40.0/go.mod h1:khvBS2IggMFNwZK/6lEeHg/W57h/IX6J4URh57fuI40=
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.43.0/go.mod h1:/G+nUPfhq2e+qiXMGxMwumDrP5jtzU+mWN7/sjT2rak=
|
||||||
go.opentelemetry.io/otel/metric v1.40.0 h1:rcZe317KPftE2rstWIBitCdVp89A2HqjkxR3c11+p9g=
|
go.opentelemetry.io/otel/metric v1.43.0 h1:d7638QeInOnuwOONPp4JAOGfbCEpYb+K6DVWvdxGzgM=
|
||||||
go.opentelemetry.io/otel/metric v1.40.0/go.mod h1:ib/crwQH7N3r5kfiBZQbwrTge743UDc7DTFVZrrXnqc=
|
go.opentelemetry.io/otel/metric v1.43.0/go.mod h1:RDnPtIxvqlgO8GRW18W6Z/4P462ldprJtfxHxyKd2PY=
|
||||||
go.opentelemetry.io/otel/sdk v1.40.0 h1:KHW/jUzgo6wsPh9At46+h4upjtccTmuZCFAc9OJ71f8=
|
go.opentelemetry.io/otel/sdk v1.43.0 h1:pi5mE86i5rTeLXqoF/hhiBtUNcrAGHLKQdhg4h4V9Dg=
|
||||||
go.opentelemetry.io/otel/sdk v1.40.0/go.mod h1:Ph7EFdYvxq72Y8Li9q8KebuYUr2KoeyHx0DRMKrYBUE=
|
go.opentelemetry.io/otel/sdk v1.43.0/go.mod h1:P+IkVU3iWukmiit/Yf9AWvpyRDlUeBaRg6Y+C58QHzg=
|
||||||
go.opentelemetry.io/otel/sdk/metric v1.40.0 h1:mtmdVqgQkeRxHgRv4qhyJduP3fYJRMX4AtAlbuWdCYw=
|
go.opentelemetry.io/otel/sdk/metric v1.43.0 h1:S88dyqXjJkuBNLeMcVPRFXpRw2fuwdvfCGLEo89fDkw=
|
||||||
go.opentelemetry.io/otel/sdk/metric v1.40.0/go.mod h1:4Z2bGMf0KSK3uRjlczMOeMhKU2rhUqdWNoKcYrtcBPg=
|
go.opentelemetry.io/otel/sdk/metric v1.43.0/go.mod h1:C/RJtwSEJ5hzTiUz5pXF1kILHStzb9zFlIEe85bhj6A=
|
||||||
go.opentelemetry.io/otel/trace v1.40.0 h1:WA4etStDttCSYuhwvEa8OP8I5EWu24lkOzp+ZYblVjw=
|
go.opentelemetry.io/otel/trace v1.43.0 h1:BkNrHpup+4k4w+ZZ86CZoHHEkohws8AY+WTX09nk+3A=
|
||||||
go.opentelemetry.io/otel/trace v1.40.0/go.mod h1:zeAhriXecNGP/s2SEG3+Y8X9ujcJOTqQ5RgdEJcawiA=
|
go.opentelemetry.io/otel/trace v1.43.0/go.mod h1:/QJhyVBUUswCphDVxq+8mld+AvhXZLhe+8WVFxiFff0=
|
||||||
go.opentelemetry.io/proto/otlp v1.9.0 h1:l706jCMITVouPOqEnii2fIAuO3IVGBRPV5ICjceRb/A=
|
go.opentelemetry.io/proto/otlp v1.10.0 h1:IQRWgT5srOCYfiWnpqUYz9CVmbO8bFmKcwYxpuCSL2g=
|
||||||
go.opentelemetry.io/proto/otlp v1.9.0/go.mod h1:xE+Cx5E/eEHw+ISFkwPLwCZefwVjY+pqKg1qcK03+/4=
|
go.opentelemetry.io/proto/otlp v1.10.0/go.mod h1:/CV4QoCR/S9yaPj8utp3lvQPoqMtxXdzn7ozvvozVqk=
|
||||||
|
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
|
||||||
|
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
|
||||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||||
go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
|
go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
|
||||||
go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
|
go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
|
||||||
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
|
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
|
||||||
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||||
golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8=
|
golang.org/x/crypto v0.49.0 h1:+Ng2ULVvLHnJ/ZFEq4KdcDd/cfjrrjjNSXNzxg0Y4U4=
|
||||||
golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A=
|
golang.org/x/crypto v0.49.0/go.mod h1:ErX4dUh2UM+CFYiXZRTcMpEcN8b/1gxEuv3nODoYtCA=
|
||||||
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 h1:mgKeJMpvi0yx/sU5GsxQ7p6s2wtOnGAHZWCHUM4KGzY=
|
golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8=
|
||||||
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70=
|
golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w=
|
||||||
golang.org/x/mod v0.31.0 h1:HaW9xtz0+kOcWKwli0ZXy79Ix+UW/vOfmWI5QVd2tgI=
|
golang.org/x/net v0.52.0 h1:He/TN1l0e4mmR3QqHMT2Xab3Aj3L9qjbhRm78/6jrW0=
|
||||||
golang.org/x/mod v0.31.0/go.mod h1:43JraMp9cGx1Rx3AqioxrbrhNsLl2l/iNAvuBkrezpg=
|
golang.org/x/net v0.52.0/go.mod h1:R1MAz7uMZxVMualyPXb+VaqGSa3LIaUqk0eEt3w36Sw=
|
||||||
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
|
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
|
||||||
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
|
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||||
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.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
|
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
|
||||||
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||||
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
|
golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8=
|
||||||
golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
|
golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA=
|
||||||
golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI=
|
golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U=
|
||||||
golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4=
|
golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno=
|
||||||
golang.org/x/tools v0.40.0 h1:yLkxfA+Qnul4cs9QA3KnlFu0lVmd8JJfoq+E41uSutA=
|
golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k=
|
||||||
golang.org/x/tools v0.40.0/go.mod h1:Ik/tzLRlbscWpqqMRjyWYDisX8bG13FrdXp3o4Sr9lc=
|
golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0=
|
||||||
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
|
gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
|
||||||
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
|
gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E=
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20260128011058-8636f8732409 h1:merA0rdPeUV3YIIfHHcH4qBkiQAc1nfCKSI7lB4cV2M=
|
google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9 h1:VPWxll4HlMw1Vs/qXtN7BvhZqsS9cdAittCNvVENElA=
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20260128011058-8636f8732409/go.mod h1:fl8J1IvUjCilwZzQowmw2b7HQB2eAuYBabMXzWurF+I=
|
google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9/go.mod h1:7QBABkRtR8z+TEnmXTqIqwJLlzrZKVfAUm7tY3yGv0M=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409 h1:H86B94AW+VfJWDqFeEbBPhEtHzJwJfTbgE2lZa54ZAQ=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9 h1:m8qni9SQFH0tJc1X0vmnpw/0t+AImlSvp30sEupozUg=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409/go.mod h1:j9x/tPzZkyxcgEFkiKEEGxfvyumM01BEtsW8xzOahRQ=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
|
||||||
google.golang.org/grpc v1.78.0 h1:K1XZG/yGDJnzMdd/uZHAkVqJE+xIDOcmdSFZkBUicNc=
|
google.golang.org/grpc v1.80.0 h1:Xr6m2WmWZLETvUNvIUmeD5OAagMw3FiKmMlTdViWsHM=
|
||||||
google.golang.org/grpc v1.78.0/go.mod h1:I47qjTo4OKbMkjA/aOOwxDIiPSBofUtQUI5EfpWvW7U=
|
google.golang.org/grpc v1.80.0/go.mod h1:ho/dLnxwi3EDJA4Zghp7k2Ec1+c2jqup0bFkw07bwF4=
|
||||||
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
|
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
|
||||||
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
@@ -184,32 +200,34 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
|
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
|
||||||
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
|
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
|
||||||
modernc.org/cc/v4 v4.27.1 h1:9W30zRlYrefrDV2JE2O8VDtJ1yPGownxciz5rrbQZis=
|
modernc.org/cc/v4 v4.27.3 h1:uNCgn37E5U09mTv1XgskEVUJ8ADKpmFMPxzGJ0TSo+U=
|
||||||
modernc.org/cc/v4 v4.27.1/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0=
|
modernc.org/cc/v4 v4.27.3/go.mod h1:3YjcbCqhoTTHPycJDRl2WZKKFj0nwcOIPBfEZK0Hdk8=
|
||||||
modernc.org/ccgo/v4 v4.30.1 h1:4r4U1J6Fhj98NKfSjnPUN7Ze2c6MnAdL0hWw6+LrJpc=
|
modernc.org/ccgo/v4 v4.32.4 h1:L5OB8rpEX4ZsXEQwGozRfJyJSFHbbNVOoQ59DU9/KuU=
|
||||||
modernc.org/ccgo/v4 v4.30.1/go.mod h1:bIOeI1JL54Utlxn+LwrFyjCx2n2RDiYEaJVSrgdrRfM=
|
modernc.org/ccgo/v4 v4.32.4/go.mod h1:lY7f+fiTDHfcv6YlRgSkxYfhs+UvOEEzj49jAn2TOx0=
|
||||||
modernc.org/fileutil v1.3.40 h1:ZGMswMNc9JOCrcrakF1HrvmergNLAmxOPjizirpfqBA=
|
modernc.org/fileutil v1.4.0 h1:j6ZzNTftVS054gi281TyLjHPp6CPHr2KCxEXjEbD6SM=
|
||||||
modernc.org/fileutil v1.3.40/go.mod h1:HxmghZSZVAz/LXcMNwZPA/DRrQZEVP9VX0V4LQGQFOc=
|
modernc.org/fileutil v1.4.0/go.mod h1:EqdKFDxiByqxLk8ozOxObDSfcVOv/54xDs/DUHdvCUU=
|
||||||
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
|
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
|
||||||
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
|
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
|
||||||
modernc.org/gc/v3 v3.1.1 h1:k8T3gkXWY9sEiytKhcgyiZ2L0DTyCQ/nvX+LoCljoRE=
|
modernc.org/gc/v3 v3.1.2 h1:ZtDCnhonXSZexk/AYsegNRV1lJGgaNZJuKjJSWKyEqo=
|
||||||
modernc.org/gc/v3 v3.1.1/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY=
|
modernc.org/gc/v3 v3.1.2/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY=
|
||||||
modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks=
|
modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks=
|
||||||
modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
|
modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
|
||||||
modernc.org/libc v1.67.1 h1:bFaqOaa5/zbWYJo8aW0tXPX21hXsngG2M7mckCnFSVk=
|
modernc.org/libc v1.72.0 h1:IEu559v9a0XWjw0DPoVKtXpO2qt5NVLAnFaBbjq+n8c=
|
||||||
modernc.org/libc v1.67.1/go.mod h1:QvvnnJ5P7aitu0ReNpVIEyesuhmDLQ8kaEoyMjIFZJA=
|
modernc.org/libc v1.72.0/go.mod h1:tTU8DL8A+XLVkEY3x5E/tO7s2Q/q42EtnNWda/L5QhQ=
|
||||||
modernc.org/libquickjs v0.12.3 h1:2IU9B6njBmce2PuYttJDkXeoLRV9WnvgP+eU5HAC8YI=
|
modernc.org/libquickjs v0.12.4 h1:WQ2XP6pAscvtHKPEVuHTf8NiAl5nMomKgIL6790r7AQ=
|
||||||
modernc.org/libquickjs v0.12.3/go.mod h1:iCsgVxnHTX3i0YPxxHBmJk0GLA5sVUHXWI/090UXgeE=
|
modernc.org/libquickjs v0.12.4/go.mod h1:MqdjijqGUwLw+r86+YbFLLj7vKZhVHEKRs8XOsnM/n8=
|
||||||
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
|
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
|
||||||
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
|
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 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
|
||||||
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
|
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 h1:2kNGMRiUjrp4LcaPuLY2PzUfqM/w9N23quVwhKt5Qm8=
|
||||||
modernc.org/opt v0.1.4/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
|
modernc.org/opt v0.1.4/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
|
||||||
modernc.org/quickjs v0.17.1 h1:CbYnbTf7ksZk9YZ1rRM2Ab1Zfi+X6s50kXiOhpd2NIg=
|
modernc.org/quickjs v0.18.0 h1:J7WrUSduFjxqtNwqsEzN2saEKfu4QRftfV3vHD/zkEo=
|
||||||
modernc.org/quickjs v0.17.1/go.mod h1:hATT7DIJc33I5Q/Fjffhm0tpUHNSqdKHma/ossibTA0=
|
modernc.org/quickjs v0.18.0/go.mod h1:l+qt8/Ofo+RLpfp4NYdKp0noJsh1den4lFXXZ3fQT+U=
|
||||||
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
|
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
|
||||||
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
|
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
|
||||||
|
modernc.org/sqlite v1.49.1 h1:dYGHTKcX1sJ+EQDnUzvz4TJ5GbuvhNJa8Fg6ElGx73U=
|
||||||
|
modernc.org/sqlite v1.49.1/go.mod h1:m0w8xhwYUVY3H6pSDwc3gkJ/irZT/0YEXwBlhaxQEew=
|
||||||
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
|
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
|
||||||
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
|
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
|
||||||
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
||||||
|
|||||||
175
internal/common/common.go
Normal file
175
internal/common/common.go
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math"
|
||||||
|
"reflect"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetAnyAs[T any](value any) (T, bool) {
|
||||||
|
typed, ok := value.(T)
|
||||||
|
return typed, ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAnyAsInt(value any) (int, bool) {
|
||||||
|
|
||||||
|
intValue, ok := value.(int)
|
||||||
|
if ok {
|
||||||
|
return intValue, true
|
||||||
|
}
|
||||||
|
|
||||||
|
uintValue, ok := value.(uint)
|
||||||
|
if ok {
|
||||||
|
return int(uintValue), true
|
||||||
|
}
|
||||||
|
|
||||||
|
byteValue, ok := value.(byte)
|
||||||
|
if ok {
|
||||||
|
return int(byteValue), true
|
||||||
|
}
|
||||||
|
|
||||||
|
float32Value, ok := value.(float32)
|
||||||
|
if ok {
|
||||||
|
if float64(float32Value) != math.Floor(float64(float32Value)) {
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
return int(float32Value), true
|
||||||
|
}
|
||||||
|
|
||||||
|
float64Value, ok := value.(float64)
|
||||||
|
if ok {
|
||||||
|
if float64Value != math.Floor(float64Value) {
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
return int(float64Value), true
|
||||||
|
}
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAnyAsByte(value any) (byte, bool) {
|
||||||
|
|
||||||
|
byteValue, ok := value.(byte)
|
||||||
|
if ok {
|
||||||
|
return byte(byteValue), true
|
||||||
|
}
|
||||||
|
|
||||||
|
intValue, ok := value.(int)
|
||||||
|
if ok {
|
||||||
|
return byte(intValue), true
|
||||||
|
}
|
||||||
|
|
||||||
|
uintValue, ok := value.(uint)
|
||||||
|
if ok {
|
||||||
|
return byte(uintValue), true
|
||||||
|
}
|
||||||
|
|
||||||
|
float32Value, ok := value.(float32)
|
||||||
|
if ok {
|
||||||
|
if float64(float32Value) != math.Floor(float64(float32Value)) {
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
return byte(float32Value), true
|
||||||
|
}
|
||||||
|
|
||||||
|
float64Value, ok := value.(float64)
|
||||||
|
if ok {
|
||||||
|
if float64Value != math.Floor(float64Value) {
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
return byte(float64Value), true
|
||||||
|
}
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAnyAsByteSlice(value any) ([]byte, bool) {
|
||||||
|
v := reflect.ValueOf(value)
|
||||||
|
if v.Kind() != reflect.Slice {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
result := make([]byte, v.Len())
|
||||||
|
for i := 0; i < v.Len(); i++ {
|
||||||
|
elem := v.Index(i).Interface()
|
||||||
|
elemValue, ok := GetAnyAsByte(elem)
|
||||||
|
if !ok {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
result[i] = elemValue
|
||||||
|
}
|
||||||
|
return result, true
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAnyAsIntSlice(value any) ([]int, bool) {
|
||||||
|
v := reflect.ValueOf(value)
|
||||||
|
if v.Kind() != reflect.Slice {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
result := make([]int, v.Len())
|
||||||
|
for i := 0; i < v.Len(); i++ {
|
||||||
|
elem := v.Index(i).Interface()
|
||||||
|
elemInt, ok := GetAnyAsInt(elem)
|
||||||
|
if !ok {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
result[i] = elemInt
|
||||||
|
}
|
||||||
|
return result, true
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAnyAsFloat32(value any) (float32, bool) {
|
||||||
|
float32Value, ok := value.(float32)
|
||||||
|
if ok {
|
||||||
|
return float32Value, true
|
||||||
|
}
|
||||||
|
|
||||||
|
float64Value, ok := value.(float64)
|
||||||
|
if ok {
|
||||||
|
return float32(float64Value), true
|
||||||
|
}
|
||||||
|
|
||||||
|
intValue, ok := value.(int)
|
||||||
|
if ok {
|
||||||
|
return float32(intValue), true
|
||||||
|
}
|
||||||
|
|
||||||
|
uintValue, ok := value.(uint)
|
||||||
|
if ok {
|
||||||
|
return float32(uintValue), true
|
||||||
|
}
|
||||||
|
|
||||||
|
byteValue, ok := value.(byte)
|
||||||
|
if ok {
|
||||||
|
return float32(byteValue), true
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAnyAsFloat64(value any) (float64, bool) {
|
||||||
|
float64Value, ok := value.(float64)
|
||||||
|
if ok {
|
||||||
|
return float64Value, true
|
||||||
|
}
|
||||||
|
|
||||||
|
float32Value, ok := value.(float32)
|
||||||
|
if ok {
|
||||||
|
return float64(float32Value), true
|
||||||
|
}
|
||||||
|
|
||||||
|
intValue, ok := value.(int)
|
||||||
|
if ok {
|
||||||
|
return float64(intValue), true
|
||||||
|
}
|
||||||
|
|
||||||
|
uintValue, ok := value.(uint)
|
||||||
|
if ok {
|
||||||
|
return float64(uintValue), true
|
||||||
|
}
|
||||||
|
|
||||||
|
byteValue, ok := value.(byte)
|
||||||
|
if ok {
|
||||||
|
return float64(byteValue), true
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
424
internal/common/common_test.go
Normal file
424
internal/common/common_test.go
Normal file
@@ -0,0 +1,424 @@
|
|||||||
|
package common_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"slices"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGoodGetAnyAsInt(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
value any
|
||||||
|
typedValue int
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "int",
|
||||||
|
value: int(42),
|
||||||
|
typedValue: 42,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "uint",
|
||||||
|
value: uint(42),
|
||||||
|
typedValue: 42,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "float32 without decimal",
|
||||||
|
value: float32(42.0),
|
||||||
|
typedValue: 42,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "float64 without decimal",
|
||||||
|
value: float64(42.0),
|
||||||
|
typedValue: 42,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
value, ok := common.GetAnyAsInt(testCase.value)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("GetAnyAsInt expected to succeed but failed")
|
||||||
|
}
|
||||||
|
if value != testCase.typedValue {
|
||||||
|
t.Fatalf("GetAnyAsInt expected got %d, expected %d", value, testCase.typedValue)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadGetAnyAsInt(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
value any
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "string",
|
||||||
|
value: "value",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "float32 with decimal",
|
||||||
|
value: float32(1.5),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "float64 with decimal",
|
||||||
|
value: float64(1.5),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
value, ok := common.GetAnyAsInt(testCase.value)
|
||||||
|
if ok {
|
||||||
|
t.Fatalf("GetAnyAsInt expected to fail but succeeded, got: %v", value)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGoodGetAnyAsByte(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
value any
|
||||||
|
typedValue byte
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "int",
|
||||||
|
value: int(42),
|
||||||
|
typedValue: 42,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "uint",
|
||||||
|
value: uint(42),
|
||||||
|
typedValue: 42,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "float32 without decimal",
|
||||||
|
value: float32(42.0),
|
||||||
|
typedValue: 42,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "float64 without decimal",
|
||||||
|
value: float64(42.0),
|
||||||
|
typedValue: 42,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
value, ok := common.GetAnyAsByte(testCase.value)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("GetAnyAsByte expected to succeed but failed")
|
||||||
|
}
|
||||||
|
if value != testCase.typedValue {
|
||||||
|
t.Fatalf("GetAnyAsByte expected got %d, expected %d", value, testCase.typedValue)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadGetAnyAsByte(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
value any
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "string",
|
||||||
|
value: "value",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "float32 with decimal",
|
||||||
|
value: float32(1.5),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "float64 with decimal",
|
||||||
|
value: float64(1.5),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
value, ok := common.GetAnyAsByte(testCase.value)
|
||||||
|
if ok {
|
||||||
|
t.Fatalf("GetAnyAsByte expected to fail but succeeded, got: %v", value)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGoodGetAnyAsByteSlice(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
value any
|
||||||
|
typedValue []byte
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "byte slice",
|
||||||
|
value: []byte{1, 2, 3},
|
||||||
|
typedValue: []byte{1, 2, 3},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "int slice",
|
||||||
|
value: []int{1, 2, 3},
|
||||||
|
typedValue: []byte{1, 2, 3},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "uint slice",
|
||||||
|
value: []uint{1, 2, 3},
|
||||||
|
typedValue: []byte{1, 2, 3},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "float32 without decimal slice",
|
||||||
|
value: []float32{1, 2, 3},
|
||||||
|
typedValue: []byte{1, 2, 3},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "float64 without decimal slice",
|
||||||
|
value: []float64{1, 2, 3},
|
||||||
|
typedValue: []byte{1, 2, 3},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
value, ok := common.GetAnyAsByteSlice(testCase.value)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("GetAnyAsByteSlice expected to succeed but failed")
|
||||||
|
}
|
||||||
|
if !slices.Equal(value, testCase.typedValue) {
|
||||||
|
t.Fatalf("GetAnyAsByteSlice expected got %d, expected %d", value, testCase.typedValue)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadGetAnyAsByteSlice(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
value any
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "not a slice",
|
||||||
|
value: "value",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "not a int slice",
|
||||||
|
value: []any{"value1", 2},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
value, ok := common.GetAnyAsByteSlice(testCase.value)
|
||||||
|
if ok {
|
||||||
|
t.Fatalf("GetAnyAsByteSlice expected to fail but succeeded, got: %v", value)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGoodGetAnyAsIntSlice(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
value any
|
||||||
|
typedValue []int
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "int slice",
|
||||||
|
value: []int{1, 2, 3},
|
||||||
|
typedValue: []int{1, 2, 3},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "byte slice",
|
||||||
|
value: []byte{1, 2, 3},
|
||||||
|
typedValue: []int{1, 2, 3},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "uint slice",
|
||||||
|
value: []uint{1, 2, 3},
|
||||||
|
typedValue: []int{1, 2, 3},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "float32 without decimal slice",
|
||||||
|
value: []float32{1, 2, 3},
|
||||||
|
typedValue: []int{1, 2, 3},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "float64 without decimal slice",
|
||||||
|
value: []float64{1, 2, 3},
|
||||||
|
typedValue: []int{1, 2, 3},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
value, ok := common.GetAnyAsIntSlice(testCase.value)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("GetAnyAsIntSlice expected to succeed but failed")
|
||||||
|
}
|
||||||
|
if !slices.Equal(value, testCase.typedValue) {
|
||||||
|
t.Fatalf("GetAnyAsIntSlice expected got %d, expected %d", value, testCase.typedValue)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadGetAnyAsIntSlice(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
value any
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "not a slice",
|
||||||
|
value: "value",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "not a int slice",
|
||||||
|
value: []any{"value1", 2},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
value, ok := common.GetAnyAsIntSlice(testCase.value)
|
||||||
|
if ok {
|
||||||
|
t.Fatalf("GetAnyAsIntSlice expected to fail but succeeded, got: %v", value)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGoodGetAnyAsFloat32(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
value any
|
||||||
|
typedValue float32
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "int",
|
||||||
|
value: int(42),
|
||||||
|
typedValue: 42,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "uint",
|
||||||
|
value: uint(42),
|
||||||
|
typedValue: 42,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "byte",
|
||||||
|
value: byte(42),
|
||||||
|
typedValue: 42,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "float32",
|
||||||
|
value: float32(42.3),
|
||||||
|
typedValue: 42.3,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "float64",
|
||||||
|
value: float64(42.3),
|
||||||
|
typedValue: 42.3,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
value, ok := common.GetAnyAsFloat32(testCase.value)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("GetAnyAsFloat32 expected to succeed but failed")
|
||||||
|
}
|
||||||
|
if value != testCase.typedValue {
|
||||||
|
t.Fatalf("GetAnyAsFloat32 expected got %f, expected %f", value, testCase.typedValue)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadGetAnyAsFloat32(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
value any
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "string",
|
||||||
|
value: "value",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
value, ok := common.GetAnyAsFloat32(testCase.value)
|
||||||
|
if ok {
|
||||||
|
t.Fatalf("GetAnyAsFloat32 expected to fail but succeeded, got: %v", value)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGoodGetAnyAsFloat64(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
value any
|
||||||
|
typedValue float64
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "int",
|
||||||
|
value: int(42),
|
||||||
|
typedValue: 42,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "uint",
|
||||||
|
value: uint(42),
|
||||||
|
typedValue: 42,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "byte",
|
||||||
|
value: byte(42),
|
||||||
|
typedValue: 42,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "float32",
|
||||||
|
value: float32(42.5),
|
||||||
|
typedValue: 42.5,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "float64",
|
||||||
|
value: float64(42.5),
|
||||||
|
typedValue: 42.5,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
value, ok := common.GetAnyAsFloat64(testCase.value)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("GetAnyAsFloat64 expected to succeed but failed")
|
||||||
|
}
|
||||||
|
if value != testCase.typedValue {
|
||||||
|
t.Fatalf("GetAnyAsFloat64 expected got %f, expected %f", value, testCase.typedValue)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadGetAnyAsFloat64(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
value any
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "string",
|
||||||
|
value: "value",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
value, ok := common.GetAnyAsFloat64(testCase.value)
|
||||||
|
if ok {
|
||||||
|
t.Fatalf("GetAnyAsFloat64 expected to fail but succeeded, got: %v", value)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
8
internal/common/context.go
Normal file
8
internal/common/context.go
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
type contextKey string
|
||||||
|
|
||||||
|
const RouterContextKey contextKey = contextKey("router")
|
||||||
|
const SourceContextKey contextKey = contextKey("source")
|
||||||
|
const ModulesContextKey contextKey = contextKey("modules")
|
||||||
|
const SenderContextKey contextKey = contextKey("sender")
|
||||||
26
internal/common/module.go
Normal file
26
internal/common/module.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Module interface {
|
||||||
|
Id() string
|
||||||
|
Type() string
|
||||||
|
Start(context.Context) error
|
||||||
|
Stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
type OutputModule interface {
|
||||||
|
Output(context.Context, any) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type KeyValueModule interface {
|
||||||
|
Get(key string) (any, error)
|
||||||
|
Set(key string, value any) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type DatabaseModule interface {
|
||||||
|
Database() *sql.DB
|
||||||
|
}
|
||||||
40
internal/common/payload.go
Normal file
40
internal/common/payload.go
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
)
|
||||||
|
|
||||||
|
type WrappedPayload struct {
|
||||||
|
Payload any
|
||||||
|
Modules map[string]Module
|
||||||
|
Sender any
|
||||||
|
Source string
|
||||||
|
End bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetWrappedPayload(ctx context.Context, payload any) WrappedPayload {
|
||||||
|
wrappedPayload := WrappedPayload{
|
||||||
|
Payload: payload,
|
||||||
|
End: false,
|
||||||
|
}
|
||||||
|
modules := ctx.Value(ModulesContextKey)
|
||||||
|
if modules != nil {
|
||||||
|
moduleMap, ok := modules.(map[string]Module)
|
||||||
|
if ok {
|
||||||
|
wrappedPayload.Modules = moduleMap
|
||||||
|
} else {
|
||||||
|
wrappedPayload.Modules = make(map[string]Module)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sender := ctx.Value(SenderContextKey)
|
||||||
|
if sender != nil {
|
||||||
|
wrappedPayload.Sender = sender
|
||||||
|
}
|
||||||
|
|
||||||
|
source := ctx.Value(SourceContextKey)
|
||||||
|
if source != nil {
|
||||||
|
wrappedPayload.Source = source.(string)
|
||||||
|
}
|
||||||
|
return wrappedPayload
|
||||||
|
}
|
||||||
82
internal/common/payload_test.go
Normal file
82
internal/common/payload_test.go
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
package common_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/test"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGoodGetWrappedPayload(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
ctx context.Context
|
||||||
|
payload any
|
||||||
|
expected common.WrappedPayload
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "basic",
|
||||||
|
ctx: t.Context(),
|
||||||
|
payload: "test",
|
||||||
|
expected: common.WrappedPayload{
|
||||||
|
Payload: "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "with modules in context",
|
||||||
|
ctx: test.GetContextWithModules(t.Context(), map[string]common.Module{}),
|
||||||
|
payload: "test",
|
||||||
|
expected: common.WrappedPayload{
|
||||||
|
Payload: "test",
|
||||||
|
Modules: map[string]common.Module{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "with sender in context",
|
||||||
|
ctx: test.GetContextWithSender(t.Context(), "sender"),
|
||||||
|
payload: "test",
|
||||||
|
expected: common.WrappedPayload{
|
||||||
|
Payload: "test",
|
||||||
|
Sender: "sender",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "with source in context",
|
||||||
|
ctx: test.GetContextWithSource(t.Context(), "source"),
|
||||||
|
payload: "test",
|
||||||
|
expected: common.WrappedPayload{
|
||||||
|
Payload: "test",
|
||||||
|
Source: "source",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "with all fields in context",
|
||||||
|
ctx: test.GetContextWithSource(
|
||||||
|
test.GetContextWithSender(
|
||||||
|
test.GetContextWithModules(t.Context(), map[string]common.Module{}),
|
||||||
|
"sender",
|
||||||
|
),
|
||||||
|
"source",
|
||||||
|
),
|
||||||
|
payload: "test",
|
||||||
|
expected: common.WrappedPayload{
|
||||||
|
Payload: "test",
|
||||||
|
Modules: map[string]common.Module{},
|
||||||
|
Sender: "sender",
|
||||||
|
Source: "source",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
wrappedPayload := common.GetWrappedPayload(testCase.ctx, testCase.payload)
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(wrappedPayload, testCase.expected) {
|
||||||
|
t.Fatalf("GetWrappedPayload expected got %+v, expected %+v", wrappedPayload, testCase.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
15
internal/common/routing.go
Normal file
15
internal/common/routing.go
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
|
type RouteIO interface {
|
||||||
|
HandleInput(ctx context.Context, sourceId string, payload any) (bool, []RouteIOError)
|
||||||
|
HandleOutput(ctx context.Context, destinationId string, payload any) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type RouteIOError struct {
|
||||||
|
Index int `json:"index"`
|
||||||
|
OutputError error `json:"outputError"`
|
||||||
|
ProcessError error `json:"processError"`
|
||||||
|
InputError error `json:"inputError"`
|
||||||
|
}
|
||||||
6
internal/config/api.go
Normal file
6
internal/config/api.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
type ApiConfig struct {
|
||||||
|
Enabled bool `json:"enabled"`
|
||||||
|
Port int `json:"port"`
|
||||||
|
}
|
||||||
@@ -1,78 +1,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
Api ApiConfig `json:"api"`
|
||||||
Modules []ModuleConfig `json:"modules"`
|
Modules []ModuleConfig `json:"modules"`
|
||||||
Routes []RouteConfig `json:"routes"`
|
Routes []RouteConfig `json:"routes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Params map[string]any
|
|
||||||
|
|
||||||
var (
|
|
||||||
ErrParamNotFound = errors.New("not found")
|
|
||||||
ErrParamNotString = errors.New("not a string")
|
|
||||||
ErrParamNotNumber = errors.New("not a number")
|
|
||||||
)
|
|
||||||
|
|
||||||
func (p Params) GetString(key string) (string, error) {
|
|
||||||
value, ok := p[key]
|
|
||||||
if !ok {
|
|
||||||
return "", ErrParamNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
stringValue, ok := value.(string)
|
|
||||||
if !ok {
|
|
||||||
return "", ErrParamNotString
|
|
||||||
}
|
|
||||||
return stringValue, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p Params) GetInt(key string) (int, error) {
|
|
||||||
value, ok := p[key]
|
|
||||||
if !ok {
|
|
||||||
return 0, ErrParamNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
intValue, ok := value.(int)
|
|
||||||
if !ok {
|
|
||||||
floatValue, ok := value.(float64)
|
|
||||||
if !ok {
|
|
||||||
return 0, ErrParamNotNumber
|
|
||||||
}
|
|
||||||
intValue = int(floatValue)
|
|
||||||
}
|
|
||||||
return intValue, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p Params) GetBool(key string) (bool, error) {
|
|
||||||
value, ok := p[key]
|
|
||||||
if !ok {
|
|
||||||
return false, ErrParamNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
boolValue, ok := value.(bool)
|
|
||||||
if !ok {
|
|
||||||
return false, errors.New("not a boolean")
|
|
||||||
}
|
|
||||||
return boolValue, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type ModuleConfig struct {
|
|
||||||
Id string `json:"id"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
Params Params `json:"params"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type RouteConfig struct {
|
|
||||||
Input string `json:"input"`
|
|
||||||
Processors []ProcessorConfig `json:"processors"`
|
|
||||||
Output string `json:"output"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ProcessorConfig struct {
|
|
||||||
Type string `json:"type"`
|
|
||||||
Params Params `json:"params"`
|
|
||||||
}
|
|
||||||
|
|||||||
7
internal/config/module.go
Normal file
7
internal/config/module.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
type ModuleConfig struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Params Params `json:"params,omitempty"`
|
||||||
|
}
|
||||||
140
internal/config/params.go
Normal file
140
internal/config/params.go
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Params map[string]any
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrParamNotFound = errors.New("not found")
|
||||||
|
ErrParamNotString = errors.New("not a string")
|
||||||
|
ErrParamNotNumber = errors.New("not a number")
|
||||||
|
ErrParamNotInteger = errors.New("not an integer")
|
||||||
|
ErrParamNotBool = errors.New("not a boolean")
|
||||||
|
ErrParamNotSlice = errors.New("not a slice")
|
||||||
|
ErrParamNotStringSlice = errors.New("not a string slice")
|
||||||
|
ErrParamNotByteSlice = errors.New("not a byte slice")
|
||||||
|
ErrParamNotIntSlice = errors.New("not an int slice")
|
||||||
|
)
|
||||||
|
|
||||||
|
func (p Params) GetString(key string) (string, error) {
|
||||||
|
value, ok := p[key]
|
||||||
|
if !ok {
|
||||||
|
return "", ErrParamNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
stringValue, ok := value.(string)
|
||||||
|
if !ok {
|
||||||
|
return "", ErrParamNotString
|
||||||
|
}
|
||||||
|
return stringValue, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Params) GetInt(key string) (int, error) {
|
||||||
|
value, ok := p[key]
|
||||||
|
if !ok {
|
||||||
|
return 0, ErrParamNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
intValue, ok := common.GetAnyAsInt(value)
|
||||||
|
if ok {
|
||||||
|
return intValue, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0, ErrParamNotNumber
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Params) GetFloat32(key string) (float32, error) {
|
||||||
|
value, ok := p[key]
|
||||||
|
if !ok {
|
||||||
|
return 0, ErrParamNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
floatValue, ok := common.GetAnyAsFloat32(value)
|
||||||
|
if ok {
|
||||||
|
return floatValue, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0, ErrParamNotNumber
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Params) GetFloat64(key string) (float64, error) {
|
||||||
|
value, ok := p[key]
|
||||||
|
if !ok {
|
||||||
|
return 0, ErrParamNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
floatValue, ok := common.GetAnyAsFloat64(value)
|
||||||
|
if ok {
|
||||||
|
return floatValue, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0, ErrParamNotNumber
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Params) GetBool(key string) (bool, error) {
|
||||||
|
value, ok := p[key]
|
||||||
|
if !ok {
|
||||||
|
return false, ErrParamNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
boolValue, ok := value.(bool)
|
||||||
|
if !ok {
|
||||||
|
return false, ErrParamNotBool
|
||||||
|
}
|
||||||
|
return boolValue, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Params) GetStringSlice(key string) ([]string, error) {
|
||||||
|
value, ok := p[key]
|
||||||
|
if !ok {
|
||||||
|
return nil, ErrParamNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
interfaceSlice, ok := value.([]any)
|
||||||
|
if !ok {
|
||||||
|
return nil, ErrParamNotSlice
|
||||||
|
}
|
||||||
|
|
||||||
|
stringSlice := make([]string, len(interfaceSlice))
|
||||||
|
for i, v := range interfaceSlice {
|
||||||
|
str, ok := v.(string)
|
||||||
|
if !ok {
|
||||||
|
return nil, ErrParamNotStringSlice
|
||||||
|
}
|
||||||
|
stringSlice[i] = str
|
||||||
|
}
|
||||||
|
return stringSlice, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Params) GetIntSlice(key string) ([]int, error) {
|
||||||
|
value, ok := p[key]
|
||||||
|
if !ok {
|
||||||
|
return nil, ErrParamNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
intSlice, ok := common.GetAnyAsIntSlice(value)
|
||||||
|
if !ok {
|
||||||
|
return nil, ErrParamNotIntSlice
|
||||||
|
}
|
||||||
|
|
||||||
|
return intSlice, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Params) GetByteSlice(key string) ([]byte, error) {
|
||||||
|
value, ok := p[key]
|
||||||
|
if !ok {
|
||||||
|
return nil, ErrParamNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
byteSlice, ok := common.GetAnyAsByteSlice(value)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, ErrParamNotByteSlice
|
||||||
|
}
|
||||||
|
|
||||||
|
return byteSlice, nil
|
||||||
|
}
|
||||||
628
internal/config/params_test.go
Normal file
628
internal/config/params_test.go
Normal file
@@ -0,0 +1,628 @@
|
|||||||
|
package config_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"slices"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGoodStringParamsJSON(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
paramsJSON string
|
||||||
|
key string
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "string param",
|
||||||
|
paramsJSON: `{"key": "value"}`,
|
||||||
|
key: "key",
|
||||||
|
expected: "value",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
params := config.Params{}
|
||||||
|
err := json.Unmarshal([]byte(testCase.paramsJSON), ¶ms)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to unmarshal params JSON: %v", err)
|
||||||
|
}
|
||||||
|
value, err := params.GetString(testCase.key)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GetString returned error: %v", err)
|
||||||
|
}
|
||||||
|
if value != testCase.expected {
|
||||||
|
t.Fatalf("GetString got %s, expected %s", value, testCase.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadStringParamsJSON(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
paramsJSON string
|
||||||
|
key string
|
||||||
|
returnError error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "key not found",
|
||||||
|
paramsJSON: `{"key": "value"}`,
|
||||||
|
key: "test",
|
||||||
|
returnError: config.ErrParamNotFound,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "not a string",
|
||||||
|
paramsJSON: `{"key": 1}`,
|
||||||
|
key: "key",
|
||||||
|
returnError: config.ErrParamNotString,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
params := config.Params{}
|
||||||
|
err := json.Unmarshal([]byte(testCase.paramsJSON), ¶ms)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to unmarshal params JSON: %v", err)
|
||||||
|
}
|
||||||
|
value, err := params.GetString(testCase.key)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("GetString expected to fail but succeeded, got: %v", value)
|
||||||
|
}
|
||||||
|
if !errors.Is(err, testCase.returnError) {
|
||||||
|
t.Fatalf("GetString got error '%s', expected '%s'", err, testCase.returnError)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGoodIntParamsJSON(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
paramsJSON string
|
||||||
|
key string
|
||||||
|
expected int
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "int param",
|
||||||
|
paramsJSON: `{"key": 1}`,
|
||||||
|
key: "key",
|
||||||
|
expected: 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
params := config.Params{}
|
||||||
|
err := json.Unmarshal([]byte(testCase.paramsJSON), ¶ms)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to unmarshal params JSON: %v", err)
|
||||||
|
}
|
||||||
|
value, err := params.GetInt(testCase.key)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GetInt returned error: %v", err)
|
||||||
|
}
|
||||||
|
if value != testCase.expected {
|
||||||
|
t.Fatalf("GetInt got %d, expected %d", value, testCase.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadIntParamsJSON(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
paramsJSON string
|
||||||
|
key string
|
||||||
|
returnError error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "key not found",
|
||||||
|
paramsJSON: `{"key": 1}`,
|
||||||
|
key: "test",
|
||||||
|
returnError: config.ErrParamNotFound,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "not a number",
|
||||||
|
paramsJSON: `{"key": "1"}`,
|
||||||
|
key: "key",
|
||||||
|
returnError: config.ErrParamNotNumber,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
params := config.Params{}
|
||||||
|
err := json.Unmarshal([]byte(testCase.paramsJSON), ¶ms)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to unmarshal params JSON: %v", err)
|
||||||
|
}
|
||||||
|
value, err := params.GetInt(testCase.key)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("GetInt expected to fail but succeeded, got: %v", value)
|
||||||
|
}
|
||||||
|
if !errors.Is(err, testCase.returnError) {
|
||||||
|
t.Fatalf("GetInt got error '%s', expected '%s'", err, testCase.returnError)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGoodFloat32ParamsJSON(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
paramsJSON string
|
||||||
|
key string
|
||||||
|
expected float32
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "no decimal param",
|
||||||
|
paramsJSON: `{"key": 1}`,
|
||||||
|
key: "key",
|
||||||
|
expected: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "float param",
|
||||||
|
paramsJSON: `{"key": 1.23}`,
|
||||||
|
key: "key",
|
||||||
|
expected: 1.23,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
params := config.Params{}
|
||||||
|
err := json.Unmarshal([]byte(testCase.paramsJSON), ¶ms)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to unmarshal params JSON: %v", err)
|
||||||
|
}
|
||||||
|
value, err := params.GetFloat32(testCase.key)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GetFloat32 returned error: %v", err)
|
||||||
|
}
|
||||||
|
if value != testCase.expected {
|
||||||
|
t.Fatalf("GetFloat32 got %f, expected %f", value, testCase.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadFloat32ParamsJSON(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
paramsJSON string
|
||||||
|
key string
|
||||||
|
returnError error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "key not found",
|
||||||
|
paramsJSON: `{"key": 1}`,
|
||||||
|
key: "test",
|
||||||
|
returnError: config.ErrParamNotFound,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "not a number",
|
||||||
|
paramsJSON: `{"key": "1"}`,
|
||||||
|
key: "key",
|
||||||
|
returnError: config.ErrParamNotNumber,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
params := config.Params{}
|
||||||
|
err := json.Unmarshal([]byte(testCase.paramsJSON), ¶ms)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to unmarshal params JSON: %v", err)
|
||||||
|
}
|
||||||
|
value, err := params.GetFloat32(testCase.key)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("GetFloat32 expected to fail but succeeded, got: %v", value)
|
||||||
|
}
|
||||||
|
if !errors.Is(err, testCase.returnError) {
|
||||||
|
t.Fatalf("GetFloat32 got error '%s', expected '%s'", err, testCase.returnError)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGoodFloat64ParamsJSON(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
paramsJSON string
|
||||||
|
key string
|
||||||
|
expected float64
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "no decimal param",
|
||||||
|
paramsJSON: `{"key": 1}`,
|
||||||
|
key: "key",
|
||||||
|
expected: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "float param",
|
||||||
|
paramsJSON: `{"key": 1.23}`,
|
||||||
|
key: "key",
|
||||||
|
expected: 1.23,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
params := config.Params{}
|
||||||
|
err := json.Unmarshal([]byte(testCase.paramsJSON), ¶ms)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to unmarshal params JSON: %v", err)
|
||||||
|
}
|
||||||
|
value, err := params.GetFloat64(testCase.key)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GetFloat64 returned error: %v", err)
|
||||||
|
}
|
||||||
|
if value != testCase.expected {
|
||||||
|
t.Fatalf("GetFloat64 got %f, expected %f", value, testCase.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadFloat64ParamsJSON(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
paramsJSON string
|
||||||
|
key string
|
||||||
|
returnError error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "key not found",
|
||||||
|
paramsJSON: `{"key": 1}`,
|
||||||
|
key: "test",
|
||||||
|
returnError: config.ErrParamNotFound,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "not a number",
|
||||||
|
paramsJSON: `{"key": "1"}`,
|
||||||
|
key: "key",
|
||||||
|
returnError: config.ErrParamNotNumber,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
params := config.Params{}
|
||||||
|
err := json.Unmarshal([]byte(testCase.paramsJSON), ¶ms)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to unmarshal params JSON: %v", err)
|
||||||
|
}
|
||||||
|
value, err := params.GetFloat64(testCase.key)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("GetFloat64 expected to fail but succeeded, got: %v", value)
|
||||||
|
}
|
||||||
|
if !errors.Is(err, testCase.returnError) {
|
||||||
|
t.Fatalf("GetFloat64 got error '%s', expected '%s'", err, testCase.returnError)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGoodBoolParamsJSON(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
paramsJSON string
|
||||||
|
key string
|
||||||
|
expected bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "bool param",
|
||||||
|
paramsJSON: `{"key": true}`,
|
||||||
|
key: "key",
|
||||||
|
expected: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
params := config.Params{}
|
||||||
|
err := json.Unmarshal([]byte(testCase.paramsJSON), ¶ms)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to unmarshal params JSON: %v", err)
|
||||||
|
}
|
||||||
|
value, err := params.GetBool(testCase.key)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GetBool returned error: %v", err)
|
||||||
|
}
|
||||||
|
if value != testCase.expected {
|
||||||
|
t.Fatalf("GetBool got %t, expected %t", value, testCase.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadBoolParamsJSON(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
paramsJSON string
|
||||||
|
key string
|
||||||
|
returnError error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "key not found",
|
||||||
|
paramsJSON: `{"key": 1}`,
|
||||||
|
key: "test",
|
||||||
|
returnError: config.ErrParamNotFound,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "not a bool",
|
||||||
|
paramsJSON: `{"key": "1"}`,
|
||||||
|
key: "key",
|
||||||
|
returnError: config.ErrParamNotBool,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
params := config.Params{}
|
||||||
|
err := json.Unmarshal([]byte(testCase.paramsJSON), ¶ms)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to unmarshal params JSON: %v", err)
|
||||||
|
}
|
||||||
|
value, err := params.GetBool(testCase.key)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("GetBool expected to fail but succeeded, got: %v", value)
|
||||||
|
}
|
||||||
|
if !errors.Is(err, testCase.returnError) {
|
||||||
|
t.Fatalf("GetBool got error '%s', expected '%s'", err, testCase.returnError)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGoodStringSliceParamsJSON(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
paramsJSON string
|
||||||
|
key string
|
||||||
|
expected []string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "string array",
|
||||||
|
paramsJSON: `{"key": ["value1", "value2"]}`,
|
||||||
|
key: "key",
|
||||||
|
expected: []string{"value1", "value2"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
params := config.Params{}
|
||||||
|
err := json.Unmarshal([]byte(testCase.paramsJSON), ¶ms)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to unmarshal params JSON: %v", err)
|
||||||
|
}
|
||||||
|
value, err := params.GetStringSlice(testCase.key)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GetStringSlice returned error: %v", err)
|
||||||
|
}
|
||||||
|
if !slices.Equal(value, testCase.expected) {
|
||||||
|
t.Fatalf("GetStringSlice got %v, expected %v", value, testCase.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadStringSliceParamsJSON(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
paramsJSON string
|
||||||
|
key string
|
||||||
|
returnError error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "key not found",
|
||||||
|
paramsJSON: `{"key": ["value1", "value2"]}`,
|
||||||
|
key: "test",
|
||||||
|
returnError: config.ErrParamNotFound,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "not a slice",
|
||||||
|
paramsJSON: `{"key": "value"}`,
|
||||||
|
key: "key",
|
||||||
|
returnError: config.ErrParamNotSlice,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "not a string slice",
|
||||||
|
paramsJSON: `{"key": ["value1", 2]}`,
|
||||||
|
key: "key",
|
||||||
|
returnError: config.ErrParamNotStringSlice,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
params := config.Params{}
|
||||||
|
err := json.Unmarshal([]byte(testCase.paramsJSON), ¶ms)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to unmarshal params JSON: %v", err)
|
||||||
|
}
|
||||||
|
value, err := params.GetStringSlice(testCase.key)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("GetStringSlice expected to fail but succeeded, got: %v", value)
|
||||||
|
}
|
||||||
|
if !errors.Is(err, testCase.returnError) {
|
||||||
|
t.Fatalf("GetStringSlice got error '%s', expected '%s'", err, testCase.returnError)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGoodIntSliceParamsJSON(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
paramsJSON string
|
||||||
|
key string
|
||||||
|
expected []int
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "int array",
|
||||||
|
paramsJSON: `{"key": [1, 2, 3]}`,
|
||||||
|
key: "key",
|
||||||
|
expected: []int{1, 2, 3},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "int array with floats",
|
||||||
|
paramsJSON: `{"key": [1.0, 2.0, 3.0]}`,
|
||||||
|
key: "key",
|
||||||
|
expected: []int{1, 2, 3},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
params := config.Params{}
|
||||||
|
err := json.Unmarshal([]byte(testCase.paramsJSON), ¶ms)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to unmarshal params JSON: %v", err)
|
||||||
|
}
|
||||||
|
value, err := params.GetIntSlice(testCase.key)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GetIntSlice returned error: %v", err)
|
||||||
|
}
|
||||||
|
if !slices.Equal(value, testCase.expected) {
|
||||||
|
t.Fatalf("GetIntSlice got %v, expected %v", value, testCase.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadIntSliceParamsJSON(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
paramsJSON string
|
||||||
|
key string
|
||||||
|
returnError error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "key not found",
|
||||||
|
paramsJSON: `{"key": ["value1", "value2"]}`,
|
||||||
|
key: "test",
|
||||||
|
returnError: config.ErrParamNotFound,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "not a slice",
|
||||||
|
paramsJSON: `{"key": "value"}`,
|
||||||
|
key: "key",
|
||||||
|
returnError: config.ErrParamNotIntSlice,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "not a int slice",
|
||||||
|
paramsJSON: `{"key": ["value1", 2]}`,
|
||||||
|
key: "key",
|
||||||
|
returnError: config.ErrParamNotIntSlice,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
params := config.Params{}
|
||||||
|
err := json.Unmarshal([]byte(testCase.paramsJSON), ¶ms)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to unmarshal params JSON: %v", err)
|
||||||
|
}
|
||||||
|
value, err := params.GetIntSlice(testCase.key)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("GetIntSlice expected to fail but succeeded, got: %v", value)
|
||||||
|
}
|
||||||
|
if !errors.Is(err, testCase.returnError) {
|
||||||
|
t.Fatalf("GetIntSlice got error '%s', expected '%s'", err, testCase.returnError)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGoodByteSliceParamsJSON(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
paramsJSON string
|
||||||
|
key string
|
||||||
|
expected []byte
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "byte array",
|
||||||
|
paramsJSON: `{"key": [1,2,3,4]}`,
|
||||||
|
key: "key",
|
||||||
|
expected: []byte{1, 2, 3, 4},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "byte array with floats",
|
||||||
|
paramsJSON: `{"key": [1.0,2.0,3.0,4.0]}`,
|
||||||
|
key: "key",
|
||||||
|
expected: []byte{1, 2, 3, 4},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
params := config.Params{}
|
||||||
|
err := json.Unmarshal([]byte(testCase.paramsJSON), ¶ms)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to unmarshal params JSON: %v", err)
|
||||||
|
}
|
||||||
|
value, err := params.GetByteSlice(testCase.key)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GetByteSlice returned error: %v", err)
|
||||||
|
}
|
||||||
|
if !slices.Equal(value, testCase.expected) {
|
||||||
|
t.Fatalf("GetByteSlice got %v, expected %v", value, testCase.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadByteSliceParamsJSON(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
paramsJSON string
|
||||||
|
key string
|
||||||
|
returnError error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "key not found",
|
||||||
|
paramsJSON: `{"key": ["value1", "value2"]}`,
|
||||||
|
key: "test",
|
||||||
|
returnError: config.ErrParamNotFound,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "not a slice",
|
||||||
|
paramsJSON: `{"key": "value"}`,
|
||||||
|
key: "key",
|
||||||
|
returnError: config.ErrParamNotByteSlice,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "not a int slice",
|
||||||
|
paramsJSON: `{"key": ["value1", 2]}`,
|
||||||
|
key: "key",
|
||||||
|
returnError: config.ErrParamNotByteSlice,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
params := config.Params{}
|
||||||
|
err := json.Unmarshal([]byte(testCase.paramsJSON), ¶ms)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to unmarshal params JSON: %v", err)
|
||||||
|
}
|
||||||
|
value, err := params.GetByteSlice(testCase.key)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("GetByteSlice expected to fail but succeeded, got: %v", value)
|
||||||
|
}
|
||||||
|
if !errors.Is(err, testCase.returnError) {
|
||||||
|
t.Fatalf("GetByteSlice got error '%s', expected '%s'", err, testCase.returnError)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
6
internal/config/processor.go
Normal file
6
internal/config/processor.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
type ProcessorConfig struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
Params Params `json:"params,omitempty"`
|
||||||
|
}
|
||||||
6
internal/config/route.go
Normal file
6
internal/config/route.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
type RouteConfig struct {
|
||||||
|
Input string `json:"input"`
|
||||||
|
Processors []ProcessorConfig `json:"processors"`
|
||||||
|
}
|
||||||
90
internal/module/db-sqlite.go
Normal file
90
internal/module/db-sqlite.go
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
package module
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
|
||||||
|
_ "modernc.org/sqlite"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DbSqlite struct {
|
||||||
|
config config.ModuleConfig
|
||||||
|
Dsn string
|
||||||
|
ctx context.Context
|
||||||
|
router common.RouteIO
|
||||||
|
db *sql.DB
|
||||||
|
logger *slog.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterModule(ModuleRegistration{
|
||||||
|
Type: "db.sqlite",
|
||||||
|
Title: "SQLite Database",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"dsn": {
|
||||||
|
Type: "string",
|
||||||
|
MinLength: jsonschema.Ptr(1),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"dsn"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
|
params := config.Params
|
||||||
|
|
||||||
|
dsnString, err := params.GetString("dsn")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("db.sqlite dsn error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &DbSqlite{Dsn: dsnString, config: config, logger: CreateLogger(config)}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *DbSqlite) Id() string {
|
||||||
|
return t.config.Id
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *DbSqlite) Type() string {
|
||||||
|
return t.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *DbSqlite) Start(ctx context.Context) error {
|
||||||
|
t.logger.Debug("running")
|
||||||
|
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return errors.New("db.sqlite unable to get router from context")
|
||||||
|
}
|
||||||
|
t.router = router
|
||||||
|
t.ctx = ctx
|
||||||
|
|
||||||
|
db, err := sql.Open("sqlite", t.Dsn)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("db.sqlite error opening database: %w", err)
|
||||||
|
}
|
||||||
|
t.db = db
|
||||||
|
defer t.db.Close()
|
||||||
|
<-ctx.Done()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *DbSqlite) Stop() {
|
||||||
|
if t.db != nil {
|
||||||
|
t.db.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *DbSqlite) Database() *sql.DB {
|
||||||
|
return t.db
|
||||||
|
}
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
package module
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"log/slog"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/route"
|
|
||||||
)
|
|
||||||
|
|
||||||
type HTTPClient struct {
|
|
||||||
config config.ModuleConfig
|
|
||||||
ctx context.Context
|
|
||||||
client *http.Client
|
|
||||||
router route.RouteIO
|
|
||||||
logger *slog.Logger
|
|
||||||
cancel context.CancelFunc
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
RegisterModule(ModuleRegistration{
|
|
||||||
Type: "http.client",
|
|
||||||
New: func(config config.ModuleConfig) (Module, error) {
|
|
||||||
|
|
||||||
return &HTTPClient{config: config, logger: CreateLogger(config)}, nil
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hc *HTTPClient) Id() string {
|
|
||||||
return hc.config.Id
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hc *HTTPClient) Type() string {
|
|
||||||
return hc.config.Type
|
|
||||||
}
|
|
||||||
|
|
||||||
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,
|
|
||||||
}
|
|
||||||
|
|
||||||
<-hc.ctx.Done()
|
|
||||||
hc.logger.Debug("done")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hc *HTTPClient) Output(ctx context.Context, payload any) error {
|
|
||||||
|
|
||||||
payloadRequest, ok := payload.(*http.Request)
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return errors.New("http.client is only able to output an http.Request")
|
|
||||||
}
|
|
||||||
|
|
||||||
if hc.client == nil {
|
|
||||||
return errors.New("http.client client is nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
response, err := hc.client.Do(payloadRequest)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if hc.router != nil {
|
|
||||||
hc.router.HandleInput(hc.ctx, hc.Id(), response)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hc *HTTPClient) Stop() {
|
|
||||||
hc.cancel()
|
|
||||||
}
|
|
||||||
@@ -6,18 +6,20 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
"github.com/jwetzell/showbridge-go/internal/route"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type HTTPServer struct {
|
type HTTPServer struct {
|
||||||
config config.ModuleConfig
|
config config.ModuleConfig
|
||||||
Port uint16
|
Port uint16
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
router route.RouteIO
|
router common.RouteIO
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
}
|
}
|
||||||
@@ -54,8 +56,22 @@ func (hsrw *HTTPServerResponseWriter) Write(data []byte) (int, error) {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "http.server",
|
Type: "http.server",
|
||||||
New: func(config config.ModuleConfig) (Module, error) {
|
Title: "HTTP Server",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"port": {
|
||||||
|
Title: "Port",
|
||||||
|
Type: "integer",
|
||||||
|
Minimum: jsonschema.Ptr[float64](1024),
|
||||||
|
Maximum: jsonschema.Ptr[float64](65535),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"port"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
portNum, err := params.GetInt("port")
|
portNum, err := params.GetInt("port")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -83,6 +99,10 @@ func (hs *HTTPServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
if hs.router != nil {
|
if hs.router != nil {
|
||||||
inputContext := context.WithValue(hs.ctx, httpServerContextKey("responseWriter"), &responseWriter)
|
inputContext := context.WithValue(hs.ctx, httpServerContextKey("responseWriter"), &responseWriter)
|
||||||
|
senderAddr, err := net.ResolveTCPAddr("tcp", r.RemoteAddr)
|
||||||
|
if err == nil {
|
||||||
|
inputContext = context.WithValue(inputContext, common.SenderContextKey, senderAddr)
|
||||||
|
}
|
||||||
aRouteFound, routingErrors := hs.router.HandleInput(inputContext, hs.Id(), r)
|
aRouteFound, routingErrors := hs.router.HandleInput(inputContext, hs.Id(), r)
|
||||||
if !responseWriter.done {
|
if !responseWriter.done {
|
||||||
if aRouteFound {
|
if aRouteFound {
|
||||||
@@ -142,7 +162,7 @@ func (hs *HTTPServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func (hs *HTTPServer) Start(ctx context.Context) error {
|
func (hs *HTTPServer) Start(ctx context.Context) error {
|
||||||
hs.logger.Debug("running")
|
hs.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("http.server unable to get router from context")
|
return errors.New("http.server unable to get router from context")
|
||||||
@@ -182,7 +202,7 @@ func (hs *HTTPServer) Output(ctx context.Context, payload any) error {
|
|||||||
return errors.New("http.server output must originate from an http.server input")
|
return errors.New("http.server output must originate from an http.server input")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadResponse, ok := payload.(processor.HTTPResponse)
|
payloadResponse, ok := common.GetAnyAs[processor.HTTPResponse](payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("http.server is only able to output HTTPResponse")
|
return errors.New("http.server is only able to output HTTPResponse")
|
||||||
|
|||||||
@@ -8,8 +8,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/route"
|
|
||||||
"gitlab.com/gomidi/midi/v2"
|
"gitlab.com/gomidi/midi/v2"
|
||||||
_ "gitlab.com/gomidi/midi/v2/drivers/rtmididrv"
|
_ "gitlab.com/gomidi/midi/v2/drivers/rtmididrv"
|
||||||
)
|
)
|
||||||
@@ -17,7 +18,7 @@ import (
|
|||||||
type MIDIInput struct {
|
type MIDIInput struct {
|
||||||
config config.ModuleConfig
|
config config.ModuleConfig
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
router route.RouteIO
|
router common.RouteIO
|
||||||
Port string
|
Port string
|
||||||
SendFunc func(midi.Message) error
|
SendFunc func(midi.Message) error
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
@@ -26,8 +27,20 @@ type MIDIInput struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "midi.input",
|
Type: "midi.input",
|
||||||
New: func(config config.ModuleConfig) (Module, error) {
|
Title: "MIDI Input",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"port": {
|
||||||
|
Title: "Port",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"port"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
portString, err := params.GetString("port")
|
portString, err := params.GetString("port")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -50,7 +63,7 @@ func (mi *MIDIInput) Type() string {
|
|||||||
func (mi *MIDIInput) Start(ctx context.Context) error {
|
func (mi *MIDIInput) Start(ctx context.Context) error {
|
||||||
mi.logger.Debug("running")
|
mi.logger.Debug("running")
|
||||||
defer midi.CloseDriver()
|
defer midi.CloseDriver()
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("midi.input unable to get router from context")
|
return errors.New("midi.input unable to get router from context")
|
||||||
@@ -82,10 +95,6 @@ func (mi *MIDIInput) Start(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mi *MIDIInput) Output(ctx context.Context, payload any) error {
|
|
||||||
return errors.New("midi.input output is not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mi *MIDIInput) Stop() {
|
func (mi *MIDIInput) Stop() {
|
||||||
mi.cancel()
|
mi.cancel()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/route"
|
|
||||||
"gitlab.com/gomidi/midi/v2"
|
"gitlab.com/gomidi/midi/v2"
|
||||||
_ "gitlab.com/gomidi/midi/v2/drivers/rtmididrv"
|
_ "gitlab.com/gomidi/midi/v2/drivers/rtmididrv"
|
||||||
)
|
)
|
||||||
@@ -17,7 +18,7 @@ import (
|
|||||||
type MIDIOutput struct {
|
type MIDIOutput struct {
|
||||||
config config.ModuleConfig
|
config config.ModuleConfig
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
router route.RouteIO
|
router common.RouteIO
|
||||||
Port string
|
Port string
|
||||||
SendFunc func(midi.Message) error
|
SendFunc func(midi.Message) error
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
@@ -26,8 +27,20 @@ type MIDIOutput struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "midi.output",
|
Type: "midi.output",
|
||||||
New: func(config config.ModuleConfig) (Module, error) {
|
Title: "MIDI Output",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"port": {
|
||||||
|
Title: "Port",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"port"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
|
|
||||||
portString, err := params.GetString("port")
|
portString, err := params.GetString("port")
|
||||||
@@ -51,7 +64,7 @@ func (mo *MIDIOutput) Type() string {
|
|||||||
func (mo *MIDIOutput) Start(ctx context.Context) error {
|
func (mo *MIDIOutput) Start(ctx context.Context) error {
|
||||||
mo.logger.Debug("running")
|
mo.logger.Debug("running")
|
||||||
defer midi.CloseDriver()
|
defer midi.CloseDriver()
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("midi.output unable to get router from context")
|
return errors.New("midi.output unable to get router from context")
|
||||||
@@ -84,10 +97,10 @@ func (mo *MIDIOutput) Output(ctx context.Context, payload any) error {
|
|||||||
return errors.New("midi.output output is not setup")
|
return errors.New("midi.output output is not setup")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadMessage, ok := payload.(midi.Message)
|
payloadMessage, ok := common.GetAnyAs[midi.Message](payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("midi.output can only ouptut midi.Message")
|
return errors.New("midi.output can only output midi.Message")
|
||||||
}
|
}
|
||||||
|
|
||||||
return mo.SendFunc(payloadMessage)
|
return mo.SendFunc(payloadMessage)
|
||||||
|
|||||||
@@ -1,31 +1,27 @@
|
|||||||
package module
|
package module
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ModuleError struct {
|
type ModuleError struct {
|
||||||
Index int
|
Index int `json:"index"`
|
||||||
Config config.ModuleConfig
|
Config config.ModuleConfig `json:"config"`
|
||||||
Error error
|
Error string `json:"error"`
|
||||||
}
|
|
||||||
|
|
||||||
type Module interface {
|
|
||||||
Id() string
|
|
||||||
Type() string
|
|
||||||
Start(context.Context) error
|
|
||||||
Stop()
|
|
||||||
Output(context.Context, any) error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ModuleRegistration struct {
|
type ModuleRegistration struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
New func(config.ModuleConfig) (Module, error)
|
Title string `json:"title,omitempty"`
|
||||||
|
Description string `json:"description,omitempty"`
|
||||||
|
ParamsSchema *jsonschema.Schema `json:"paramsSchema,omitempty"`
|
||||||
|
New func(config.ModuleConfig) (common.Module, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterModule(mod ModuleRegistration) {
|
func RegisterModule(mod ModuleRegistration) {
|
||||||
|
|||||||
@@ -7,14 +7,15 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/route"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type MQTTClient struct {
|
type MQTTClient struct {
|
||||||
config config.ModuleConfig
|
config config.ModuleConfig
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
router route.RouteIO
|
router common.RouteIO
|
||||||
Broker string
|
Broker string
|
||||||
ClientID string
|
ClientID string
|
||||||
Topic string
|
Topic string
|
||||||
@@ -25,8 +26,28 @@ type MQTTClient struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "mqtt.client",
|
Type: "mqtt.client",
|
||||||
New: func(config config.ModuleConfig) (Module, error) {
|
Title: "MQTT Client",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"broker": {
|
||||||
|
Title: "Broker URL",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"topic": {
|
||||||
|
Title: "Topic",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"clientId": {
|
||||||
|
Title: "Client ID",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"broker", "topic", "clientId"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
brokerString, err := params.GetString("broker")
|
brokerString, err := params.GetString("broker")
|
||||||
|
|
||||||
@@ -61,7 +82,7 @@ func (mc *MQTTClient) Type() string {
|
|||||||
|
|
||||||
func (mc *MQTTClient) Start(ctx context.Context) error {
|
func (mc *MQTTClient) Start(ctx context.Context) error {
|
||||||
mc.logger.Debug("running")
|
mc.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("mqtt.client unable to get router from context")
|
return errors.New("mqtt.client unable to get router from context")
|
||||||
@@ -101,7 +122,7 @@ func (mc *MQTTClient) Start(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (mc *MQTTClient) Output(ctx context.Context, payload any) error {
|
func (mc *MQTTClient) Output(ctx context.Context, payload any) error {
|
||||||
payloadMessage, ok := payload.(mqtt.Message)
|
payloadMessage, ok := common.GetAnyAs[mqtt.Message](payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("mqtt.client is only able to output a MQTTMessage")
|
return errors.New("mqtt.client is only able to output a MQTTMessage")
|
||||||
|
|||||||
@@ -5,16 +5,17 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
"github.com/jwetzell/showbridge-go/internal/route"
|
|
||||||
"github.com/nats-io/nats.go"
|
"github.com/nats-io/nats.go"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NATSClient struct {
|
type NATSClient struct {
|
||||||
config config.ModuleConfig
|
config config.ModuleConfig
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
router route.RouteIO
|
router common.RouteIO
|
||||||
URL string
|
URL string
|
||||||
Subject string
|
Subject string
|
||||||
client *nats.Conn
|
client *nats.Conn
|
||||||
@@ -24,8 +25,24 @@ type NATSClient struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "nats.client",
|
Type: "nats.client",
|
||||||
New: func(config config.ModuleConfig) (Module, error) {
|
Title: "NATS Client",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"url": {
|
||||||
|
Title: "NATS Server URL",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"subject": {
|
||||||
|
Title: "Subject",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"url", "subject"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
urlString, err := params.GetString("url")
|
urlString, err := params.GetString("url")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -53,7 +70,7 @@ func (nc *NATSClient) Type() string {
|
|||||||
|
|
||||||
func (nc *NATSClient) Start(ctx context.Context) error {
|
func (nc *NATSClient) Start(ctx context.Context) error {
|
||||||
nc.logger.Debug("running")
|
nc.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("nats.client unable to get router from context")
|
return errors.New("nats.client unable to get router from context")
|
||||||
@@ -94,7 +111,7 @@ func (nc *NATSClient) Start(ctx context.Context) error {
|
|||||||
|
|
||||||
func (nc *NATSClient) Output(ctx context.Context, payload any) error {
|
func (nc *NATSClient) Output(ctx context.Context, payload any) error {
|
||||||
|
|
||||||
payloadMessage, ok := payload.(processor.NATSMessage)
|
payloadMessage, ok := common.GetAnyAs[processor.NATSMessage](payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("nats.client is only able to output NATSMessage")
|
return errors.New("nats.client is only able to output NATSMessage")
|
||||||
|
|||||||
@@ -2,14 +2,16 @@ package module
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/route"
|
|
||||||
"github.com/nats-io/nats-server/v2/server"
|
"github.com/nats-io/nats-server/v2/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,7 +20,7 @@ type NATSServer struct {
|
|||||||
ctx context.Context
|
ctx context.Context
|
||||||
Ip string
|
Ip string
|
||||||
Port int
|
Port int
|
||||||
router route.RouteIO
|
router common.RouteIO
|
||||||
server *server.Server
|
server *server.Server
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
@@ -26,8 +28,28 @@ type NATSServer struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "nats.server",
|
Type: "nats.server",
|
||||||
New: func(moduleConfig config.ModuleConfig) (Module, error) {
|
Title: "NATS Server",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"ip": {
|
||||||
|
Title: "IP",
|
||||||
|
Type: "string",
|
||||||
|
Default: json.RawMessage(`"0.0.0.0"`),
|
||||||
|
},
|
||||||
|
"port": {
|
||||||
|
Title: "Port",
|
||||||
|
Type: "integer",
|
||||||
|
Minimum: jsonschema.Ptr[float64](1024),
|
||||||
|
Maximum: jsonschema.Ptr[float64](65535),
|
||||||
|
Default: json.RawMessage(`4222`),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(moduleConfig config.ModuleConfig) (common.Module, error) {
|
||||||
params := moduleConfig.Params
|
params := moduleConfig.Params
|
||||||
portNum, err := params.GetInt("port")
|
portNum, err := params.GetInt("port")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -66,7 +88,7 @@ func (ns *NATSServer) Type() string {
|
|||||||
|
|
||||||
func (ns *NATSServer) Start(ctx context.Context) error {
|
func (ns *NATSServer) Start(ctx context.Context) error {
|
||||||
ns.logger.Debug("running")
|
ns.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("nats.server unable to get router from context")
|
return errors.New("nats.server unable to get router from context")
|
||||||
@@ -102,10 +124,6 @@ func (ns *NATSServer) Start(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ns *NATSServer) Output(ctx context.Context, payload any) error {
|
|
||||||
return errors.ErrUnsupported
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ns *NATSServer) Stop() {
|
func (ns *NATSServer) Stop() {
|
||||||
ns.cancel()
|
ns.cancel()
|
||||||
if ns.server != nil {
|
if ns.server != nil {
|
||||||
|
|||||||
@@ -3,21 +3,20 @@ package module
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jwetzell/psn-go"
|
"github.com/jwetzell/psn-go"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/route"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type PSNClient struct {
|
type PSNClient struct {
|
||||||
config config.ModuleConfig
|
config config.ModuleConfig
|
||||||
conn *net.UDPConn
|
conn *net.UDPConn
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
router route.RouteIO
|
router common.RouteIO
|
||||||
decoder *psn.Decoder
|
decoder *psn.Decoder
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
@@ -25,9 +24,9 @@ type PSNClient struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "psn.client",
|
Type: "psn.client",
|
||||||
New: func(config config.ModuleConfig) (Module, error) {
|
Title: "PosiStageNet Client",
|
||||||
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
return &PSNClient{config: config, decoder: psn.NewDecoder(), logger: CreateLogger(config)}, nil
|
return &PSNClient{config: config, decoder: psn.NewDecoder(), logger: CreateLogger(config)}, nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -43,7 +42,7 @@ func (pc *PSNClient) Type() string {
|
|||||||
|
|
||||||
func (pc *PSNClient) Start(ctx context.Context) error {
|
func (pc *PSNClient) Start(ctx context.Context) error {
|
||||||
pc.logger.Debug("running")
|
pc.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("psn.client unable to get router from context")
|
return errors.New("psn.client unable to get router from context")
|
||||||
@@ -105,10 +104,6 @@ func (pc *PSNClient) Start(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *PSNClient) Output(ctx context.Context, payload any) error {
|
|
||||||
return fmt.Errorf("psn.client output is not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pc *PSNClient) Stop() {
|
func (pc *PSNClient) Stop() {
|
||||||
pc.cancel()
|
pc.cancel()
|
||||||
}
|
}
|
||||||
|
|||||||
126
internal/module/redis-client.go
Normal file
126
internal/module/redis-client.go
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
package module
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RedisClient struct {
|
||||||
|
config config.ModuleConfig
|
||||||
|
ctx context.Context
|
||||||
|
router common.RouteIO
|
||||||
|
Host string
|
||||||
|
Port uint16
|
||||||
|
client *redis.Client
|
||||||
|
logger *slog.Logger
|
||||||
|
cancel context.CancelFunc
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterModule(ModuleRegistration{
|
||||||
|
Type: "redis.client",
|
||||||
|
Title: "Redis Client",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"host": {
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"port": {
|
||||||
|
Type: "integer",
|
||||||
|
Minimum: jsonschema.Ptr[float64](1),
|
||||||
|
Maximum: jsonschema.Ptr[float64](65535),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"host", "port"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
|
params := config.Params
|
||||||
|
hostString, err := params.GetString("host")
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("redis.client host error: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
portInt, err := params.GetInt("port")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("redis.client port error: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return &RedisClient{config: config, Host: hostString, Port: uint16(portInt), logger: CreateLogger(config)}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc *RedisClient) Id() string {
|
||||||
|
return rc.config.Id
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc *RedisClient) Type() string {
|
||||||
|
return rc.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc *RedisClient) Printf(ctx context.Context, format string, v ...interface{}) {
|
||||||
|
msg := fmt.Sprintf(format, v...)
|
||||||
|
rc.logger.Debug(msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc *RedisClient) Start(ctx context.Context) error {
|
||||||
|
redis.SetLogger(rc)
|
||||||
|
rc.logger.Debug("running")
|
||||||
|
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return errors.New("redis.client unable to get router from context")
|
||||||
|
}
|
||||||
|
|
||||||
|
rc.router = router
|
||||||
|
moduleContext, cancel := context.WithCancel(ctx)
|
||||||
|
rc.ctx = moduleContext
|
||||||
|
rc.cancel = cancel
|
||||||
|
|
||||||
|
client := redis.NewClient(&redis.Options{
|
||||||
|
Addr: fmt.Sprintf("%s:%d", rc.Host, rc.Port),
|
||||||
|
Password: "",
|
||||||
|
DB: 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
rc.client = client
|
||||||
|
|
||||||
|
defer client.Close()
|
||||||
|
|
||||||
|
<-rc.ctx.Done()
|
||||||
|
rc.logger.Debug("done")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc *RedisClient) Stop() {
|
||||||
|
rc.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc *RedisClient) Get(key string) (any, error) {
|
||||||
|
if rc.client != nil {
|
||||||
|
val, err := rc.client.Get(rc.ctx, key).Result()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
return nil, errors.New("redis.client not setup")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc *RedisClient) Set(key string, value any) error {
|
||||||
|
if rc.client != nil {
|
||||||
|
status := rc.client.Set(rc.ctx, key, value, 0)
|
||||||
|
return status.Err()
|
||||||
|
}
|
||||||
|
return errors.New("redis.client not setup")
|
||||||
|
}
|
||||||
@@ -9,16 +9,17 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/framer"
|
"github.com/jwetzell/showbridge-go/internal/framer"
|
||||||
"github.com/jwetzell/showbridge-go/internal/route"
|
|
||||||
"go.bug.st/serial"
|
"go.bug.st/serial"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SerialClient struct {
|
type SerialClient struct {
|
||||||
config config.ModuleConfig
|
config config.ModuleConfig
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
router route.RouteIO
|
router common.RouteIO
|
||||||
Port string
|
Port string
|
||||||
Framer framer.Framer
|
Framer framer.Framer
|
||||||
Mode *serial.Mode
|
Mode *serial.Mode
|
||||||
@@ -29,8 +30,24 @@ type SerialClient struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "serial.client",
|
Type: "serial.client",
|
||||||
New: func(config config.ModuleConfig) (Module, error) {
|
Title: "Serial Client",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"port": {
|
||||||
|
Title: "Port",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"baudRate": {
|
||||||
|
Title: "Baud Rate",
|
||||||
|
Type: "integer",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"port", "baudRate"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
portString, err := params.GetString("port")
|
portString, err := params.GetString("port")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -84,7 +101,7 @@ func (sc *SerialClient) SetupPort() error {
|
|||||||
|
|
||||||
func (sc *SerialClient) Start(ctx context.Context) error {
|
func (sc *SerialClient) Start(ctx context.Context) error {
|
||||||
sc.logger.Debug("running")
|
sc.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("serial.client unable to get router from context")
|
return errors.New("serial.client unable to get router from context")
|
||||||
@@ -156,10 +173,10 @@ func (sc *SerialClient) Start(ctx context.Context) error {
|
|||||||
|
|
||||||
func (sc *SerialClient) Output(ctx context.Context, payload any) error {
|
func (sc *SerialClient) Output(ctx context.Context, payload any) error {
|
||||||
|
|
||||||
payloadBytes, ok := payload.([]byte)
|
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("serial.client can only ouptut bytes")
|
return errors.New("serial.client can only output bytes")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := sc.port.Write(sc.Framer.Encode(payloadBytes))
|
_, err := sc.port.Write(sc.Framer.Encode(payloadBytes))
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package module
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -14,15 +15,16 @@ import (
|
|||||||
"github.com/emiago/diago/media"
|
"github.com/emiago/diago/media"
|
||||||
"github.com/emiago/sipgo"
|
"github.com/emiago/sipgo"
|
||||||
"github.com/emiago/sipgo/sip"
|
"github.com/emiago/sipgo/sip"
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
"github.com/jwetzell/showbridge-go/internal/route"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type SIPCallServer struct {
|
type SIPCallServer struct {
|
||||||
config config.ModuleConfig
|
config config.ModuleConfig
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
router route.RouteIO
|
router common.RouteIO
|
||||||
IP string
|
IP string
|
||||||
Port int
|
Port int
|
||||||
Transport string
|
Transport string
|
||||||
@@ -45,8 +47,39 @@ type sipCallContextKey string
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "sip.call.server",
|
Type: "sip.call.server",
|
||||||
New: func(moduleConfig config.ModuleConfig) (Module, error) {
|
Title: "SIP Call Server",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"ip": {
|
||||||
|
Title: "IP",
|
||||||
|
Type: "string",
|
||||||
|
Default: json.RawMessage(`"0.0.0.0"`),
|
||||||
|
},
|
||||||
|
"port": {
|
||||||
|
Title: "Port",
|
||||||
|
Type: "integer",
|
||||||
|
Minimum: jsonschema.Ptr[float64](1024),
|
||||||
|
Maximum: jsonschema.Ptr[float64](65535),
|
||||||
|
Default: json.RawMessage(`5060`),
|
||||||
|
},
|
||||||
|
"transport": {
|
||||||
|
Title: "Transport",
|
||||||
|
Type: "string",
|
||||||
|
Enum: []any{"udp", "tcp", "ws", "udp4", "tcp4"},
|
||||||
|
Default: json.RawMessage(`"udp"`),
|
||||||
|
},
|
||||||
|
"userAgent": {
|
||||||
|
Title: "User Agent",
|
||||||
|
Type: "string",
|
||||||
|
Default: json.RawMessage(`"showbridge"`),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(moduleConfig config.ModuleConfig) (common.Module, error) {
|
||||||
params := moduleConfig.Params
|
params := moduleConfig.Params
|
||||||
portNum, err := params.GetInt("port")
|
portNum, err := params.GetInt("port")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -100,7 +133,7 @@ func (scs *SIPCallServer) Type() string {
|
|||||||
|
|
||||||
func (scs *SIPCallServer) Start(ctx context.Context) error {
|
func (scs *SIPCallServer) Start(ctx context.Context) error {
|
||||||
scs.logger.Debug("running")
|
scs.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("sip.call.server unable to get router from context")
|
return errors.New("sip.call.server unable to get router from context")
|
||||||
@@ -173,7 +206,7 @@ func (scs *SIPCallServer) Output(ctx context.Context, payload any) error {
|
|||||||
return errors.New("sip.call.server inDialog already ended")
|
return errors.New("sip.call.server inDialog already ended")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadDTMFResponse, ok := payload.(processor.SipDTMFResponse)
|
payloadDTMFResponse, ok := common.GetAnyAs[processor.SipDTMFResponse](payload)
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
dtmfWriter := call.inDialog.AudioWriterDTMF()
|
dtmfWriter := call.inDialog.AudioWriterDTMF()
|
||||||
@@ -189,7 +222,7 @@ func (scs *SIPCallServer) Output(ctx context.Context, payload any) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadAudioFileResponse, ok := payload.(processor.SipAudioFileResponse)
|
payloadAudioFileResponse, ok := common.GetAnyAs[processor.SipAudioFileResponse](payload)
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
audioFile, err := os.Open(payloadAudioFileResponse.AudioFile)
|
audioFile, err := os.Open(payloadAudioFileResponse.AudioFile)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package module
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -15,15 +16,16 @@ import (
|
|||||||
"github.com/emiago/diago/media"
|
"github.com/emiago/diago/media"
|
||||||
"github.com/emiago/sipgo"
|
"github.com/emiago/sipgo"
|
||||||
"github.com/emiago/sipgo/sip"
|
"github.com/emiago/sipgo/sip"
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
"github.com/jwetzell/showbridge-go/internal/route"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type SIPDTMFServer struct {
|
type SIPDTMFServer struct {
|
||||||
config config.ModuleConfig
|
config config.ModuleConfig
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
router route.RouteIO
|
router common.RouteIO
|
||||||
IP string
|
IP string
|
||||||
Port int
|
Port int
|
||||||
Transport string
|
Transport string
|
||||||
@@ -45,8 +47,45 @@ type SIPDTMFCall struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "sip.dtmf.server",
|
Type: "sip.dtmf.server",
|
||||||
New: func(moduleConfig config.ModuleConfig) (Module, error) {
|
Title: "SIP DTMF Server",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"ip": {
|
||||||
|
Title: "IP",
|
||||||
|
Type: "string",
|
||||||
|
Default: json.RawMessage(`"0.0.0.0"`),
|
||||||
|
},
|
||||||
|
"port": {
|
||||||
|
Title: "Port",
|
||||||
|
Type: "integer",
|
||||||
|
Minimum: jsonschema.Ptr[float64](1024),
|
||||||
|
Maximum: jsonschema.Ptr[float64](65535),
|
||||||
|
Default: json.RawMessage(`5060`),
|
||||||
|
},
|
||||||
|
"transport": {
|
||||||
|
Title: "Transport",
|
||||||
|
Type: "string",
|
||||||
|
Enum: []any{"udp", "tcp", "ws", "udp4", "tcp4"},
|
||||||
|
Default: json.RawMessage(`"udp"`),
|
||||||
|
},
|
||||||
|
"userAgent": {
|
||||||
|
Title: "User Agent",
|
||||||
|
Type: "string",
|
||||||
|
Default: json.RawMessage(`"showbridge"`),
|
||||||
|
},
|
||||||
|
"separator": {
|
||||||
|
Title: "DTMF Separator",
|
||||||
|
Type: "string",
|
||||||
|
MinLength: jsonschema.Ptr(1),
|
||||||
|
MaxLength: jsonschema.Ptr(1),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"separator"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(moduleConfig config.ModuleConfig) (common.Module, error) {
|
||||||
params := moduleConfig.Params
|
params := moduleConfig.Params
|
||||||
|
|
||||||
portNum, err := params.GetInt("port")
|
portNum, err := params.GetInt("port")
|
||||||
@@ -113,7 +152,7 @@ func (sds *SIPDTMFServer) Type() string {
|
|||||||
|
|
||||||
func (sds *SIPDTMFServer) Start(ctx context.Context) error {
|
func (sds *SIPDTMFServer) Start(ctx context.Context) error {
|
||||||
sds.logger.Debug("running")
|
sds.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("sip.dtmf.server unable to get router from context")
|
return errors.New("sip.dtmf.server unable to get router from context")
|
||||||
@@ -199,7 +238,7 @@ func (sds *SIPDTMFServer) Output(ctx context.Context, payload any) error {
|
|||||||
return errors.New("sip.dtmf.server inDialog already ended")
|
return errors.New("sip.dtmf.server inDialog already ended")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadDTMFResponse, ok := payload.(processor.SipDTMFResponse)
|
payloadDTMFResponse, ok := common.GetAnyAs[processor.SipDTMFResponse](payload)
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
dtmfWriter := call.inDialog.AudioWriterDTMF()
|
dtmfWriter := call.inDialog.AudioWriterDTMF()
|
||||||
@@ -216,7 +255,7 @@ func (sds *SIPDTMFServer) Output(ctx context.Context, payload any) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadAudioFileResponse, ok := payload.(processor.SipAudioFileResponse)
|
payloadAudioFileResponse, ok := common.GetAnyAs[processor.SipAudioFileResponse](payload)
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
audioFile, err := os.Open(payloadAudioFileResponse.AudioFile)
|
audioFile, err := os.Open(payloadAudioFileResponse.AudioFile)
|
||||||
|
|||||||
@@ -8,9 +8,10 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/framer"
|
"github.com/jwetzell/showbridge-go/internal/framer"
|
||||||
"github.com/jwetzell/showbridge-go/internal/route"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type TCPClient struct {
|
type TCPClient struct {
|
||||||
@@ -18,7 +19,7 @@ type TCPClient struct {
|
|||||||
framer framer.Framer
|
framer framer.Framer
|
||||||
conn *net.TCPConn
|
conn *net.TCPConn
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
router route.RouteIO
|
router common.RouteIO
|
||||||
Addr *net.TCPAddr
|
Addr *net.TCPAddr
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
@@ -26,8 +27,31 @@ type TCPClient struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "net.tcp.client",
|
Type: "net.tcp.client",
|
||||||
New: func(config config.ModuleConfig) (Module, error) {
|
Title: "TCP Client",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"host": {
|
||||||
|
Title: "Host",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"port": {
|
||||||
|
Title: "Port",
|
||||||
|
Type: "integer",
|
||||||
|
Minimum: jsonschema.Ptr[float64](1),
|
||||||
|
Maximum: jsonschema.Ptr[float64](65535),
|
||||||
|
},
|
||||||
|
"framing": {
|
||||||
|
Title: "Framing Method",
|
||||||
|
Type: "string",
|
||||||
|
Enum: []any{"LF", "CR", "CRLF", "SLIP", "RAW"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"host", "port", "framing"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
hostString, err := params.GetString("host")
|
hostString, err := params.GetString("host")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -69,7 +93,7 @@ func (tc *TCPClient) Type() string {
|
|||||||
|
|
||||||
func (tc *TCPClient) Start(ctx context.Context) error {
|
func (tc *TCPClient) Start(ctx context.Context) error {
|
||||||
tc.logger.Debug("running")
|
tc.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("net.tcp.client unable to get router from context")
|
return errors.New("net.tcp.client unable to get router from context")
|
||||||
@@ -152,7 +176,7 @@ func (tc *TCPClient) Output(ctx context.Context, payload any) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
payloadBytes, ok := payload.([]byte)
|
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("net.tcp.client is only able to output bytes")
|
return errors.New("net.tcp.client is only able to output bytes")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package module
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
@@ -11,9 +12,10 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/framer"
|
"github.com/jwetzell/showbridge-go/internal/framer"
|
||||||
"github.com/jwetzell/showbridge-go/internal/route"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type TCPServer struct {
|
type TCPServer struct {
|
||||||
@@ -21,7 +23,7 @@ type TCPServer struct {
|
|||||||
Addr *net.TCPAddr
|
Addr *net.TCPAddr
|
||||||
Framer framer.Framer
|
Framer framer.Framer
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
router route.RouteIO
|
router common.RouteIO
|
||||||
quit chan interface{}
|
quit chan interface{}
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
connections []*net.TCPConn
|
connections []*net.TCPConn
|
||||||
@@ -32,8 +34,32 @@ type TCPServer struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "net.tcp.server",
|
Type: "net.tcp.server",
|
||||||
New: func(moduleConfig config.ModuleConfig) (Module, error) {
|
Title: "TCP Server",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"ip": {
|
||||||
|
Title: "IP",
|
||||||
|
Type: "string",
|
||||||
|
Default: json.RawMessage(`"0.0.0.0"`),
|
||||||
|
},
|
||||||
|
"port": {
|
||||||
|
Title: "Port",
|
||||||
|
Type: "integer",
|
||||||
|
Minimum: jsonschema.Ptr[float64](1024),
|
||||||
|
Maximum: jsonschema.Ptr[float64](65535),
|
||||||
|
},
|
||||||
|
"framing": {
|
||||||
|
Title: "Framing Method",
|
||||||
|
Type: "string",
|
||||||
|
Enum: []any{"LF", "CR", "CRLF", "SLIP", "RAW"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"port", "framing"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(moduleConfig config.ModuleConfig) (common.Module, error) {
|
||||||
params := moduleConfig.Params
|
params := moduleConfig.Params
|
||||||
portNum, err := params.GetInt("port")
|
portNum, err := params.GetInt("port")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -140,7 +166,13 @@ ClientRead:
|
|||||||
messages := ts.Framer.Decode(buffer[0:byteCount])
|
messages := ts.Framer.Decode(buffer[0:byteCount])
|
||||||
for _, message := range messages {
|
for _, message := range messages {
|
||||||
if ts.router != nil {
|
if ts.router != nil {
|
||||||
ts.router.HandleInput(ts.ctx, ts.Id(), message)
|
senderAddr, ok := client.RemoteAddr().(*net.TCPAddr)
|
||||||
|
if ok {
|
||||||
|
senderCtx := context.WithValue(ts.ctx, common.SenderContextKey, senderAddr)
|
||||||
|
ts.router.HandleInput(senderCtx, ts.Id(), message)
|
||||||
|
} else {
|
||||||
|
ts.router.HandleInput(ts.ctx, ts.Id(), message)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ts.logger.Error("input received but no router is configured")
|
ts.logger.Error("input received but no router is configured")
|
||||||
}
|
}
|
||||||
@@ -153,7 +185,7 @@ ClientRead:
|
|||||||
|
|
||||||
func (ts *TCPServer) Start(ctx context.Context) error {
|
func (ts *TCPServer) Start(ctx context.Context) error {
|
||||||
ts.logger.Debug("running")
|
ts.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("net.tcp.server unable to get router from context")
|
return errors.New("net.tcp.server unable to get router from context")
|
||||||
@@ -200,7 +232,7 @@ AcceptLoop:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TCPServer) Output(ctx context.Context, payload any) error {
|
func (ts *TCPServer) Output(ctx context.Context, payload any) error {
|
||||||
payloadBytes, ok := payload.([]byte)
|
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("net.tcp.server is only able to output bytes")
|
return errors.New("net.tcp.server is only able to output bytes")
|
||||||
|
|||||||
87
internal/module/test/db-sqlite_test.go
Normal file
87
internal/module/test/db-sqlite_test.go
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
package module_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/module"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDbSqliteFromRegistry(t *testing.T) {
|
||||||
|
registration, ok := module.ModuleRegistry["db.sqlite"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("db.sqlite module not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||||
|
Id: "test",
|
||||||
|
Type: "db.sqlite",
|
||||||
|
Params: map[string]any{
|
||||||
|
"dsn": ":memory:",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create db.sqlite module: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if moduleInstance.Id() != "test" {
|
||||||
|
t.Fatalf("db.sqlite module has wrong id: %s", moduleInstance.Id())
|
||||||
|
}
|
||||||
|
|
||||||
|
if moduleInstance.Type() != "db.sqlite" {
|
||||||
|
t.Fatalf("db.sqlite module has wrong type: %s", moduleInstance.Type())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadDbSqlite(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
params map[string]any
|
||||||
|
errorString string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "no dsn param",
|
||||||
|
params: map[string]any{},
|
||||||
|
errorString: "db.sqlite dsn error: not found",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "non-string dsn",
|
||||||
|
params: map[string]any{"dsn": 123},
|
||||||
|
errorString: "db.sqlite dsn error: not a string",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
|
registration, ok := module.ModuleRegistry["db.sqlite"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("db.sqlite module not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||||
|
Id: "test",
|
||||||
|
Type: "db.sqlite",
|
||||||
|
Params: test.params,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
if test.errorString != err.Error() {
|
||||||
|
t.Fatalf("db.sqlite got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = moduleInstance.Start(t.Context())
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("db.sqlite expected to fail")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err.Error() != test.errorString {
|
||||||
|
t.Fatalf("db.sqlite got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
package module_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/module"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestHTTPClientFromRegistry(t *testing.T) {
|
|
||||||
registration, ok := module.ModuleRegistry["http.client"]
|
|
||||||
if !ok {
|
|
||||||
t.Fatalf("http.client module not registered")
|
|
||||||
}
|
|
||||||
|
|
||||||
moduleInstance, err := registration.New(config.ModuleConfig{
|
|
||||||
Id: "test",
|
|
||||||
Type: "http.client",
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to create http.client module: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if moduleInstance.Id() != "test" {
|
|
||||||
t.Fatalf("http.client module has wrong id: %s", moduleInstance.Id())
|
|
||||||
}
|
|
||||||
|
|
||||||
if moduleInstance.Type() != "http.client" {
|
|
||||||
t.Fatalf("http.client module has wrong type: %s", moduleInstance.Type())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBadHTTPClient(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
params map[string]any
|
|
||||||
errorString string
|
|
||||||
}{}
|
|
||||||
|
|
||||||
for _, test := range tests {
|
|
||||||
t.Run(test.name, func(t *testing.T) {
|
|
||||||
|
|
||||||
registration, ok := module.ModuleRegistry["http.client"]
|
|
||||||
if !ok {
|
|
||||||
t.Fatalf("http.client module not registered")
|
|
||||||
}
|
|
||||||
|
|
||||||
moduleInstance, err := registration.New(config.ModuleConfig{
|
|
||||||
Id: "test",
|
|
||||||
Type: "http.client",
|
|
||||||
Params: test.params,
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
if test.errorString != err.Error() {
|
|
||||||
t.Fatalf("http.client got error '%s', expected '%s'", err.Error(), test.errorString)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = moduleInstance.Start(t.Context())
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
t.Fatalf("http.client expected to fail")
|
|
||||||
}
|
|
||||||
|
|
||||||
if err.Error() != test.errorString {
|
|
||||||
t.Fatalf("http.client got error '%s', expected '%s'", err.Error(), test.errorString)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,7 +17,7 @@ func TestHTTPServerFromRegistry(t *testing.T) {
|
|||||||
Id: "test",
|
Id: "test",
|
||||||
Type: "http.server",
|
Type: "http.server",
|
||||||
Params: map[string]any{
|
Params: map[string]any{
|
||||||
"port": 3000.0,
|
"port": 3000,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,35 +1,14 @@
|
|||||||
package module_test
|
package module_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/module"
|
"github.com/jwetzell/showbridge-go/internal/module"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TestModule struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *TestModule) Output(ctx context.Context, payload any) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *TestModule) Start(ctx context.Context) error {
|
|
||||||
<-ctx.Done()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *TestModule) Stop() {}
|
|
||||||
|
|
||||||
func (m *TestModule) Type() string {
|
|
||||||
return "module.test"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *TestModule) Id() string {
|
|
||||||
return "test"
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestModuleBadRegistrationNoType(t *testing.T) {
|
func TestModuleBadRegistrationNoType(t *testing.T) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r == nil {
|
if r := recover(); r == nil {
|
||||||
@@ -39,8 +18,8 @@ func TestModuleBadRegistrationNoType(t *testing.T) {
|
|||||||
|
|
||||||
module.RegisterModule(module.ModuleRegistration{
|
module.RegisterModule(module.ModuleRegistration{
|
||||||
Type: "",
|
Type: "",
|
||||||
New: func(config config.ModuleConfig) (module.Module, error) {
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
return &TestModule{}, nil
|
return &test.TestModule{}, nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -67,15 +46,15 @@ func TestModuleBadRegistrationExistingType(t *testing.T) {
|
|||||||
|
|
||||||
module.RegisterModule(module.ModuleRegistration{
|
module.RegisterModule(module.ModuleRegistration{
|
||||||
Type: "module.test",
|
Type: "module.test",
|
||||||
New: func(config config.ModuleConfig) (module.Module, error) {
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
return &TestModule{}, nil
|
return &test.TestModule{}, nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
module.RegisterModule(module.ModuleRegistration{
|
module.RegisterModule(module.ModuleRegistration{
|
||||||
Type: "module.test",
|
Type: "module.test",
|
||||||
New: func(config config.ModuleConfig) (module.Module, error) {
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
return &TestModule{}, nil
|
return &test.TestModule{}, nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
108
internal/module/test/redis-client_test.go
Normal file
108
internal/module/test/redis-client_test.go
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
package module_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/module"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRedisClientFromRegistry(t *testing.T) {
|
||||||
|
registration, ok := module.ModuleRegistry["redis.client"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("redis.client module not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||||
|
Id: "test",
|
||||||
|
Type: "redis.client",
|
||||||
|
Params: map[string]any{
|
||||||
|
"host": "localhost",
|
||||||
|
"port": 6379,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create redis.client module: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if moduleInstance.Id() != "test" {
|
||||||
|
t.Fatalf("redis.client module has wrong id: %s", moduleInstance.Id())
|
||||||
|
}
|
||||||
|
|
||||||
|
if moduleInstance.Type() != "redis.client" {
|
||||||
|
t.Fatalf("redis.client module has wrong type: %s", moduleInstance.Type())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBadRedisClient(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
params map[string]any
|
||||||
|
errorString string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "no host param",
|
||||||
|
params: map[string]any{
|
||||||
|
"port": 6379,
|
||||||
|
},
|
||||||
|
errorString: "redis.client host error: not found",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "non-string host",
|
||||||
|
params: map[string]any{
|
||||||
|
"host": 123,
|
||||||
|
"port": 6379,
|
||||||
|
},
|
||||||
|
errorString: "redis.client host error: not a string",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "no port param",
|
||||||
|
params: map[string]any{
|
||||||
|
"host": "localhost",
|
||||||
|
},
|
||||||
|
errorString: "redis.client port error: not found",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "non-number port",
|
||||||
|
params: map[string]any{
|
||||||
|
"host": "localhost",
|
||||||
|
"port": "6379",
|
||||||
|
},
|
||||||
|
errorString: "redis.client port error: not a number",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
|
registration, ok := module.ModuleRegistry["redis.client"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("redis.client module not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||||
|
Id: "test",
|
||||||
|
Type: "redis.client",
|
||||||
|
Params: test.params,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
if test.errorString != err.Error() {
|
||||||
|
t.Fatalf("redis.client got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = moduleInstance.Start(t.Context())
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("redis.client expected to fail")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err.Error() != test.errorString {
|
||||||
|
t.Fatalf("redis.client got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,7 +19,7 @@ func TestSerialClientFromRegistry(t *testing.T) {
|
|||||||
Params: map[string]any{
|
Params: map[string]any{
|
||||||
"port": "/dev/ttyUSB0",
|
"port": "/dev/ttyUSB0",
|
||||||
"framing": "LF",
|
"framing": "LF",
|
||||||
"baudRate": 9600.0,
|
"baudRate": 9600,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func TestTCPClientFromRegistry(t *testing.T) {
|
|||||||
Type: "net.tcp.client",
|
Type: "net.tcp.client",
|
||||||
Params: map[string]any{
|
Params: map[string]any{
|
||||||
"host": "localhost",
|
"host": "localhost",
|
||||||
"port": 8000.0,
|
"port": 8000,
|
||||||
"framing": "LF",
|
"framing": "LF",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -60,7 +60,7 @@ func TestBadTCPClient(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "no host param",
|
name: "no host param",
|
||||||
params: map[string]any{
|
params: map[string]any{
|
||||||
"port": 8000.0,
|
"port": 8000,
|
||||||
},
|
},
|
||||||
errorString: "net.tcp.client host error: not found",
|
errorString: "net.tcp.client host error: not found",
|
||||||
},
|
},
|
||||||
@@ -68,7 +68,7 @@ func TestBadTCPClient(t *testing.T) {
|
|||||||
name: "non-string host param",
|
name: "non-string host param",
|
||||||
params: map[string]any{
|
params: map[string]any{
|
||||||
"host": 123,
|
"host": 123,
|
||||||
"port": 8000.0,
|
"port": 8000,
|
||||||
},
|
},
|
||||||
errorString: "net.tcp.client host error: not a string",
|
errorString: "net.tcp.client host error: not a string",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func TestTCPServerFromRegistry(t *testing.T) {
|
|||||||
Id: "test",
|
Id: "test",
|
||||||
Type: "net.tcp.server",
|
Type: "net.tcp.server",
|
||||||
Params: map[string]any{
|
Params: map[string]any{
|
||||||
"port": 8000.0,
|
"port": 8000,
|
||||||
"framing": "LF",
|
"framing": "LF",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -59,14 +59,14 @@ func TestBadTCPServer(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "no framing param",
|
name: "no framing param",
|
||||||
params: map[string]any{
|
params: map[string]any{
|
||||||
"port": 8000.0,
|
"port": 8000,
|
||||||
},
|
},
|
||||||
errorString: "net.tcp.server framing error: not found",
|
errorString: "net.tcp.server framing error: not found",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "non-string framing param",
|
name: "non-string framing param",
|
||||||
params: map[string]any{
|
params: map[string]any{
|
||||||
"port": 8000.0,
|
"port": 8000,
|
||||||
"framing": 1,
|
"framing": 1,
|
||||||
},
|
},
|
||||||
errorString: "net.tcp.server framing error: not a string",
|
errorString: "net.tcp.server framing error: not a string",
|
||||||
@@ -74,7 +74,7 @@ func TestBadTCPServer(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "unkown framing method",
|
name: "unkown framing method",
|
||||||
params: map[string]any{
|
params: map[string]any{
|
||||||
"port": 8000.0,
|
"port": 8000,
|
||||||
"framing": "asdfasdfasdfasdflkj",
|
"framing": "asdfasdfasdfasdflkj",
|
||||||
},
|
},
|
||||||
errorString: "net.tcp.server unknown framing method: asdfasdfasdfasdflkj",
|
errorString: "net.tcp.server unknown framing method: asdfasdfasdfasdflkj",
|
||||||
@@ -82,7 +82,7 @@ func TestBadTCPServer(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "non-string ip param",
|
name: "non-string ip param",
|
||||||
params: map[string]any{
|
params: map[string]any{
|
||||||
"port": 8000.0,
|
"port": 8000,
|
||||||
"framing": "LF",
|
"framing": "LF",
|
||||||
"ip": 123,
|
"ip": 123,
|
||||||
},
|
},
|
||||||
@@ -92,7 +92,7 @@ func TestBadTCPServer(t *testing.T) {
|
|||||||
name: "invalid addr",
|
name: "invalid addr",
|
||||||
params: map[string]any{
|
params: map[string]any{
|
||||||
"ip": "127.0.0.",
|
"ip": "127.0.0.",
|
||||||
"port": 8000.0,
|
"port": 8000,
|
||||||
"framing": "LF",
|
"framing": "LF",
|
||||||
},
|
},
|
||||||
errorString: "lookup 127.0.0.: no such host",
|
errorString: "lookup 127.0.0.: no such host",
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func TestTimeIntervalFromRegistry(t *testing.T) {
|
|||||||
Id: "test",
|
Id: "test",
|
||||||
Type: "time.interval",
|
Type: "time.interval",
|
||||||
Params: map[string]any{
|
Params: map[string]any{
|
||||||
"duration": 1000.0,
|
"duration": 1000,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func TestTimeTimerFromRegistry(t *testing.T) {
|
|||||||
Id: "test",
|
Id: "test",
|
||||||
Type: "time.timer",
|
Type: "time.timer",
|
||||||
Params: map[string]any{
|
Params: map[string]any{
|
||||||
"duration": 1000.0,
|
"duration": 1000,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func TestUDPClientFromRegistry(t *testing.T) {
|
|||||||
Type: "net.udp.client",
|
Type: "net.udp.client",
|
||||||
Params: map[string]any{
|
Params: map[string]any{
|
||||||
"host": "localhost",
|
"host": "localhost",
|
||||||
"port": 8000.0,
|
"port": 8000,
|
||||||
"framing": "LF",
|
"framing": "LF",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -60,7 +60,7 @@ func TestBadUDPClient(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "no host param",
|
name: "no host param",
|
||||||
params: map[string]any{
|
params: map[string]any{
|
||||||
"port": 8000.0,
|
"port": 8000,
|
||||||
},
|
},
|
||||||
errorString: "net.udp.client host error: not found",
|
errorString: "net.udp.client host error: not found",
|
||||||
},
|
},
|
||||||
@@ -68,7 +68,7 @@ func TestBadUDPClient(t *testing.T) {
|
|||||||
name: "non-string host param",
|
name: "non-string host param",
|
||||||
params: map[string]any{
|
params: map[string]any{
|
||||||
"host": 123,
|
"host": 123,
|
||||||
"port": 8000.0,
|
"port": 8000,
|
||||||
},
|
},
|
||||||
errorString: "net.udp.client host error: not a string",
|
errorString: "net.udp.client host error: not a string",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func TestUDPMulticastFromRegistry(t *testing.T) {
|
|||||||
Type: "net.udp.multicast",
|
Type: "net.udp.multicast",
|
||||||
Params: map[string]any{
|
Params: map[string]any{
|
||||||
"ip": "236.10.10.10",
|
"ip": "236.10.10.10",
|
||||||
"port": 56565.0,
|
"port": 56565,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ func TestBadUDPMulticast(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "no ip param",
|
name: "no ip param",
|
||||||
params: map[string]any{
|
params: map[string]any{
|
||||||
"port": 8000.0,
|
"port": 8000,
|
||||||
},
|
},
|
||||||
errorString: "net.udp.multicast ip error: not found",
|
errorString: "net.udp.multicast ip error: not found",
|
||||||
},
|
},
|
||||||
@@ -67,7 +67,7 @@ func TestBadUDPMulticast(t *testing.T) {
|
|||||||
name: "non-string ip param",
|
name: "non-string ip param",
|
||||||
params: map[string]any{
|
params: map[string]any{
|
||||||
"ip": 123,
|
"ip": 123,
|
||||||
"port": 8000.0,
|
"port": 8000,
|
||||||
},
|
},
|
||||||
errorString: "net.udp.multicast ip error: not a string",
|
errorString: "net.udp.multicast ip error: not a string",
|
||||||
},
|
},
|
||||||
@@ -75,7 +75,7 @@ func TestBadUDPMulticast(t *testing.T) {
|
|||||||
name: "invalid addr",
|
name: "invalid addr",
|
||||||
params: map[string]any{
|
params: map[string]any{
|
||||||
"ip": "127.0.0.",
|
"ip": "127.0.0.",
|
||||||
"port": 8000.0,
|
"port": 8000,
|
||||||
},
|
},
|
||||||
errorString: "lookup 127.0.0.: no such host",
|
errorString: "lookup 127.0.0.: no such host",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func TestUDPServerFromRegistry(t *testing.T) {
|
|||||||
Id: "test",
|
Id: "test",
|
||||||
Type: "net.udp.server",
|
Type: "net.udp.server",
|
||||||
Params: map[string]any{
|
Params: map[string]any{
|
||||||
"port": 8000.0,
|
"port": 8000,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ func TestBadUDPServer(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "non-string ip param",
|
name: "non-string ip param",
|
||||||
params: map[string]any{
|
params: map[string]any{
|
||||||
"port": 8000.0,
|
"port": 8000,
|
||||||
"ip": 123,
|
"ip": 123,
|
||||||
},
|
},
|
||||||
errorString: "net.udp.server ip error: not a string",
|
errorString: "net.udp.server ip error: not a string",
|
||||||
@@ -63,7 +63,7 @@ func TestBadUDPServer(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "non-number bufferSize param",
|
name: "non-number bufferSize param",
|
||||||
params: map[string]any{
|
params: map[string]any{
|
||||||
"port": 8000.0,
|
"port": 8000,
|
||||||
"bufferSize": "1024",
|
"bufferSize": "1024",
|
||||||
},
|
},
|
||||||
errorString: "net.udp.server bufferSize error: not a number",
|
errorString: "net.udp.server bufferSize error: not a number",
|
||||||
@@ -72,7 +72,7 @@ func TestBadUDPServer(t *testing.T) {
|
|||||||
name: "invalid addr",
|
name: "invalid addr",
|
||||||
params: map[string]any{
|
params: map[string]any{
|
||||||
"ip": "127.0.0.",
|
"ip": "127.0.0.",
|
||||||
"port": 8000.0,
|
"port": 8000,
|
||||||
},
|
},
|
||||||
errorString: "lookup 127.0.0.: no such host",
|
errorString: "lookup 127.0.0.: no such host",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -7,15 +7,16 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/route"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type TimeInterval struct {
|
type TimeInterval struct {
|
||||||
config config.ModuleConfig
|
config config.ModuleConfig
|
||||||
Duration uint32
|
Duration uint32
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
router route.RouteIO
|
router common.RouteIO
|
||||||
ticker *time.Ticker
|
ticker *time.Ticker
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
@@ -23,8 +24,21 @@ type TimeInterval struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "time.interval",
|
Type: "time.interval",
|
||||||
New: func(config config.ModuleConfig) (Module, error) {
|
Title: "Interval",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"duration": {
|
||||||
|
Title: "Duration",
|
||||||
|
Type: "integer",
|
||||||
|
Description: "Interval duration in milliseconds",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"duration"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
|
|
||||||
durationInt, err := params.GetInt("duration")
|
durationInt, err := params.GetInt("duration")
|
||||||
@@ -46,7 +60,7 @@ func (i *TimeInterval) Type() string {
|
|||||||
|
|
||||||
func (i *TimeInterval) Start(ctx context.Context) error {
|
func (i *TimeInterval) Start(ctx context.Context) error {
|
||||||
i.logger.Debug("running")
|
i.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("time.interval unable to get router from context")
|
return errors.New("time.interval unable to get router from context")
|
||||||
@@ -74,11 +88,6 @@ func (i *TimeInterval) Start(ctx context.Context) error {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *TimeInterval) Output(ctx context.Context, payload any) error {
|
|
||||||
i.ticker.Reset(time.Millisecond * time.Duration(i.Duration))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *TimeInterval) Stop() {
|
func (i *TimeInterval) Stop() {
|
||||||
i.cancel()
|
i.cancel()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,15 +7,16 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/route"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type TimeTimer struct {
|
type TimeTimer struct {
|
||||||
config config.ModuleConfig
|
config config.ModuleConfig
|
||||||
Duration uint32
|
Duration uint32
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
router route.RouteIO
|
router common.RouteIO
|
||||||
timer *time.Timer
|
timer *time.Timer
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
@@ -23,8 +24,21 @@ type TimeTimer struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "time.timer",
|
Type: "time.timer",
|
||||||
New: func(config config.ModuleConfig) (Module, error) {
|
Title: "Timer",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"duration": {
|
||||||
|
Title: "Duration",
|
||||||
|
Type: "integer",
|
||||||
|
Description: "Interval duration in milliseconds",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"duration"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
|
|
||||||
durationNum, err := params.GetInt("duration")
|
durationNum, err := params.GetInt("duration")
|
||||||
@@ -47,7 +61,7 @@ func (t *TimeTimer) Type() string {
|
|||||||
|
|
||||||
func (t *TimeTimer) Start(ctx context.Context) error {
|
func (t *TimeTimer) Start(ctx context.Context) error {
|
||||||
t.logger.Debug("running")
|
t.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("net.tcp.client unable to get router from context")
|
return errors.New("net.tcp.client unable to get router from context")
|
||||||
@@ -73,11 +87,6 @@ func (t *TimeTimer) Start(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TimeTimer) Output(ctx context.Context, payload any) error {
|
|
||||||
t.timer.Reset(time.Millisecond * time.Duration(t.Duration))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *TimeTimer) Stop() {
|
func (t *TimeTimer) Stop() {
|
||||||
t.cancel()
|
t.cancel()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/route"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type UDPClient struct {
|
type UDPClient struct {
|
||||||
@@ -17,15 +18,33 @@ type UDPClient struct {
|
|||||||
Port uint16
|
Port uint16
|
||||||
conn *net.UDPConn
|
conn *net.UDPConn
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
router route.RouteIO
|
router common.RouteIO
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "net.udp.client",
|
Type: "net.udp.client",
|
||||||
New: func(config config.ModuleConfig) (Module, error) {
|
Title: "UDP Client",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"host": {
|
||||||
|
Title: "Host",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"port": {
|
||||||
|
Title: "Port",
|
||||||
|
Type: "integer",
|
||||||
|
Minimum: jsonschema.Ptr[float64](1),
|
||||||
|
Maximum: jsonschema.Ptr[float64](65535),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"host", "port"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(config config.ModuleConfig) (common.Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
hostString, err := params.GetString("host")
|
hostString, err := params.GetString("host")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -62,7 +81,7 @@ func (uc *UDPClient) SetupConn() error {
|
|||||||
|
|
||||||
func (uc *UDPClient) Start(ctx context.Context) error {
|
func (uc *UDPClient) Start(ctx context.Context) error {
|
||||||
uc.logger.Debug("running")
|
uc.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("net.udp.client unable to get router from context")
|
return errors.New("net.udp.client unable to get router from context")
|
||||||
@@ -87,7 +106,7 @@ func (uc *UDPClient) Start(ctx context.Context) error {
|
|||||||
|
|
||||||
func (uc *UDPClient) Output(ctx context.Context, payload any) error {
|
func (uc *UDPClient) Output(ctx context.Context, payload any) error {
|
||||||
|
|
||||||
payloadBytes, ok := payload.([]byte)
|
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("net.udp.client is only able to output bytes")
|
return errors.New("net.udp.client is only able to output bytes")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,15 +8,16 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/route"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type UDPMulticast struct {
|
type UDPMulticast struct {
|
||||||
config config.ModuleConfig
|
config config.ModuleConfig
|
||||||
conn *net.UDPConn
|
conn *net.UDPConn
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
router route.RouteIO
|
router common.RouteIO
|
||||||
Addr *net.UDPAddr
|
Addr *net.UDPAddr
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
@@ -24,8 +25,26 @@ type UDPMulticast struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "net.udp.multicast",
|
Type: "net.udp.multicast",
|
||||||
New: func(moduleConfig config.ModuleConfig) (Module, error) {
|
Title: "UDP Multicast",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"ip": {
|
||||||
|
Title: "IP",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"port": {
|
||||||
|
Title: "Port",
|
||||||
|
Type: "integer",
|
||||||
|
Minimum: jsonschema.Ptr[float64](1024),
|
||||||
|
Maximum: jsonschema.Ptr[float64](65535),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"ip", "port"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(moduleConfig config.ModuleConfig) (common.Module, error) {
|
||||||
params := moduleConfig.Params
|
params := moduleConfig.Params
|
||||||
ipString, err := params.GetString("ip")
|
ipString, err := params.GetString("ip")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -56,7 +75,7 @@ func (um *UDPMulticast) Type() string {
|
|||||||
|
|
||||||
func (um *UDPMulticast) Start(ctx context.Context) error {
|
func (um *UDPMulticast) Start(ctx context.Context) error {
|
||||||
um.logger.Debug("running")
|
um.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("net.udp.multicast unable to get router from context")
|
return errors.New("net.udp.multicast unable to get router from context")
|
||||||
@@ -108,7 +127,7 @@ func (um *UDPMulticast) Start(ctx context.Context) error {
|
|||||||
|
|
||||||
func (um *UDPMulticast) Output(ctx context.Context, payload any) error {
|
func (um *UDPMulticast) Output(ctx context.Context, payload any) error {
|
||||||
|
|
||||||
payloadBytes, ok := payload.([]byte)
|
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("net.udp.multicast can only output bytes")
|
return errors.New("net.udp.multicast can only output bytes")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,16 @@ package module
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/route"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type UDPServer struct {
|
type UDPServer struct {
|
||||||
@@ -17,15 +19,41 @@ type UDPServer struct {
|
|||||||
BufferSize int
|
BufferSize int
|
||||||
config config.ModuleConfig
|
config config.ModuleConfig
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
router route.RouteIO
|
router common.RouteIO
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "net.udp.server",
|
Type: "net.udp.server",
|
||||||
New: func(moduleConfig config.ModuleConfig) (Module, error) {
|
Title: "UDP Server",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"ip": {
|
||||||
|
Title: "IP",
|
||||||
|
Type: "string",
|
||||||
|
Default: json.RawMessage(`"0.0.0.0"`),
|
||||||
|
},
|
||||||
|
"port": {
|
||||||
|
Title: "Port",
|
||||||
|
Type: "integer",
|
||||||
|
Minimum: jsonschema.Ptr[float64](1024),
|
||||||
|
Maximum: jsonschema.Ptr[float64](65535),
|
||||||
|
},
|
||||||
|
"bufferSize": {
|
||||||
|
Title: "Buffer Size",
|
||||||
|
Type: "integer",
|
||||||
|
Minimum: jsonschema.Ptr[float64](1),
|
||||||
|
Maximum: jsonschema.Ptr[float64](65535),
|
||||||
|
Default: json.RawMessage("2048"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"port"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(moduleConfig config.ModuleConfig) (common.Module, error) {
|
||||||
params := moduleConfig.Params
|
params := moduleConfig.Params
|
||||||
portNum, err := params.GetInt("port")
|
portNum, err := params.GetInt("port")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -69,7 +97,7 @@ func (us *UDPServer) Type() string {
|
|||||||
|
|
||||||
func (us *UDPServer) Start(ctx context.Context) error {
|
func (us *UDPServer) Start(ctx context.Context) error {
|
||||||
us.logger.Debug("running")
|
us.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("net.udp.server unable to get router from context")
|
return errors.New("net.udp.server unable to get router from context")
|
||||||
@@ -96,7 +124,7 @@ func (us *UDPServer) Start(ctx context.Context) error {
|
|||||||
default:
|
default:
|
||||||
listener.SetDeadline(time.Now().Add(time.Millisecond * 200))
|
listener.SetDeadline(time.Now().Add(time.Millisecond * 200))
|
||||||
|
|
||||||
numBytes, _, err := listener.ReadFromUDP(buffer)
|
numBytes, senderAddr, err := listener.ReadFromUDP(buffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//NOTE(jwetzell) we hit deadline
|
//NOTE(jwetzell) we hit deadline
|
||||||
if opErr, ok := err.(*net.OpError); ok && opErr.Timeout() {
|
if opErr, ok := err.(*net.OpError); ok && opErr.Timeout() {
|
||||||
@@ -106,7 +134,8 @@ func (us *UDPServer) Start(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
message := buffer[:numBytes]
|
message := buffer[:numBytes]
|
||||||
if us.router != nil {
|
if us.router != nil {
|
||||||
us.router.HandleInput(us.ctx, us.Id(), message)
|
senderCtx := context.WithValue(us.ctx, common.SenderContextKey, senderAddr)
|
||||||
|
us.router.HandleInput(senderCtx, us.Id(), message)
|
||||||
} else {
|
} else {
|
||||||
us.logger.Error("input received but no router is configured")
|
us.logger.Error("input received but no router is configured")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/jwetzell/artnet-go"
|
"github.com/jwetzell/artnet-go"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -12,20 +13,25 @@ type ArtNetPacketDecode struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (apd *ArtNetPacketDecode) Process(ctx context.Context, payload any) (any, error) {
|
func (apd *ArtNetPacketDecode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
payloadBytes, ok := payload.([]byte)
|
payload := wrappedPayload.Payload
|
||||||
|
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("artnet.packet.decode processor only accepts a []byte")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("artnet.packet.decode processor only accepts a []byte")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadMessage, err := artnet.Decode(payloadBytes)
|
payloadMessage, err := artnet.Decode(payloadBytes)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return payloadMessage, nil
|
wrappedPayload.Payload = payloadMessage
|
||||||
|
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (apd *ArtNetPacketDecode) Type() string {
|
func (apd *ArtNetPacketDecode) Type() string {
|
||||||
@@ -34,7 +40,8 @@ func (apd *ArtNetPacketDecode) Type() string {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterProcessor(ProcessorRegistration{
|
RegisterProcessor(ProcessorRegistration{
|
||||||
Type: "artnet.packet.decode",
|
Type: "artnet.packet.decode",
|
||||||
|
Title: "Decode ArtNet Packet",
|
||||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
return &ArtNetPacketDecode{config: config}, nil
|
return &ArtNetPacketDecode{config: config}, nil
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/jwetzell/artnet-go"
|
"github.com/jwetzell/artnet-go"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -12,19 +13,24 @@ type ArtNetPacketEncode struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ape *ArtNetPacketEncode) Process(ctx context.Context, payload any) (any, error) {
|
func (ape *ArtNetPacketEncode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
payloadPacket, ok := payload.(artnet.ArtNetPacket)
|
payload := wrappedPayload.Payload
|
||||||
|
payloadPacket, ok := common.GetAnyAs[artnet.ArtNetPacket](payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("artnet.packet.encode processor only accepts an ArtNetPacket")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("artnet.packet.encode processor only accepts an ArtNetPacket")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadBytes, err := payloadPacket.MarshalBinary()
|
payloadBytes, err := payloadPacket.MarshalBinary()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return payloadBytes, nil
|
wrappedPayload.Payload = payloadBytes
|
||||||
|
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ape *ArtNetPacketEncode) Type() string {
|
func (ape *ArtNetPacketEncode) Type() string {
|
||||||
@@ -33,7 +39,8 @@ func (ape *ArtNetPacketEncode) Type() string {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterProcessor(ProcessorRegistration{
|
RegisterProcessor(ProcessorRegistration{
|
||||||
Type: "artnet.packet.encode",
|
Type: "artnet.packet.encode",
|
||||||
|
Title: "Encode ArtNet Packet",
|
||||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
return &ArtNetPacketEncode{config: config}, nil
|
return &ArtNetPacketEncode{config: config}, nil
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
package processor
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/jwetzell/artnet-go"
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ArtNetPacketFilter struct {
|
|
||||||
config config.ProcessorConfig
|
|
||||||
OpCode uint16
|
|
||||||
}
|
|
||||||
|
|
||||||
func (apf *ArtNetPacketFilter) Process(ctx context.Context, payload any) (any, error) {
|
|
||||||
payloadPacket, ok := payload.(artnet.ArtNetPacket)
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("artnet.packet.filter processor only accepts an ArtNetPacket")
|
|
||||||
}
|
|
||||||
|
|
||||||
if payloadPacket.GetOpCode() != apf.OpCode {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return payloadPacket, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (apf *ArtNetPacketFilter) Type() string {
|
|
||||||
return apf.config.Type
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
RegisterProcessor(ProcessorRegistration{
|
|
||||||
Type: "artnet.packet.filter",
|
|
||||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
|
||||||
params := config.Params
|
|
||||||
|
|
||||||
opCodeNum, err := params.GetInt("opCode")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("artnet.packet.filter opCode error: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &ArtNetPacketFilter{config: config, OpCode: uint16(opCodeNum)}, nil
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
131
internal/processor/db-query.go
Normal file
131
internal/processor/db-query.go
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
package processor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DbQuery struct {
|
||||||
|
config config.ProcessorConfig
|
||||||
|
ModuleId string
|
||||||
|
Query *template.Template
|
||||||
|
logger *slog.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dq *DbQuery) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
if wrappedPayload.Modules == nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("db.query wrapped payload has no modules")
|
||||||
|
}
|
||||||
|
|
||||||
|
module, ok := wrappedPayload.Modules[dq.ModuleId]
|
||||||
|
if !ok {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("db.query unable to find module with id: %s", dq.ModuleId)
|
||||||
|
}
|
||||||
|
|
||||||
|
dbModule, ok := module.(common.DatabaseModule)
|
||||||
|
if !ok {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("db.query module with id %s is not a DatabaseModule", dq.ModuleId)
|
||||||
|
}
|
||||||
|
|
||||||
|
db := dbModule.Database()
|
||||||
|
if db == nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("db.query module with id %s returned nil database", dq.ModuleId)
|
||||||
|
}
|
||||||
|
|
||||||
|
var queryBuffer bytes.Buffer
|
||||||
|
err := dq.Query.Execute(&queryBuffer, wrappedPayload)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// support proper parameterized queries
|
||||||
|
rows, err := db.QueryContext(ctx, queryBuffer.String())
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("db.query error executing query: %w", err)
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
|
columns, err := rows.Columns()
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("db.query error getting columns: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
results := make([]map[string]any, 0)
|
||||||
|
|
||||||
|
for rows.Next() {
|
||||||
|
columnValues := make([]interface{}, len(columns))
|
||||||
|
|
||||||
|
for i := range columnValues {
|
||||||
|
columnValues[i] = new(interface{})
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := rows.Scan(columnValues...); err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("db.query error scanning row: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
rowMap := make(map[string]any)
|
||||||
|
for i, colName := range columns {
|
||||||
|
value := *columnValues[i].(*interface{})
|
||||||
|
rowMap[colName] = value
|
||||||
|
}
|
||||||
|
results = append(results, rowMap)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(results) == 0 {
|
||||||
|
wrappedPayload.Payload = nil
|
||||||
|
return wrappedPayload, nil
|
||||||
|
} else if len(results) == 1 {
|
||||||
|
wrappedPayload.Payload = results[0]
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
wrappedPayload.Payload = results
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dq *DbQuery) Type() string {
|
||||||
|
return dq.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterProcessor(ProcessorRegistration{
|
||||||
|
Type: "db.query",
|
||||||
|
Title: "Query Database",
|
||||||
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
|
|
||||||
|
params := config.Params
|
||||||
|
|
||||||
|
moduleIdString, err := params.GetString("module")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("db.query module error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
queryString, err := params.GetString("query")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("db.query query error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
queryTemplate, err := template.New("query").Parse(queryString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &DbQuery{config: config, ModuleId: moduleIdString, Query: queryTemplate, logger: slog.Default().With("component", "processor", "type", config.Type)}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -13,11 +14,12 @@ type DebugLog struct {
|
|||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dl *DebugLog) Process(ctx context.Context, payload any) (any, error) {
|
func (dl *DebugLog) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
payload := wrappedPayload.Payload
|
||||||
payloadString := fmt.Sprintf("%+v", payload)
|
payloadString := fmt.Sprintf("%+v", payload)
|
||||||
payloadType := fmt.Sprintf("%T", payload)
|
payloadType := fmt.Sprintf("%T", payload)
|
||||||
dl.logger.Debug("", "payload", payloadString, "payloadType", payloadType)
|
dl.logger.Debug("", "payload", payloadString, "payloadType", payloadType)
|
||||||
return payload, nil
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dl *DebugLog) Type() string {
|
func (dl *DebugLog) Type() string {
|
||||||
@@ -26,7 +28,8 @@ func (dl *DebugLog) Type() string {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterProcessor(ProcessorRegistration{
|
RegisterProcessor(ProcessorRegistration{
|
||||||
Type: "debug.log",
|
Type: "debug.log",
|
||||||
|
Title: "Debug Log",
|
||||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
return &DebugLog{config: config, logger: slog.Default().With("component", "processor", "type", config.Type)}, nil
|
return &DebugLog{config: config, logger: slog.Default().With("component", "processor", "type", config.Type)}, nil
|
||||||
},
|
},
|
||||||
|
|||||||
40
internal/processor/filter-change.go
Normal file
40
internal/processor/filter-change.go
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package processor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FilterChange struct {
|
||||||
|
config config.ProcessorConfig
|
||||||
|
previous any
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fc *FilterChange) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
payload := wrappedPayload.Payload
|
||||||
|
|
||||||
|
if reflect.DeepEqual(payload, fc.previous) {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
fc.previous = payload
|
||||||
|
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fc *FilterChange) Type() string {
|
||||||
|
return fc.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterProcessor(ProcessorRegistration{
|
||||||
|
Type: "filter.change",
|
||||||
|
Title: "Filter On Change",
|
||||||
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
|
return &FilterChange{config: config}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
80
internal/processor/filter-expr.go
Normal file
80
internal/processor/filter-expr.go
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
package processor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/expr-lang/expr"
|
||||||
|
"github.com/expr-lang/expr/vm"
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NOTE(jwetzell): see language definition https://expr-lang.org/docs/language-definition
|
||||||
|
type FilterExpr struct {
|
||||||
|
config config.ProcessorConfig
|
||||||
|
Program *vm.Program
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fe *FilterExpr) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
|
||||||
|
exprEnv := wrappedPayload
|
||||||
|
|
||||||
|
output, err := expr.Run(fe.Program, exprEnv)
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
|
outputBool, ok := output.(bool)
|
||||||
|
if !ok {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("filter.expr expression did not return a boolean")
|
||||||
|
}
|
||||||
|
if !outputBool {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
wrappedPayload.Payload = exprEnv.Payload
|
||||||
|
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fe *FilterExpr) Type() string {
|
||||||
|
return fe.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterProcessor(ProcessorRegistration{
|
||||||
|
Type: "filter.expr",
|
||||||
|
Title: "Filter by Expr expression",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"expression": {
|
||||||
|
Title: "Expression",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"expression"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
|
params := config.Params
|
||||||
|
|
||||||
|
expressionString, err := params.GetString("expression")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("filter.expr expression error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
program, err := expr.Compile(expressionString)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &FilterExpr{config: config, Program: program}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
73
internal/processor/filter-regex.go
Normal file
73
internal/processor/filter-regex.go
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
package processor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FilterRegex struct {
|
||||||
|
config config.ProcessorConfig
|
||||||
|
Pattern *regexp.Regexp
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fr *FilterRegex) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
payload := wrappedPayload.Payload
|
||||||
|
payloadString, ok := common.GetAnyAs[string](payload)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("filter.regex processor only accepts a string")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !fr.Pattern.MatchString(payloadString) {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
wrappedPayload.Payload = payloadString
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fr *FilterRegex) Type() string {
|
||||||
|
return fr.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterProcessor(ProcessorRegistration{
|
||||||
|
Type: "filter.regex",
|
||||||
|
Title: "Filter by Regex",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"pattern": {
|
||||||
|
Title: "Pattern",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"pattern"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
|
params := config.Params
|
||||||
|
|
||||||
|
patternString, err := params.GetString("pattern")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("filter.regex pattern error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
patternRegexp, err := regexp.Compile(patternString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &FilterRegex{config: config, Pattern: patternRegexp}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -2,10 +2,13 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -14,18 +17,22 @@ type FloatParse struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fp *FloatParse) Process(ctx context.Context, payload any) (any, error) {
|
func (fp *FloatParse) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
payloadString, ok := payload.(string)
|
payload := wrappedPayload.Payload
|
||||||
|
payloadString, ok := common.GetAnyAs[string](payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("float.parse processor only accepts a string")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("float.parse processor only accepts a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadFloat, err := strconv.ParseFloat(payloadString, fp.BitSize)
|
payloadFloat, err := strconv.ParseFloat(payloadString, fp.BitSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
return payloadFloat, nil
|
wrappedPayload.Payload = payloadFloat
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fp *FloatParse) Type() string {
|
func (fp *FloatParse) Type() string {
|
||||||
@@ -34,7 +41,20 @@ func (fp *FloatParse) Type() string {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterProcessor(ProcessorRegistration{
|
RegisterProcessor(ProcessorRegistration{
|
||||||
Type: "float.parse",
|
Type: "float.parse",
|
||||||
|
Title: "Parse Float",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"bitSize": {
|
||||||
|
Title: "Bit Size",
|
||||||
|
Type: "integer",
|
||||||
|
Enum: []any{32, 64},
|
||||||
|
Default: json.RawMessage("64"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
New: func(moduleConfig config.ProcessorConfig) (Processor, error) {
|
New: func(moduleConfig config.ProcessorConfig) (Processor, error) {
|
||||||
params := moduleConfig.Params
|
params := moduleConfig.Params
|
||||||
|
|
||||||
|
|||||||
99
internal/processor/float-random.go
Normal file
99
internal/processor/float-random.go
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
package processor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"math/rand/v2"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FloatRandom struct {
|
||||||
|
BitSize int
|
||||||
|
Min float64
|
||||||
|
Max float64
|
||||||
|
config config.ProcessorConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fr *FloatRandom) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
if fr.BitSize == 32 {
|
||||||
|
payloadFloat := rand.Float32()*(float32(fr.Max)-float32(fr.Min)) + float32(fr.Min)
|
||||||
|
wrappedPayload.Payload = payloadFloat
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
if fr.BitSize == 64 {
|
||||||
|
payloadFloat := rand.Float64()*(fr.Max-fr.Min) + fr.Min
|
||||||
|
wrappedPayload.Payload = payloadFloat
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("float.random bitSize error: must be 32 or 64")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fr *FloatRandom) Type() string {
|
||||||
|
return fr.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterProcessor(ProcessorRegistration{
|
||||||
|
Type: "float.random",
|
||||||
|
Title: "Random Float",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"bitSize": {
|
||||||
|
Title: "Bit Size",
|
||||||
|
Type: "integer",
|
||||||
|
Enum: []any{32, 64},
|
||||||
|
Default: json.RawMessage("32"),
|
||||||
|
},
|
||||||
|
"min": {
|
||||||
|
Title: "Minimum",
|
||||||
|
Type: "number",
|
||||||
|
},
|
||||||
|
"max": {
|
||||||
|
Title: "Maximum",
|
||||||
|
Type: "number",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"min", "max"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(processorConfig config.ProcessorConfig) (Processor, error) {
|
||||||
|
params := processorConfig.Params
|
||||||
|
|
||||||
|
bitSizeInt, err := params.GetInt("bitSize")
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, config.ErrParamNotFound) {
|
||||||
|
bitSizeInt = 32
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("float.random bitSize error: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if bitSizeInt != 32 && bitSizeInt != 64 {
|
||||||
|
return nil, errors.New("float.random bitSize error: must be 32 or 64")
|
||||||
|
}
|
||||||
|
|
||||||
|
minFloat, err := params.GetFloat64("min")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("float.random min error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
maxFloat, err := params.GetFloat64("max")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("float.random max error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if maxFloat < minFloat {
|
||||||
|
return nil, errors.New("float.random max must be greater than min")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &FloatRandom{config: processorConfig, Min: minFloat, Max: maxFloat, BitSize: bitSizeInt}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -7,7 +7,9 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
freeD "github.com/jwetzell/free-d-go"
|
freeD "github.com/jwetzell/free-d-go"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -24,13 +26,16 @@ type FreeDCreate struct {
|
|||||||
Focus *template.Template
|
Focus *template.Template
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fc *FreeDCreate) Process(ctx context.Context, payload any) (any, error) {
|
func (fc *FreeDCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
|
||||||
|
templateData := wrappedPayload
|
||||||
|
|
||||||
var idBuffer bytes.Buffer
|
var idBuffer bytes.Buffer
|
||||||
err := fc.Id.Execute(&idBuffer, payload)
|
err := fc.Id.Execute(&idBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
idString := idBuffer.String()
|
idString := idBuffer.String()
|
||||||
@@ -38,14 +43,16 @@ func (fc *FreeDCreate) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
idNum, err := strconv.ParseUint(idString, 10, 8)
|
idNum, err := strconv.ParseUint(idString, 10, 8)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var panBuffer bytes.Buffer
|
var panBuffer bytes.Buffer
|
||||||
err = fc.Pan.Execute(&panBuffer, payload)
|
err = fc.Pan.Execute(&panBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
panString := panBuffer.String()
|
panString := panBuffer.String()
|
||||||
@@ -53,14 +60,16 @@ func (fc *FreeDCreate) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
panNum, err := strconv.ParseFloat(panString, 32)
|
panNum, err := strconv.ParseFloat(panString, 32)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var tiltBuffer bytes.Buffer
|
var tiltBuffer bytes.Buffer
|
||||||
err = fc.Tilt.Execute(&tiltBuffer, payload)
|
err = fc.Tilt.Execute(&tiltBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
tiltString := tiltBuffer.String()
|
tiltString := tiltBuffer.String()
|
||||||
@@ -68,14 +77,16 @@ func (fc *FreeDCreate) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
tiltNum, err := strconv.ParseFloat(tiltString, 32)
|
tiltNum, err := strconv.ParseFloat(tiltString, 32)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var rollBuffer bytes.Buffer
|
var rollBuffer bytes.Buffer
|
||||||
err = fc.Tilt.Execute(&rollBuffer, payload)
|
err = fc.Roll.Execute(&rollBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
rollString := rollBuffer.String()
|
rollString := rollBuffer.String()
|
||||||
@@ -83,14 +94,16 @@ func (fc *FreeDCreate) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
rollNum, err := strconv.ParseFloat(rollString, 32)
|
rollNum, err := strconv.ParseFloat(rollString, 32)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var posXBuffer bytes.Buffer
|
var posXBuffer bytes.Buffer
|
||||||
err = fc.PosX.Execute(&posXBuffer, payload)
|
err = fc.PosX.Execute(&posXBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
posXString := posXBuffer.String()
|
posXString := posXBuffer.String()
|
||||||
@@ -98,14 +111,16 @@ func (fc *FreeDCreate) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
posXNum, err := strconv.ParseFloat(posXString, 32)
|
posXNum, err := strconv.ParseFloat(posXString, 32)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var posYBuffer bytes.Buffer
|
var posYBuffer bytes.Buffer
|
||||||
err = fc.PosY.Execute(&posYBuffer, payload)
|
err = fc.PosY.Execute(&posYBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
posYString := posYBuffer.String()
|
posYString := posYBuffer.String()
|
||||||
@@ -113,14 +128,16 @@ func (fc *FreeDCreate) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
posYNum, err := strconv.ParseFloat(posYString, 32)
|
posYNum, err := strconv.ParseFloat(posYString, 32)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var posZBuffer bytes.Buffer
|
var posZBuffer bytes.Buffer
|
||||||
err = fc.PosZ.Execute(&posZBuffer, payload)
|
err = fc.PosZ.Execute(&posZBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
posZString := posZBuffer.String()
|
posZString := posZBuffer.String()
|
||||||
@@ -128,14 +145,16 @@ func (fc *FreeDCreate) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
posZNum, err := strconv.ParseFloat(posZString, 32)
|
posZNum, err := strconv.ParseFloat(posZString, 32)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var zoomBuffer bytes.Buffer
|
var zoomBuffer bytes.Buffer
|
||||||
err = fc.Zoom.Execute(&zoomBuffer, payload)
|
err = fc.Zoom.Execute(&zoomBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
zoomString := zoomBuffer.String()
|
zoomString := zoomBuffer.String()
|
||||||
@@ -143,14 +162,16 @@ func (fc *FreeDCreate) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
zoomNum, err := strconv.ParseInt(zoomString, 10, 32)
|
zoomNum, err := strconv.ParseInt(zoomString, 10, 32)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var focusBuffer bytes.Buffer
|
var focusBuffer bytes.Buffer
|
||||||
err = fc.Zoom.Execute(&focusBuffer, payload)
|
err = fc.Focus.Execute(&focusBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
focusString := focusBuffer.String()
|
focusString := focusBuffer.String()
|
||||||
@@ -158,7 +179,8 @@ func (fc *FreeDCreate) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
focusNum, err := strconv.ParseInt(focusString, 10, 32)
|
focusNum, err := strconv.ParseInt(focusString, 10, 32)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadMessage := freeD.FreeDPosition{
|
payloadMessage := freeD.FreeDPosition{
|
||||||
@@ -173,7 +195,9 @@ func (fc *FreeDCreate) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
Focus: int32(focusNum),
|
Focus: int32(focusNum),
|
||||||
}
|
}
|
||||||
|
|
||||||
return payloadMessage, nil
|
wrappedPayload.Payload = payloadMessage
|
||||||
|
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fc *FreeDCreate) Type() string {
|
func (fc *FreeDCreate) Type() string {
|
||||||
@@ -182,7 +206,61 @@ func (fc *FreeDCreate) Type() string {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterProcessor(ProcessorRegistration{
|
RegisterProcessor(ProcessorRegistration{
|
||||||
Type: "freed.create",
|
Type: "freed.create",
|
||||||
|
Title: "Create FreeD",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"id": {
|
||||||
|
Title: "Camera ID",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"pan": {
|
||||||
|
Title: "Pan",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"tilt": {
|
||||||
|
Title: "Tilt",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"roll": {
|
||||||
|
Title: "Roll",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"posX": {
|
||||||
|
Title: "Position X",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"posY": {
|
||||||
|
Title: "Position Y",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"posZ": {
|
||||||
|
Title: "Position Z",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"zoom": {
|
||||||
|
Title: "Zoom",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"focus": {
|
||||||
|
Title: "Focus",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{
|
||||||
|
"id",
|
||||||
|
"pan",
|
||||||
|
"tilt",
|
||||||
|
"roll",
|
||||||
|
"posX",
|
||||||
|
"posY",
|
||||||
|
"posZ",
|
||||||
|
"zoom",
|
||||||
|
"focus",
|
||||||
|
},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
|
|
||||||
// TODO(jwetzell): make some params optional
|
// TODO(jwetzell): make some params optional
|
||||||
@@ -205,6 +283,10 @@ func init() {
|
|||||||
|
|
||||||
panTemplate, err := template.New("pan").Parse(panString)
|
panTemplate, err := template.New("pan").Parse(panString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
tiltString, err := params.GetString("tilt")
|
tiltString, err := params.GetString("tilt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("freed.create tilt error: %w", err)
|
return nil, fmt.Errorf("freed.create tilt error: %w", err)
|
||||||
@@ -212,6 +294,10 @@ func init() {
|
|||||||
|
|
||||||
tiltTemplate, err := template.New("tilt").Parse(tiltString)
|
tiltTemplate, err := template.New("tilt").Parse(tiltString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
rollString, err := params.GetString("roll")
|
rollString, err := params.GetString("roll")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("freed.create roll error: %w", err)
|
return nil, fmt.Errorf("freed.create roll error: %w", err)
|
||||||
@@ -263,12 +349,19 @@ func init() {
|
|||||||
|
|
||||||
zoomTemplate, err := template.New("zoom").Parse(zoomString)
|
zoomTemplate, err := template.New("zoom").Parse(zoomString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
focusString, err := params.GetString("focus")
|
focusString, err := params.GetString("focus")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("freed.create focus error: %w", err)
|
return nil, fmt.Errorf("freed.create focus error: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
focusTemplate, err := template.New("focus").Parse(focusString)
|
focusTemplate, err := template.New("focus").Parse(focusString)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return &FreeDCreate{
|
return &FreeDCreate{
|
||||||
config: config,
|
config: config,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
freeD "github.com/jwetzell/free-d-go"
|
freeD "github.com/jwetzell/free-d-go"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -12,27 +13,32 @@ type FreeDDecode struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fdd *FreeDDecode) Process(ctx context.Context, payload any) (any, error) {
|
func (fd *FreeDDecode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
payloadBytes, ok := payload.([]byte)
|
payload := wrappedPayload.Payload
|
||||||
|
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("freed.decode processor only accepts a []byte")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("freed.decode processor only accepts a []byte")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadMessage, err := freeD.Decode(payloadBytes)
|
payloadMessage, err := freeD.Decode(payloadBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
return payloadMessage, nil
|
wrappedPayload.Payload = payloadMessage
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fdd *FreeDDecode) Type() string {
|
func (fd *FreeDDecode) Type() string {
|
||||||
return fdd.config.Type
|
return fd.config.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterProcessor(ProcessorRegistration{
|
RegisterProcessor(ProcessorRegistration{
|
||||||
Type: "freed.decode",
|
Type: "freed.decode",
|
||||||
|
Title: "Decode FreeD",
|
||||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
return &FreeDDecode{config: config}, nil
|
return &FreeDDecode{config: config}, nil
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
freeD "github.com/jwetzell/free-d-go"
|
freeD "github.com/jwetzell/free-d-go"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -12,24 +13,29 @@ type FreeDEncode struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fde *FreeDEncode) Process(ctx context.Context, payload any) (any, error) {
|
func (fe *FreeDEncode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
payloadPosition, ok := payload.(freeD.FreeDPosition)
|
payload := wrappedPayload.Payload
|
||||||
|
payloadPosition, ok := common.GetAnyAs[freeD.FreeDPosition](payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("freed.decode processor only accepts a FreeDEncode")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("freed.encode processor only accepts a FreeDPosition")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadBytes := freeD.Encode(payloadPosition)
|
payloadBytes := freeD.Encode(payloadPosition)
|
||||||
return payloadBytes, nil
|
|
||||||
|
wrappedPayload.Payload = payloadBytes
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fde *FreeDEncode) Type() string {
|
func (fe *FreeDEncode) Type() string {
|
||||||
return fde.config.Type
|
return fe.config.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterProcessor(ProcessorRegistration{
|
RegisterProcessor(ProcessorRegistration{
|
||||||
Type: "freed.encode",
|
Type: "freed.encode",
|
||||||
|
Title: "Encode FreeD",
|
||||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
return &FreeDEncode{config: config}, nil
|
return &FreeDEncode{config: config}, nil
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
package processor
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
type HTTPRequestCreate struct {
|
|
||||||
config config.ProcessorConfig
|
|
||||||
Method string
|
|
||||||
URL *template.Template
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hrc *HTTPRequestCreate) Process(ctx context.Context, payload any) (any, error) {
|
|
||||||
|
|
||||||
var urlBuffer bytes.Buffer
|
|
||||||
err := hrc.URL.Execute(&urlBuffer, payload)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
urlString := urlBuffer.String()
|
|
||||||
|
|
||||||
//TODO(jwetzell): support body
|
|
||||||
request, err := http.NewRequest(hrc.Method, urlString, bytes.NewBuffer([]byte{}))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return request, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hrc *HTTPRequestCreate) Type() string {
|
|
||||||
return hrc.config.Type
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
RegisterProcessor(ProcessorRegistration{
|
|
||||||
Type: "http.request.create",
|
|
||||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
|
||||||
params := config.Params
|
|
||||||
|
|
||||||
methodString, err := params.GetString("method")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("http.request.create method error: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
urlString, err := params.GetString("url")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("http.request.create url error: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
urlTemplate, err := template.New("url").Parse(urlString)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &HTTPRequestCreate{config: config, URL: urlTemplate, Method: methodString}, nil
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
117
internal/processor/http-request-do.go
Normal file
117
internal/processor/http-request-do.go
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
package processor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"text/template"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HTTPRequestDo struct {
|
||||||
|
config config.ProcessorConfig
|
||||||
|
client *http.Client
|
||||||
|
Method string
|
||||||
|
URL *template.Template
|
||||||
|
}
|
||||||
|
|
||||||
|
func (hrd *HTTPRequestDo) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
|
||||||
|
templateData := wrappedPayload
|
||||||
|
|
||||||
|
var urlBuffer bytes.Buffer
|
||||||
|
err := hrd.URL.Execute(&urlBuffer, templateData)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
|
urlString := urlBuffer.String()
|
||||||
|
|
||||||
|
//TODO(jwetzell): support body
|
||||||
|
request, err := http.NewRequest(hrd.Method, urlString, bytes.NewBuffer([]byte{}))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
|
response, err := hrd.client.Do(request)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
|
body, err := io.ReadAll(response.Body)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO(jwetzell): support headers, etc
|
||||||
|
wrappedPayload.Payload = HTTPResponse{
|
||||||
|
Status: response.StatusCode,
|
||||||
|
Body: body,
|
||||||
|
}
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (hrd *HTTPRequestDo) Type() string {
|
||||||
|
return hrd.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterProcessor(ProcessorRegistration{
|
||||||
|
Type: "http.request.do",
|
||||||
|
Title: "Do HTTP Request",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"method": {
|
||||||
|
Title: "HTTP Method",
|
||||||
|
Type: "string",
|
||||||
|
Enum: []any{"GET", "POST", "PUT", "PATCH", "DELETE"},
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
Title: "URL",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"method", "url"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
|
params := config.Params
|
||||||
|
|
||||||
|
methodString, err := params.GetString("method")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("http.request.do method error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
urlString, err := params.GetString("url")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("http.request.do url error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
urlTemplate, err := template.New("url").Parse(urlString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
client := &http.Client{
|
||||||
|
Timeout: 10 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
|
return &HTTPRequestDo{config: config, URL: urlTemplate, Method: methodString, client: client}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package processor
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
type HTTPRequestEncode struct {
|
|
||||||
config config.ProcessorConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hre *HTTPRequestEncode) Process(ctx context.Context, payload any) (any, error) {
|
|
||||||
payloadRequest, ok := payload.(*http.Request)
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("http.request.encode processor only accepts an http.Request")
|
|
||||||
}
|
|
||||||
|
|
||||||
bytes, err := io.ReadAll(payloadRequest.Body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return bytes, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hre *HTTPRequestEncode) Type() string {
|
|
||||||
return hre.config.Type
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
RegisterProcessor(ProcessorRegistration{
|
|
||||||
Type: "http.request.encode",
|
|
||||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
|
||||||
return &HTTPRequestEncode{config: config}, nil
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
package processor
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"regexp"
|
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
type HTTPRequestFilter struct {
|
|
||||||
config config.ProcessorConfig
|
|
||||||
Path *regexp.Regexp
|
|
||||||
Method string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hrf *HTTPRequestFilter) Process(ctx context.Context, payload any) (any, error) {
|
|
||||||
|
|
||||||
payloadRequest, ok := payload.(*http.Request)
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("http.request.filter can only operate on http.Request payloads")
|
|
||||||
}
|
|
||||||
|
|
||||||
if hrf.Method != "" {
|
|
||||||
if payloadRequest.Method != hrf.Method {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !hrf.Path.MatchString(payloadRequest.URL.Path) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return payloadRequest, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hrf *HTTPRequestFilter) Type() string {
|
|
||||||
return hrf.config.Type
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
RegisterProcessor(ProcessorRegistration{
|
|
||||||
Type: "http.request.filter",
|
|
||||||
New: func(moduleConfig config.ProcessorConfig) (Processor, error) {
|
|
||||||
params := moduleConfig.Params
|
|
||||||
pathString, err := params.GetString("path")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("http.request.filter path error: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
pathRegexp, err := regexp.Compile(fmt.Sprintf("^%s$", pathString))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
methodString, err := params.GetString("method")
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, config.ErrParamNotFound) {
|
|
||||||
return &HTTPRequestFilter{config: moduleConfig, Path: pathRegexp}, nil
|
|
||||||
} else {
|
|
||||||
return nil, fmt.Errorf("http.request.filter method error: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return &HTTPRequestFilter{config: moduleConfig, Path: pathRegexp, Method: methodString}, nil
|
|
||||||
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -6,6 +6,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,27 +22,46 @@ type HTTPResponse struct {
|
|||||||
Body []byte
|
Body []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hre *HTTPResponseCreate) Process(ctx context.Context, payload any) (any, error) {
|
func (hrc *HTTPResponseCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
templateData := wrappedPayload
|
||||||
|
|
||||||
var bodyBuffer bytes.Buffer
|
var bodyBuffer bytes.Buffer
|
||||||
err := hre.BodyTmpl.Execute(&bodyBuffer, payload)
|
err := hrc.BodyTmpl.Execute(&bodyBuffer, templateData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
wrappedPayload.Payload = HTTPResponse{
|
||||||
return HTTPResponse{
|
Status: hrc.Status,
|
||||||
Status: hre.Status,
|
|
||||||
Body: bodyBuffer.Bytes(),
|
Body: bodyBuffer.Bytes(),
|
||||||
}, nil
|
}
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hre *HTTPResponseCreate) Type() string {
|
func (hrc *HTTPResponseCreate) Type() string {
|
||||||
return hre.config.Type
|
return hrc.config.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterProcessor(ProcessorRegistration{
|
RegisterProcessor(ProcessorRegistration{
|
||||||
Type: "http.response.create",
|
Type: "http.response.create",
|
||||||
|
Title: "Create HTTP Response",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"status": {
|
||||||
|
Title: "Status Code",
|
||||||
|
Type: "integer",
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
Title: "Body",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"status", "body"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
|
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
package processor
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
type HTTPResponseEncode struct {
|
|
||||||
config config.ProcessorConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hre *HTTPResponseEncode) Process(ctx context.Context, payload any) (any, error) {
|
|
||||||
payloadResponse, ok := payload.(*http.Response)
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("http.response.encode processor only accepts an http.Response")
|
|
||||||
}
|
|
||||||
defer payloadResponse.Body.Close()
|
|
||||||
|
|
||||||
bytes, err := io.ReadAll(payloadResponse.Body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return bytes, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hre *HTTPResponseEncode) Type() string {
|
|
||||||
return hre.config.Type
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
RegisterProcessor(ProcessorRegistration{
|
|
||||||
Type: "http.response.encode",
|
|
||||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
|
||||||
return &HTTPResponseEncode{config: config}, nil
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -2,10 +2,13 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,18 +18,22 @@ type IntParse struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ip *IntParse) Process(ctx context.Context, payload any) (any, error) {
|
func (ip *IntParse) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
payloadString, ok := payload.(string)
|
payload := wrappedPayload.Payload
|
||||||
|
payloadString, ok := common.GetAnyAs[string](payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("int.parse processor only accepts a string")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("int.parse processor only accepts a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadInt, err := strconv.ParseInt(payloadString, ip.Base, ip.BitSize)
|
payloadInt, err := strconv.ParseInt(payloadString, ip.Base, ip.BitSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
return payloadInt, nil
|
wrappedPayload.Payload = payloadInt
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ip *IntParse) Type() string {
|
func (ip *IntParse) Type() string {
|
||||||
@@ -35,7 +42,26 @@ func (ip *IntParse) Type() string {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterProcessor(ProcessorRegistration{
|
RegisterProcessor(ProcessorRegistration{
|
||||||
Type: "int.parse",
|
Type: "int.parse",
|
||||||
|
Title: "Parse Int",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"base": {
|
||||||
|
Title: "Base",
|
||||||
|
Type: "integer",
|
||||||
|
Enum: []any{0, 2, 8, 10, 16},
|
||||||
|
Default: json.RawMessage("10"),
|
||||||
|
},
|
||||||
|
"bitSize": {
|
||||||
|
Title: "Bit Size",
|
||||||
|
Type: "integer",
|
||||||
|
Enum: []any{0, 8, 16, 32, 64},
|
||||||
|
Default: json.RawMessage("64"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
New: func(moduleConfig config.ProcessorConfig) (Processor, error) {
|
New: func(moduleConfig config.ProcessorConfig) (Processor, error) {
|
||||||
params := moduleConfig.Params
|
params := moduleConfig.Params
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math/rand/v2"
|
"math/rand/v2"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,18 +17,35 @@ type IntRandom struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (up *IntRandom) Process(ctx context.Context, payload any) (any, error) {
|
func (ir *IntRandom) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
payloadInt := rand.IntN(up.Max-up.Min+1) + up.Min
|
payloadInt := rand.IntN(ir.Max-ir.Min+1) + ir.Min
|
||||||
return payloadInt, nil
|
wrappedPayload.Payload = payloadInt
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (up *IntRandom) Type() string {
|
func (ir *IntRandom) Type() string {
|
||||||
return up.config.Type
|
return ir.config.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterProcessor(ProcessorRegistration{
|
RegisterProcessor(ProcessorRegistration{
|
||||||
Type: "int.random",
|
Type: "int.random",
|
||||||
|
Title: "Random Int",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"min": {
|
||||||
|
Title: "Minimum",
|
||||||
|
Type: "integer",
|
||||||
|
},
|
||||||
|
"max": {
|
||||||
|
Title: "Maximum",
|
||||||
|
Type: "integer",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"min", "max"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
|
|
||||||
|
|||||||
99
internal/processor/int-scale.go
Normal file
99
internal/processor/int-scale.go
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
package processor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type IntScale struct {
|
||||||
|
OutMin int
|
||||||
|
OutMax int
|
||||||
|
InMin int
|
||||||
|
InMax int
|
||||||
|
config config.ProcessorConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ir *IntScale) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
payload := wrappedPayload.Payload
|
||||||
|
payloadInt, ok := common.GetAnyAs[int](payload)
|
||||||
|
if !ok {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("int.scale can only process an int")
|
||||||
|
}
|
||||||
|
|
||||||
|
payloadInt = (payloadInt-ir.InMin)*(ir.OutMax-ir.OutMin)/(ir.InMax-ir.InMin) + ir.OutMin
|
||||||
|
wrappedPayload.Payload = payloadInt
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ir *IntScale) Type() string {
|
||||||
|
return ir.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterProcessor(ProcessorRegistration{
|
||||||
|
Type: "int.scale",
|
||||||
|
Title: "Scale Int",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"inMin": {
|
||||||
|
Title: "Input Minimum",
|
||||||
|
Type: "integer",
|
||||||
|
},
|
||||||
|
"inMax": {
|
||||||
|
Title: "Input Maximum",
|
||||||
|
Type: "integer",
|
||||||
|
},
|
||||||
|
"outMin": {
|
||||||
|
Title: "Output Minimum",
|
||||||
|
Type: "integer",
|
||||||
|
},
|
||||||
|
"outMax": {
|
||||||
|
Title: "Output Maximum",
|
||||||
|
Type: "integer",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"inMin", "inMax", "outMin", "outMax"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
|
params := config.Params
|
||||||
|
|
||||||
|
inMinInt, err := params.GetInt("inMin")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("int.scale inMin error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
inMaxInt, err := params.GetInt("inMax")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("int.scale inMax error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if inMaxInt < inMinInt {
|
||||||
|
return nil, errors.New("int.scale inMax must be greater than inMin")
|
||||||
|
}
|
||||||
|
|
||||||
|
outMinInt, err := params.GetInt("outMin")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("int.scale outMin error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
outMaxInt, err := params.GetInt("outMax")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("int.scale outMax error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if outMaxInt < outMinInt {
|
||||||
|
return nil, errors.New("int.scale outMax must be greater than outMin")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &IntScale{config: config, InMin: inMinInt, InMax: inMaxInt, OutMin: outMinInt, OutMax: outMaxInt}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -12,21 +13,30 @@ type JsonDecode struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (jd *JsonDecode) Process(ctx context.Context, payload any) (any, error) {
|
func (jd *JsonDecode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
payloadString, ok := payload.(string)
|
payload := wrappedPayload.Payload
|
||||||
|
|
||||||
|
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("json.decode processor only accepts a string")
|
payloadString, ok := common.GetAnyAs[string](payload)
|
||||||
|
if !ok {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("json.decode can only process a string or []byte")
|
||||||
|
}
|
||||||
|
payloadBytes = []byte(payloadString)
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadJson := make(map[string]any)
|
payloadJson := make(map[string]any)
|
||||||
|
|
||||||
err := json.Unmarshal([]byte(payloadString), &payloadJson)
|
err := json.Unmarshal(payloadBytes, &payloadJson)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return payloadJson, nil
|
wrappedPayload.Payload = payloadJson
|
||||||
|
return wrappedPayload, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +46,8 @@ func (jd *JsonDecode) Type() string {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterProcessor(ProcessorRegistration{
|
RegisterProcessor(ProcessorRegistration{
|
||||||
Type: "json.decode",
|
Type: "json.decode",
|
||||||
|
Title: "Decode JSON",
|
||||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
return &JsonDecode{config: config}, nil
|
return &JsonDecode{config: config}, nil
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -12,20 +13,23 @@ type JsonEncode struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (je *JsonEncode) Process(ctx context.Context, payload any) (any, error) {
|
func (je *JsonEncode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
payload := wrappedPayload.Payload
|
||||||
var payloadBuffer bytes.Buffer
|
var payloadBuffer bytes.Buffer
|
||||||
|
|
||||||
err := json.NewEncoder(&payloadBuffer).Encode(payload)
|
err := json.NewEncoder(&payloadBuffer).Encode(payload)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadBytes := payloadBuffer.Bytes()
|
payloadBytes := payloadBuffer.Bytes()
|
||||||
|
|
||||||
payloadBytes = payloadBytes[0 : len(payloadBytes)-1]
|
payloadBytes = payloadBytes[0 : len(payloadBytes)-1]
|
||||||
|
|
||||||
return payloadBytes, nil
|
wrappedPayload.Payload = payloadBytes
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (je *JsonEncode) Type() string {
|
func (je *JsonEncode) Type() string {
|
||||||
@@ -34,7 +38,8 @@ func (je *JsonEncode) Type() string {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterProcessor(ProcessorRegistration{
|
RegisterProcessor(ProcessorRegistration{
|
||||||
Type: "json.encode",
|
Type: "json.encode",
|
||||||
|
Title: "Encode JSON",
|
||||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
return &JsonEncode{config: config}, nil
|
return &JsonEncode{config: config}, nil
|
||||||
},
|
},
|
||||||
|
|||||||
88
internal/processor/kv-get.go
Normal file
88
internal/processor/kv-get.go
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
package processor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type KVGet struct {
|
||||||
|
config config.ProcessorConfig
|
||||||
|
ModuleId string
|
||||||
|
Key string
|
||||||
|
logger *slog.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func (kvg *KVGet) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
if wrappedPayload.Modules == nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("kv.get wrapped payload has no modules")
|
||||||
|
}
|
||||||
|
|
||||||
|
module, ok := wrappedPayload.Modules[kvg.ModuleId]
|
||||||
|
if !ok {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("kv.get unable to find module with id: %s", kvg.ModuleId)
|
||||||
|
}
|
||||||
|
|
||||||
|
kvModule, ok := module.(common.KeyValueModule)
|
||||||
|
if !ok {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("kv.get module with id %s is not a KeyValueModule", kvg.ModuleId)
|
||||||
|
}
|
||||||
|
|
||||||
|
value, err := kvModule.Get(kvg.Key)
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("kv.get error getting key: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
wrappedPayload.Payload = value
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (kvg *KVGet) Type() string {
|
||||||
|
return kvg.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterProcessor(ProcessorRegistration{
|
||||||
|
Type: "kv.get",
|
||||||
|
Title: "Get Key",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"module": {
|
||||||
|
Title: "Module ID",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"key": {
|
||||||
|
Title: "Key",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"module", "key"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
|
|
||||||
|
params := config.Params
|
||||||
|
|
||||||
|
moduleIdString, err := params.GetString("module")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("kv.get module error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
keyString, err := params.GetString("key")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("kv.get key error: %w", err)
|
||||||
|
}
|
||||||
|
return &KVGet{config: config, ModuleId: moduleIdString, Key: keyString, logger: slog.Default().With("component", "processor", "type", config.Type)}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
114
internal/processor/kv-set.go
Normal file
114
internal/processor/kv-set.go
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
package processor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"html/template"
|
||||||
|
"log/slog"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type KVSet struct {
|
||||||
|
config config.ProcessorConfig
|
||||||
|
ModuleId string
|
||||||
|
Key string
|
||||||
|
Value *template.Template
|
||||||
|
logger *slog.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func (kvs *KVSet) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
|
||||||
|
if wrappedPayload.Modules == nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("kv.set wrapped payload has no modules")
|
||||||
|
}
|
||||||
|
|
||||||
|
module, ok := wrappedPayload.Modules[kvs.ModuleId]
|
||||||
|
if !ok {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("kv.set unable to find module with id: %s", kvs.ModuleId)
|
||||||
|
}
|
||||||
|
|
||||||
|
kvModule, ok := module.(common.KeyValueModule)
|
||||||
|
if !ok {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("kv.set module with id %s is not a KeyValueModule", kvs.ModuleId)
|
||||||
|
}
|
||||||
|
|
||||||
|
var valueBuffer bytes.Buffer
|
||||||
|
err := kvs.Value.Execute(&valueBuffer, wrappedPayload)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = kvModule.Set(kvs.Key, valueBuffer.String())
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("kv.set error setting key: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (kvs *KVSet) Type() string {
|
||||||
|
return kvs.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterProcessor(ProcessorRegistration{
|
||||||
|
Type: "kv.set",
|
||||||
|
Title: "Set Key",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"module": {
|
||||||
|
Title: "Module ID",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"key": {
|
||||||
|
Title: "Key",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"value": {
|
||||||
|
Title: "Value",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"module", "key", "value"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
|
|
||||||
|
params := config.Params
|
||||||
|
|
||||||
|
moduleIdString, err := params.GetString("module")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("kv.set module error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
keyString, err := params.GetString("key")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("kv.set key error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
valueString, err := params.GetString("value")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("kv.set value error: %w", err)
|
||||||
|
}
|
||||||
|
valueTemplate, err := template.New("template").Parse(valueString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &KVSet{config: config, ModuleId: moduleIdString, Key: keyString, Value: valueTemplate, logger: slog.Default().With("component", "processor", "type", config.Type)}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
134
internal/processor/midi-control_change-create.go
Normal file
134
internal/processor/midi-control_change-create.go
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
//go:build cgo
|
||||||
|
|
||||||
|
package processor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"gitlab.com/gomidi/midi/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MIDIControlChangeCreate struct {
|
||||||
|
config config.ProcessorConfig
|
||||||
|
Channel *template.Template
|
||||||
|
Control *template.Template
|
||||||
|
Value *template.Template
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mccc *MIDIControlChangeCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
templateData := wrappedPayload
|
||||||
|
|
||||||
|
var channelBuffer bytes.Buffer
|
||||||
|
err := mccc.Channel.Execute(&channelBuffer, templateData)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
|
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
||||||
|
|
||||||
|
var controlBuffer bytes.Buffer
|
||||||
|
err = mccc.Control.Execute(&controlBuffer, templateData)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
|
controlValue, err := strconv.ParseUint(controlBuffer.String(), 10, 8)
|
||||||
|
|
||||||
|
var valueBuffer bytes.Buffer
|
||||||
|
err = mccc.Value.Execute(&valueBuffer, templateData)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
|
valueValue, err := strconv.ParseUint(valueBuffer.String(), 10, 8)
|
||||||
|
|
||||||
|
payloadMessage := midi.ControlChange(uint8(channelValue), uint8(controlValue), uint8(valueValue))
|
||||||
|
wrappedPayload.Payload = payloadMessage
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mccc *MIDIControlChangeCreate) Type() string {
|
||||||
|
return mccc.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterProcessor(ProcessorRegistration{
|
||||||
|
Type: "midi.control_change.create",
|
||||||
|
Title: "Create MIDI Control Change Message",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"channel": {
|
||||||
|
Title: "Channel",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"control": {
|
||||||
|
Title: "Control",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"value": {
|
||||||
|
Title: "Value",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"channel", "control", "value"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
|
|
||||||
|
params := config.Params
|
||||||
|
|
||||||
|
channelString, err := params.GetString("channel")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("midi.control_change.create channel error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
channelTemplate, err := template.New("channel").Parse(channelString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
controlString, err := params.GetString("control")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("midi.control_change.create control error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
controlTemplate, err := template.New("control").Parse(controlString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
valueString, err := params.GetString("value")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("midi.control_change.create value error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
valueTemplate, err := template.New("value").Parse(valueString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &MIDIControlChangeCreate{
|
||||||
|
config: config,
|
||||||
|
Channel: channelTemplate,
|
||||||
|
Control: controlTemplate,
|
||||||
|
Value: valueTemplate,
|
||||||
|
}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -1,318 +0,0 @@
|
|||||||
//go:build cgo
|
|
||||||
|
|
||||||
package processor
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
|
||||||
"gitlab.com/gomidi/midi/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
// TODO(jwetzell): support using numbers in config file treated as hardcoded values
|
|
||||||
type MIDIMessageCreate struct {
|
|
||||||
config config.ProcessorConfig
|
|
||||||
ProcessFunc func(ctx context.Context, payload any) (any, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mmc *MIDIMessageCreate) Process(ctx context.Context, payload any) (any, error) {
|
|
||||||
return mmc.ProcessFunc(ctx, payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mmc *MIDIMessageCreate) Type() string {
|
|
||||||
return mmc.config.Type
|
|
||||||
}
|
|
||||||
|
|
||||||
func newMidiNoteOnCreate(config config.ProcessorConfig) (Processor, error) {
|
|
||||||
|
|
||||||
params := config.Params
|
|
||||||
|
|
||||||
channelString, err := params.GetString("channel")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("midi.message.create channel error: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
channelTemplate, err := template.New("channel").Parse(channelString)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
noteString, err := params.GetString("note")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("midi.message.create note error: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
noteTemplate, err := template.New("note").Parse(noteString)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
velocityString, err := params.GetString("velocity")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("midi.message.create velocity error: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
velocityTemplate, err := template.New("velocity").Parse(velocityString)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &MIDIMessageCreate{config: config, ProcessFunc: func(ctx context.Context, payload any) (any, error) {
|
|
||||||
|
|
||||||
var channelBuffer bytes.Buffer
|
|
||||||
err := channelTemplate.Execute(&channelBuffer, payload)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
|
||||||
|
|
||||||
var noteBuffer bytes.Buffer
|
|
||||||
err = noteTemplate.Execute(¬eBuffer, payload)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
noteValue, err := strconv.ParseUint(noteBuffer.String(), 10, 8)
|
|
||||||
|
|
||||||
var velocityBuffer bytes.Buffer
|
|
||||||
err = velocityTemplate.Execute(&velocityBuffer, payload)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
velocityValue, err := strconv.ParseUint(velocityBuffer.String(), 10, 8)
|
|
||||||
payloadMessage := midi.NoteOn(uint8(channelValue), uint8(noteValue), uint8(velocityValue))
|
|
||||||
return payloadMessage, nil
|
|
||||||
}}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func newMidiNoteOffCreate(config config.ProcessorConfig) (Processor, error) {
|
|
||||||
|
|
||||||
params := config.Params
|
|
||||||
|
|
||||||
channelString, err := params.GetString("channel")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("midi.message.create channel error: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
channelTemplate, err := template.New("channel").Parse(channelString)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
noteString, err := params.GetString("note")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("midi.message.create note error: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
noteTemplate, err := template.New("note").Parse(noteString)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
velocityString, err := params.GetString("velocity")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("midi.message.create velocity error: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
velocityTemplate, err := template.New("velocity").Parse(velocityString)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &MIDIMessageCreate{config: config, ProcessFunc: func(ctx context.Context, payload any) (any, error) {
|
|
||||||
|
|
||||||
var channelBuffer bytes.Buffer
|
|
||||||
err := channelTemplate.Execute(&channelBuffer, payload)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
|
||||||
|
|
||||||
var noteBuffer bytes.Buffer
|
|
||||||
err = noteTemplate.Execute(¬eBuffer, payload)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
noteValue, err := strconv.ParseUint(noteBuffer.String(), 10, 8)
|
|
||||||
|
|
||||||
var velocityBuffer bytes.Buffer
|
|
||||||
err = velocityTemplate.Execute(&velocityBuffer, payload)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
velocityValue, err := strconv.ParseUint(velocityBuffer.String(), 10, 8)
|
|
||||||
|
|
||||||
payloadMessage := midi.NoteOffVelocity(uint8(channelValue), uint8(noteValue), uint8(velocityValue))
|
|
||||||
return payloadMessage, nil
|
|
||||||
}}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func newMidiControlChangeCreate(config config.ProcessorConfig) (Processor, error) {
|
|
||||||
|
|
||||||
params := config.Params
|
|
||||||
|
|
||||||
channelString, err := params.GetString("channel")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("midi.message.create channel error: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
channelTemplate, err := template.New("channel").Parse(channelString)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
controlString, err := params.GetString("control")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("midi.message.create control error: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
controlTemplate, err := template.New("control").Parse(controlString)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
valueString, err := params.GetString("value")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("midi.message.create value error: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
valueTemplate, err := template.New("value").Parse(valueString)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &MIDIMessageCreate{config: config, ProcessFunc: func(ctx context.Context, payload any) (any, error) {
|
|
||||||
|
|
||||||
var channelBuffer bytes.Buffer
|
|
||||||
err := channelTemplate.Execute(&channelBuffer, payload)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
|
||||||
|
|
||||||
var controlBuffer bytes.Buffer
|
|
||||||
err = controlTemplate.Execute(&controlBuffer, payload)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
controlValue, err := strconv.ParseUint(controlBuffer.String(), 10, 8)
|
|
||||||
|
|
||||||
var valueBuffer bytes.Buffer
|
|
||||||
err = valueTemplate.Execute(&valueBuffer, payload)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
valueValue, err := strconv.ParseUint(valueBuffer.String(), 10, 8)
|
|
||||||
|
|
||||||
payloadMessage := midi.ControlChange(uint8(channelValue), uint8(controlValue), uint8(valueValue))
|
|
||||||
return payloadMessage, nil
|
|
||||||
}}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func newMidiProgramChangeCreate(config config.ProcessorConfig) (Processor, error) {
|
|
||||||
|
|
||||||
params := config.Params
|
|
||||||
|
|
||||||
channelString, err := params.GetString("channel")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("midi.message.create channel error: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
channelTemplate, err := template.New("channel").Parse(channelString)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
programString, err := params.GetString("program")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("midi.message.create program error: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
programTemplate, err := template.New("program").Parse(programString)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &MIDIMessageCreate{config: config, ProcessFunc: func(ctx context.Context, payload any) (any, error) {
|
|
||||||
|
|
||||||
var channelBuffer bytes.Buffer
|
|
||||||
err := channelTemplate.Execute(&channelBuffer, payload)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
|
||||||
|
|
||||||
var programBuffer bytes.Buffer
|
|
||||||
err = programTemplate.Execute(&programBuffer, payload)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
programValue, err := strconv.ParseUint(programBuffer.String(), 10, 8)
|
|
||||||
|
|
||||||
payloadMessage := midi.ProgramChange(uint8(channelValue), uint8(programValue))
|
|
||||||
return payloadMessage, nil
|
|
||||||
}}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
RegisterProcessor(ProcessorRegistration{
|
|
||||||
Type: "midi.message.create",
|
|
||||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
|
||||||
params := config.Params
|
|
||||||
|
|
||||||
msgTypeString, err := params.GetString("type")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("midi.message.create type error: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
switch msgTypeString {
|
|
||||||
case "NoteOn", "noteon", "note_on":
|
|
||||||
return newMidiNoteOnCreate(config)
|
|
||||||
case "NoteOff", "noteoff", "note_off":
|
|
||||||
return newMidiNoteOffCreate(config)
|
|
||||||
case "ControlChange", "controlchange", "control_change":
|
|
||||||
return newMidiControlChangeCreate(config)
|
|
||||||
case "ProgramChange", "programchange", "program_change":
|
|
||||||
return newMidiProgramChangeCreate(config)
|
|
||||||
default:
|
|
||||||
return nil, fmt.Errorf("midi.message.create does not support type %s", msgTypeString)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"gitlab.com/gomidi/midi/v2"
|
"gitlab.com/gomidi/midi/v2"
|
||||||
)
|
)
|
||||||
@@ -14,16 +15,19 @@ type MIDIMessageDecode struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mmd *MIDIMessageDecode) Process(ctx context.Context, payload any) (any, error) {
|
func (mmd *MIDIMessageDecode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
payloadBytes, ok := payload.([]byte)
|
payload := wrappedPayload.Payload
|
||||||
|
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("midi.message.decode processor only accepts a []byte")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("midi.message.decode processor only accepts a []byte")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadMessage := midi.Message(payloadBytes)
|
payloadMessage := midi.Message(payloadBytes)
|
||||||
|
|
||||||
return payloadMessage, nil
|
wrappedPayload.Payload = payloadMessage
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mmd *MIDIMessageDecode) Type() string {
|
func (mmd *MIDIMessageDecode) Type() string {
|
||||||
@@ -32,7 +36,8 @@ func (mmd *MIDIMessageDecode) Type() string {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterProcessor(ProcessorRegistration{
|
RegisterProcessor(ProcessorRegistration{
|
||||||
Type: "midi.message.decode",
|
Type: "midi.message.decode",
|
||||||
|
Title: "Decode MIDI Message",
|
||||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
return &MIDIMessageDecode{config: config}, nil
|
return &MIDIMessageDecode{config: config}, nil
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"gitlab.com/gomidi/midi/v2"
|
"gitlab.com/gomidi/midi/v2"
|
||||||
)
|
)
|
||||||
@@ -14,14 +15,17 @@ type MIDIMessageEncode struct {
|
|||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mme *MIDIMessageEncode) Process(ctx context.Context, payload any) (any, error) {
|
func (mme *MIDIMessageEncode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
payloadMessage, ok := payload.(midi.Message)
|
payload := wrappedPayload.Payload
|
||||||
|
payloadMessage, ok := common.GetAnyAs[midi.Message](payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("midi.message.encode processor only accepts a midi.Message")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("midi.message.encode processor only accepts a midi.Message")
|
||||||
}
|
}
|
||||||
|
|
||||||
return payloadMessage.Bytes(), nil
|
wrappedPayload.Payload = payloadMessage.Bytes()
|
||||||
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mme *MIDIMessageEncode) Type() string {
|
func (mme *MIDIMessageEncode) Type() string {
|
||||||
@@ -30,7 +34,8 @@ func (mme *MIDIMessageEncode) Type() string {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterProcessor(ProcessorRegistration{
|
RegisterProcessor(ProcessorRegistration{
|
||||||
Type: "midi.message.encode",
|
Type: "midi.message.encode",
|
||||||
|
Title: "Encode MIDI Message",
|
||||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
return &MIDIMessageEncode{config: config}, nil
|
return &MIDIMessageEncode{config: config}, nil
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
//go:build cgo
|
|
||||||
|
|
||||||
package processor
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
|
||||||
"gitlab.com/gomidi/midi/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type MIDIMessageFilter struct {
|
|
||||||
config config.ProcessorConfig
|
|
||||||
MIDIType string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mmf *MIDIMessageFilter) Process(ctx context.Context, payload any) (any, error) {
|
|
||||||
payloadMessage, ok := payload.(midi.Message)
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("midi.message.filter processor only accepts a midi.Message")
|
|
||||||
}
|
|
||||||
|
|
||||||
if payloadMessage.Type().String() != mmf.MIDIType {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return payloadMessage, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mmf *MIDIMessageFilter) Type() string {
|
|
||||||
return mmf.config.Type
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
RegisterProcessor(ProcessorRegistration{
|
|
||||||
Type: "midi.message.filter",
|
|
||||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
|
||||||
params := config.Params
|
|
||||||
msgTypeString, err := params.GetString("type")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("midi.message.filter type error: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &MIDIMessageFilter{config: config, MIDIType: msgTypeString}, nil
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"gitlab.com/gomidi/midi/v2"
|
"gitlab.com/gomidi/midi/v2"
|
||||||
)
|
)
|
||||||
@@ -44,36 +45,44 @@ type MIDIPitchBend struct {
|
|||||||
Absolute uint16
|
Absolute uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mmu *MIDIMessageUnpack) Process(ctx context.Context, payload any) (any, error) {
|
func (mmu *MIDIMessageUnpack) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
payloadMidi, ok := payload.(midi.Message)
|
payload := wrappedPayload.Payload
|
||||||
|
payloadMidi, ok := common.GetAnyAs[midi.Message](payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("midi.message.unpack processor only accepts a midi.Message")
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, errors.New("midi.message.unpack processor only accepts a midi.Message")
|
||||||
}
|
}
|
||||||
|
|
||||||
switch payloadMidi.Type() {
|
switch payloadMidi.Type() {
|
||||||
case midi.NoteOnMsg:
|
case midi.NoteOnMsg:
|
||||||
noteOnMsg := MIDINoteOn{}
|
noteOnMsg := MIDINoteOn{}
|
||||||
payloadMidi.GetNoteOn(¬eOnMsg.Channel, ¬eOnMsg.Note, ¬eOnMsg.Velocity)
|
payloadMidi.GetNoteOn(¬eOnMsg.Channel, ¬eOnMsg.Note, ¬eOnMsg.Velocity)
|
||||||
return noteOnMsg, nil
|
wrappedPayload.Payload = noteOnMsg
|
||||||
|
return wrappedPayload, nil
|
||||||
case midi.NoteOffMsg:
|
case midi.NoteOffMsg:
|
||||||
noteOffMsg := MIDINoteOff{}
|
noteOffMsg := MIDINoteOff{}
|
||||||
payloadMidi.GetNoteOff(¬eOffMsg.Channel, ¬eOffMsg.Note, ¬eOffMsg.Velocity)
|
payloadMidi.GetNoteOff(¬eOffMsg.Channel, ¬eOffMsg.Note, ¬eOffMsg.Velocity)
|
||||||
return noteOffMsg, nil
|
wrappedPayload.Payload = noteOffMsg
|
||||||
|
return wrappedPayload, nil
|
||||||
case midi.ControlChangeMsg:
|
case midi.ControlChangeMsg:
|
||||||
controlChangeMsg := MIDIControlChange{}
|
controlChangeMsg := MIDIControlChange{}
|
||||||
payloadMidi.GetControlChange(&controlChangeMsg.Channel, &controlChangeMsg.Control, &controlChangeMsg.Value)
|
payloadMidi.GetControlChange(&controlChangeMsg.Channel, &controlChangeMsg.Control, &controlChangeMsg.Value)
|
||||||
return controlChangeMsg, nil
|
wrappedPayload.Payload = controlChangeMsg
|
||||||
|
return wrappedPayload, nil
|
||||||
case midi.ProgramChangeMsg:
|
case midi.ProgramChangeMsg:
|
||||||
programChangeMsg := MIDIProgramChange{}
|
programChangeMsg := MIDIProgramChange{}
|
||||||
payloadMidi.GetProgramChange(&programChangeMsg.Channel, &programChangeMsg.Program)
|
payloadMidi.GetProgramChange(&programChangeMsg.Channel, &programChangeMsg.Program)
|
||||||
return programChangeMsg, nil
|
wrappedPayload.Payload = programChangeMsg
|
||||||
|
return wrappedPayload, nil
|
||||||
case midi.PitchBendMsg:
|
case midi.PitchBendMsg:
|
||||||
pitchBendMsg := MIDIPitchBend{}
|
pitchBendMsg := MIDIPitchBend{}
|
||||||
payloadMidi.GetPitchBend(&pitchBendMsg.Channel, &pitchBendMsg.Relative, &pitchBendMsg.Absolute)
|
payloadMidi.GetPitchBend(&pitchBendMsg.Channel, &pitchBendMsg.Relative, &pitchBendMsg.Absolute)
|
||||||
return pitchBendMsg, nil
|
wrappedPayload.Payload = pitchBendMsg
|
||||||
|
return wrappedPayload, nil
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("midi.message.unpack message type not supported %v", payloadMidi.Type())
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, fmt.Errorf("midi.message.unpack message type not supported %v", payloadMidi.Type())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +92,8 @@ func (mmu *MIDIMessageUnpack) Type() string {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterProcessor(ProcessorRegistration{
|
RegisterProcessor(ProcessorRegistration{
|
||||||
Type: "midi.message.unpack",
|
Type: "midi.message.unpack",
|
||||||
|
Title: "Unpack MIDI Message",
|
||||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
return &MIDIMessageUnpack{config: config}, nil
|
return &MIDIMessageUnpack{config: config}, nil
|
||||||
},
|
},
|
||||||
|
|||||||
132
internal/processor/midi-note_off-create.go
Normal file
132
internal/processor/midi-note_off-create.go
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
//go:build cgo
|
||||||
|
|
||||||
|
package processor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"gitlab.com/gomidi/midi/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MIDINoteOffCreate struct {
|
||||||
|
config config.ProcessorConfig
|
||||||
|
Channel *template.Template
|
||||||
|
Note *template.Template
|
||||||
|
Velocity *template.Template
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mnoc *MIDINoteOffCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
templateData := wrappedPayload
|
||||||
|
|
||||||
|
var channelBuffer bytes.Buffer
|
||||||
|
err := mnoc.Channel.Execute(&channelBuffer, templateData)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
|
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
||||||
|
|
||||||
|
var noteBuffer bytes.Buffer
|
||||||
|
err = mnoc.Note.Execute(¬eBuffer, templateData)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
|
noteValue, err := strconv.ParseUint(noteBuffer.String(), 10, 8)
|
||||||
|
|
||||||
|
var velocityBuffer bytes.Buffer
|
||||||
|
err = mnoc.Velocity.Execute(&velocityBuffer, templateData)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
|
velocityValue, err := strconv.ParseUint(velocityBuffer.String(), 10, 8)
|
||||||
|
payloadMessage := midi.NoteOffVelocity(uint8(channelValue), uint8(noteValue), uint8(velocityValue))
|
||||||
|
wrappedPayload.Payload = payloadMessage
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mnoc *MIDINoteOffCreate) Type() string {
|
||||||
|
return mnoc.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterProcessor(ProcessorRegistration{
|
||||||
|
Type: "midi.note_off.create",
|
||||||
|
Title: "Create MIDI Note Off Message",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"channel": {
|
||||||
|
Title: "Channel",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"note": {
|
||||||
|
Title: "Note",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"velocity": {
|
||||||
|
Title: "Velocity",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"channel", "note", "velocity"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
|
params := config.Params
|
||||||
|
|
||||||
|
channelString, err := params.GetString("channel")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("midi.note_off.create channel error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
channelTemplate, err := template.New("channel").Parse(channelString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
noteString, err := params.GetString("note")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("midi.note_off.create note error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
noteTemplate, err := template.New("note").Parse(noteString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
velocityString, err := params.GetString("velocity")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("midi.note_off.create velocity error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
velocityTemplate, err := template.New("velocity").Parse(velocityString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &MIDINoteOffCreate{
|
||||||
|
config: config,
|
||||||
|
Channel: channelTemplate,
|
||||||
|
Note: noteTemplate,
|
||||||
|
Velocity: velocityTemplate,
|
||||||
|
}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
132
internal/processor/midi-note_on-create.go
Normal file
132
internal/processor/midi-note_on-create.go
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
//go:build cgo
|
||||||
|
|
||||||
|
package processor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"gitlab.com/gomidi/midi/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MIDINoteOnCreate struct {
|
||||||
|
config config.ProcessorConfig
|
||||||
|
Channel *template.Template
|
||||||
|
Note *template.Template
|
||||||
|
Velocity *template.Template
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mnoc *MIDINoteOnCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
templateData := wrappedPayload
|
||||||
|
|
||||||
|
var channelBuffer bytes.Buffer
|
||||||
|
err := mnoc.Channel.Execute(&channelBuffer, templateData)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
|
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
||||||
|
|
||||||
|
var noteBuffer bytes.Buffer
|
||||||
|
err = mnoc.Note.Execute(¬eBuffer, templateData)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
|
noteValue, err := strconv.ParseUint(noteBuffer.String(), 10, 8)
|
||||||
|
|
||||||
|
var velocityBuffer bytes.Buffer
|
||||||
|
err = mnoc.Velocity.Execute(&velocityBuffer, templateData)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
|
velocityValue, err := strconv.ParseUint(velocityBuffer.String(), 10, 8)
|
||||||
|
payloadMessage := midi.NoteOn(uint8(channelValue), uint8(noteValue), uint8(velocityValue))
|
||||||
|
wrappedPayload.Payload = payloadMessage
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mnoc *MIDINoteOnCreate) Type() string {
|
||||||
|
return mnoc.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterProcessor(ProcessorRegistration{
|
||||||
|
Type: "midi.note_on.create",
|
||||||
|
Title: "Create MIDI Note On Message",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"channel": {
|
||||||
|
Title: "Channel",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"note": {
|
||||||
|
Title: "Note",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"velocity": {
|
||||||
|
Title: "Velocity",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"channel", "note", "velocity"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
|
params := config.Params
|
||||||
|
|
||||||
|
channelString, err := params.GetString("channel")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("midi.note_on.create channel error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
channelTemplate, err := template.New("channel").Parse(channelString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
noteString, err := params.GetString("note")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("midi.note_on.create note error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
noteTemplate, err := template.New("note").Parse(noteString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
velocityString, err := params.GetString("velocity")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("midi.note_on.create velocity error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
velocityTemplate, err := template.New("velocity").Parse(velocityString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &MIDINoteOnCreate{
|
||||||
|
config: config,
|
||||||
|
Channel: channelTemplate,
|
||||||
|
Note: noteTemplate,
|
||||||
|
Velocity: velocityTemplate,
|
||||||
|
}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
106
internal/processor/midi-program_change-create.go
Normal file
106
internal/processor/midi-program_change-create.go
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
//go:build cgo
|
||||||
|
|
||||||
|
package processor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"gitlab.com/gomidi/midi/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MIDIProgramChangeCreate struct {
|
||||||
|
config config.ProcessorConfig
|
||||||
|
Channel *template.Template
|
||||||
|
Program *template.Template
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mpcc *MIDIProgramChangeCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
|
templateData := wrappedPayload
|
||||||
|
|
||||||
|
var channelBuffer bytes.Buffer
|
||||||
|
err := mpcc.Channel.Execute(&channelBuffer, templateData)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
|
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
||||||
|
|
||||||
|
var programBuffer bytes.Buffer
|
||||||
|
err = mpcc.Program.Execute(&programBuffer, templateData)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
|
programValue, err := strconv.ParseUint(programBuffer.String(), 10, 8)
|
||||||
|
|
||||||
|
payloadMessage := midi.ProgramChange(uint8(channelValue), uint8(programValue))
|
||||||
|
wrappedPayload.Payload = payloadMessage
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mpcc *MIDIProgramChangeCreate) Type() string {
|
||||||
|
return mpcc.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterProcessor(ProcessorRegistration{
|
||||||
|
Type: "midi.program_change.create",
|
||||||
|
Title: "Create MIDI Prgoram Change Message",
|
||||||
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"channel": {
|
||||||
|
Title: "Channel",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"program": {
|
||||||
|
Title: "Program",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"type", "channel", "program"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
|
params := config.Params
|
||||||
|
|
||||||
|
channelString, err := params.GetString("channel")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("midi.program_change.create channel error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
channelTemplate, err := template.New("channel").Parse(channelString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
programString, err := params.GetString("program")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("midi.program_change.create program error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
programTemplate, err := template.New("program").Parse(programString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &MIDIProgramChangeCreate{
|
||||||
|
config: config,
|
||||||
|
Channel: channelTemplate,
|
||||||
|
Program: programTemplate,
|
||||||
|
}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -5,6 +5,8 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/google/jsonschema-go/jsonschema"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -60,17 +62,17 @@ func (mm MQTTMessage) Payload() []byte {
|
|||||||
|
|
||||||
func (mm MQTTMessage) Ack() {}
|
func (mm MQTTMessage) Ack() {}
|
||||||
|
|
||||||
func (mmc *MQTTMessageCreate) Process(ctx context.Context, payload any) (any, error) {
|
func (mmc *MQTTMessageCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||||
// TODO(jwetzell): support templating
|
// TODO(jwetzell): support templating
|
||||||
|
|
||||||
message := MQTTMessage{
|
wrappedPayload.Payload = MQTTMessage{
|
||||||
topic: mmc.Topic,
|
topic: mmc.Topic,
|
||||||
qos: mmc.QoS,
|
qos: mmc.QoS,
|
||||||
retained: mmc.Retained,
|
retained: mmc.Retained,
|
||||||
payload: mmc.Payload,
|
payload: mmc.Payload,
|
||||||
}
|
}
|
||||||
|
|
||||||
return message, nil
|
return wrappedPayload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mmc *MQTTMessageCreate) Type() string {
|
func (mmc *MQTTMessageCreate) Type() string {
|
||||||
@@ -79,9 +81,33 @@ func (mmc *MQTTMessageCreate) Type() string {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterProcessor(ProcessorRegistration{
|
RegisterProcessor(ProcessorRegistration{
|
||||||
Type: "mqtt.message.create",
|
Type: "mqtt.message.create",
|
||||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
Title: "Create MQTT Message",
|
||||||
params := config.Params
|
ParamsSchema: &jsonschema.Schema{
|
||||||
|
Type: "object",
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"topic": {
|
||||||
|
Title: "Topic",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"qos": {
|
||||||
|
Title: "QoS",
|
||||||
|
Type: "number",
|
||||||
|
},
|
||||||
|
"retained": {
|
||||||
|
Title: "Retained",
|
||||||
|
Type: "boolean",
|
||||||
|
},
|
||||||
|
"payload": {
|
||||||
|
Title: "Payload",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"topic", "qos", "retained", "payload"},
|
||||||
|
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||||
|
},
|
||||||
|
New: func(processorConfig config.ProcessorConfig) (Processor, error) {
|
||||||
|
params := processorConfig.Params
|
||||||
topicString, err := params.GetString("topic")
|
topicString, err := params.GetString("topic")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("mqtt.message.create topic error: %w", err)
|
return nil, fmt.Errorf("mqtt.message.create topic error: %w", err)
|
||||||
@@ -98,25 +124,22 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO(jwetzell): convert payload into []byte or string for sending
|
//TODO(jwetzell): convert payload into []byte or string for sending
|
||||||
payload, ok := params["payload"]
|
payloadString, err := params.GetString("payload")
|
||||||
|
if err != nil {
|
||||||
if !ok {
|
if errors.Is(err, config.ErrParamNotString) {
|
||||||
return nil, errors.New("mqtt.message.create payload error: not found")
|
payloadBytes, err := params.GetByteSlice("payload")
|
||||||
}
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("mqtt.message.create payload error: %w", err)
|
||||||
if payloadBytes, ok := payload.([]byte); ok {
|
}
|
||||||
return &MQTTMessageCreate{config: config, Topic: topicString, QoS: byte(qosByte), Retained: retainedBool, Payload: payloadBytes}, nil
|
return &MQTTMessageCreate{config: processorConfig, Topic: topicString, QoS: byte(qosByte), Retained: retainedBool, Payload: payloadBytes}, nil
|
||||||
}
|
} else {
|
||||||
|
return nil, fmt.Errorf("mqtt.message.create payload error: %w", err)
|
||||||
payloadString, ok := payload.(string)
|
}
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("mqtt.message.create payload error: not a string or byte array")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadBytes := []byte(payloadString)
|
payloadBytes := []byte(payloadString)
|
||||||
|
|
||||||
return &MQTTMessageCreate{config: config, Topic: topicString, QoS: byte(qosByte), Retained: retainedBool, Payload: payloadBytes}, nil
|
return &MQTTMessageCreate{config: processorConfig, Topic: topicString, QoS: byte(qosByte), Retained: retainedBool, Payload: payloadBytes}, nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user