move init functions to top of file

This commit is contained in:
Joel Wetzell
2026-05-22 17:45:03 -05:00
parent fb3c775765
commit 4323a21015
67 changed files with 1706 additions and 1706 deletions
+11 -11
View File
@@ -9,6 +9,16 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "artnet.packet.decode",
Title: "Decode ArtNet Packet",
New: func(config config.ProcessorConfig) (Processor, error) {
return &ArtNetPacketDecode{config: config}, nil
},
})
}
type ArtNetPacketDecode struct {
config config.ProcessorConfig
}
@@ -36,14 +46,4 @@ func (apd *ArtNetPacketDecode) Process(ctx context.Context, wrappedPayload commo
func (apd *ArtNetPacketDecode) Type() string {
return apd.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "artnet.packet.decode",
Title: "Decode ArtNet Packet",
New: func(config config.ProcessorConfig) (Processor, error) {
return &ArtNetPacketDecode{config: config}, nil
},
})
}
}
+10 -10
View File
@@ -9,6 +9,16 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "artnet.packet.encode",
Title: "Encode ArtNet Packet",
New: func(config config.ProcessorConfig) (Processor, error) {
return &ArtNetPacketEncode{config: config}, nil
},
})
}
type ArtNetPacketEncode struct {
config config.ProcessorConfig
}
@@ -36,13 +46,3 @@ func (ape *ArtNetPacketEncode) Process(ctx context.Context, wrappedPayload commo
func (ape *ArtNetPacketEncode) Type() string {
return ape.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "artnet.packet.encode",
Title: "Encode ArtNet Packet",
New: func(config config.ProcessorConfig) (Processor, error) {
return &ArtNetPacketEncode{config: config}, nil
},
})
}
+45 -45
View File
@@ -13,6 +13,51 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "db.query",
Title: "Query Database",
ParamsSchema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"module": {
Title: "Module ID",
Type: "string",
Description: "ID of the database module to query",
},
"query": {
Title: "Query",
Type: "string",
Description: "SQL query to execute",
},
},
Required: []string{"module", "query"},
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("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
},
})
}
type DbQuery struct {
config config.ProcessorConfig
ModuleId string
@@ -101,48 +146,3 @@ func (dq *DbQuery) Process(ctx context.Context, wrappedPayload common.WrappedPay
func (dq *DbQuery) Type() string {
return dq.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "db.query",
Title: "Query Database",
ParamsSchema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"module": {
Title: "Module ID",
Type: "string",
Description: "ID of the database module to query",
},
"query": {
Title: "Query",
Type: "string",
Description: "SQL query to execute",
},
},
Required: []string{"module", "query"},
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("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
},
})
}
+10 -10
View File
@@ -9,13 +9,22 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
// TODO(jwetzell): maybe make a more useful logging processor
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "debug.log",
Title: "Debug Log",
New: func(config config.ProcessorConfig) (Processor, error) {
return &DebugLog{config: config, logger: slog.Default().With("component", "processor", "type", config.Type)}, nil
},
})
}
type DebugLog struct {
config config.ProcessorConfig
logger *slog.Logger
}
// TODO(jwetzell): maybe make a more useful logging processor
func (dl *DebugLog) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
payload := wrappedPayload.Payload
payloadString := fmt.Sprintf("%+v", payload)
@@ -28,12 +37,3 @@ func (dl *DebugLog) Type() string {
return dl.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "debug.log",
Title: "Debug Log",
New: func(config config.ProcessorConfig) (Processor, error) {
return &DebugLog{config: config, logger: slog.Default().With("component", "processor", "type", config.Type)}, nil
},
})
}
+10 -10
View File
@@ -8,6 +8,16 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "filter.change",
Title: "Filter On Change",
New: func(config config.ProcessorConfig) (Processor, error) {
return &FilterChange{config: config}, nil
},
})
}
type FilterChange struct {
config config.ProcessorConfig
previous any
@@ -28,13 +38,3 @@ func (fc *FilterChange) Process(ctx context.Context, wrappedPayload common.Wrapp
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
},
})
}
+33 -33
View File
@@ -11,6 +11,39 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
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
},
})
}
// NOTE(jwetzell): see language definition https://expr-lang.org/docs/language-definition
type FilterExpr struct {
config config.ProcessorConfig
@@ -45,36 +78,3 @@ func (fe *FilterExpr) Process(ctx context.Context, wrappedPayload common.Wrapped
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
},
})
}
+27 -27
View File
@@ -11,33 +11,6 @@ import (
"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",
@@ -71,3 +44,30 @@ func init() {
},
})
}
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
}
+27 -27
View File
@@ -12,33 +12,6 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
type FloatParse struct {
BitSize int
config config.ProcessorConfig
}
func (fp *FloatParse) 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("float.parse processor only accepts a string")
}
payloadFloat, err := strconv.ParseFloat(payloadString, fp.BitSize)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
wrappedPayload.Payload = payloadFloat
return wrappedPayload, nil
}
func (fp *FloatParse) Type() string {
return fp.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "float.parse",
@@ -70,3 +43,30 @@ func init() {
},
})
}
type FloatParse struct {
BitSize int
config config.ProcessorConfig
}
func (fp *FloatParse) 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("float.parse processor only accepts a string")
}
payloadFloat, err := strconv.ParseFloat(payloadString, fp.BitSize)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
wrappedPayload.Payload = payloadFloat
return wrappedPayload, nil
}
func (fp *FloatParse) Type() string {
return fp.config.Type
}
+26 -26
View File
@@ -12,32 +12,6 @@ import (
"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",
@@ -97,3 +71,29 @@ func init() {
},
})
}
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
}
+175 -175
View File
@@ -13,6 +13,181 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
func init() {
RegisterProcessor(ProcessorRegistration{
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) {
// TODO(jwetzell): make some params optional
params := config.Params
idString, err := params.GetString("id")
if err != nil {
return nil, fmt.Errorf("freed.create id error: %w", err)
}
idTemplate, err := template.New("id").Parse(idString)
if err != nil {
return nil, err
}
panString, err := params.GetString("pan")
if err != nil {
return nil, fmt.Errorf("freed.create pan error: %w", err)
}
panTemplate, err := template.New("pan").Parse(panString)
if err != nil {
return nil, err
}
tiltString, err := params.GetString("tilt")
if err != nil {
return nil, fmt.Errorf("freed.create tilt error: %w", err)
}
tiltTemplate, err := template.New("tilt").Parse(tiltString)
if err != nil {
return nil, err
}
rollString, err := params.GetString("roll")
if err != nil {
return nil, fmt.Errorf("freed.create roll error: %w", err)
}
rollTemplate, err := template.New("roll").Parse(rollString)
if err != nil {
return nil, err
}
posXString, err := params.GetString("posX")
if err != nil {
return nil, fmt.Errorf("freed.create posX error: %w", err)
}
posXTemplate, err := template.New("posX").Parse(posXString)
if err != nil {
return nil, err
}
posYString, err := params.GetString("posY")
if err != nil {
return nil, fmt.Errorf("freed.create posY error: %w", err)
}
posYTemplate, err := template.New("posY").Parse(posYString)
if err != nil {
return nil, err
}
posZString, err := params.GetString("posZ")
if err != nil {
return nil, fmt.Errorf("freed.create posZ error: %w", err)
}
posZTemplate, err := template.New("posZ").Parse(posZString)
if err != nil {
return nil, err
}
zoomString, err := params.GetString("zoom")
if err != nil {
return nil, fmt.Errorf("freed.create zoom error: %w", err)
}
zoomTemplate, err := template.New("zoom").Parse(zoomString)
if err != nil {
return nil, err
}
focusString, err := params.GetString("focus")
if err != nil {
return nil, fmt.Errorf("freed.create focus error: %w", err)
}
focusTemplate, err := template.New("focus").Parse(focusString)
if err != nil {
return nil, err
}
return &FreeDCreate{
config: config,
Id: idTemplate,
Pan: panTemplate,
Tilt: tiltTemplate,
Roll: rollTemplate,
PosX: posXTemplate,
PosY: posYTemplate,
PosZ: posZTemplate,
Zoom: zoomTemplate,
Focus: focusTemplate,
}, nil
},
})
}
type FreeDCreate struct {
config config.ProcessorConfig
Id *template.Template
@@ -203,178 +378,3 @@ func (fc *FreeDCreate) Process(ctx context.Context, wrappedPayload common.Wrappe
func (fc *FreeDCreate) Type() string {
return fc.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
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) {
// TODO(jwetzell): make some params optional
params := config.Params
idString, err := params.GetString("id")
if err != nil {
return nil, fmt.Errorf("freed.create id error: %w", err)
}
idTemplate, err := template.New("id").Parse(idString)
if err != nil {
return nil, err
}
panString, err := params.GetString("pan")
if err != nil {
return nil, fmt.Errorf("freed.create pan error: %w", err)
}
panTemplate, err := template.New("pan").Parse(panString)
if err != nil {
return nil, err
}
tiltString, err := params.GetString("tilt")
if err != nil {
return nil, fmt.Errorf("freed.create tilt error: %w", err)
}
tiltTemplate, err := template.New("tilt").Parse(tiltString)
if err != nil {
return nil, err
}
rollString, err := params.GetString("roll")
if err != nil {
return nil, fmt.Errorf("freed.create roll error: %w", err)
}
rollTemplate, err := template.New("roll").Parse(rollString)
if err != nil {
return nil, err
}
posXString, err := params.GetString("posX")
if err != nil {
return nil, fmt.Errorf("freed.create posX error: %w", err)
}
posXTemplate, err := template.New("posX").Parse(posXString)
if err != nil {
return nil, err
}
posYString, err := params.GetString("posY")
if err != nil {
return nil, fmt.Errorf("freed.create posY error: %w", err)
}
posYTemplate, err := template.New("posY").Parse(posYString)
if err != nil {
return nil, err
}
posZString, err := params.GetString("posZ")
if err != nil {
return nil, fmt.Errorf("freed.create posZ error: %w", err)
}
posZTemplate, err := template.New("posZ").Parse(posZString)
if err != nil {
return nil, err
}
zoomString, err := params.GetString("zoom")
if err != nil {
return nil, fmt.Errorf("freed.create zoom error: %w", err)
}
zoomTemplate, err := template.New("zoom").Parse(zoomString)
if err != nil {
return nil, err
}
focusString, err := params.GetString("focus")
if err != nil {
return nil, fmt.Errorf("freed.create focus error: %w", err)
}
focusTemplate, err := template.New("focus").Parse(focusString)
if err != nil {
return nil, err
}
return &FreeDCreate{
config: config,
Id: idTemplate,
Pan: panTemplate,
Tilt: tiltTemplate,
Roll: rollTemplate,
PosX: posXTemplate,
PosY: posYTemplate,
PosZ: posZTemplate,
Zoom: zoomTemplate,
Focus: focusTemplate,
}, nil
},
})
}
+11 -11
View File
@@ -9,10 +9,20 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "freed.decode",
Title: "Decode FreeD",
New: func(config config.ProcessorConfig) (Processor, error) {
return &FreeDDecode{config: config}, nil
},
})
}
type FreeDDecode struct {
config config.ProcessorConfig
}
func (fd *FreeDDecode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
payload := wrappedPayload.Payload
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
@@ -34,13 +44,3 @@ func (fd *FreeDDecode) Process(ctx context.Context, wrappedPayload common.Wrappe
func (fd *FreeDDecode) Type() string {
return fd.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "freed.decode",
Title: "Decode FreeD",
New: func(config config.ProcessorConfig) (Processor, error) {
return &FreeDDecode{config: config}, nil
},
})
}
+10 -10
View File
@@ -9,6 +9,16 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "freed.encode",
Title: "Encode FreeD",
New: func(config config.ProcessorConfig) (Processor, error) {
return &FreeDEncode{config: config}, nil
},
})
}
type FreeDEncode struct {
config config.ProcessorConfig
}
@@ -31,13 +41,3 @@ func (fe *FreeDEncode) Process(ctx context.Context, wrappedPayload common.Wrappe
func (fe *FreeDEncode) Type() string {
return fe.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "freed.encode",
Title: "Encode FreeD",
New: func(config config.ProcessorConfig) (Processor, error) {
return &FreeDEncode{config: config}, nil
},
})
}
+47 -47
View File
@@ -14,6 +14,53 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
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
},
})
}
type HTTPRequestDo struct {
config config.ProcessorConfig
client *http.Client
@@ -68,50 +115,3 @@ func (hrd *HTTPRequestDo) Process(ctx context.Context, wrappedPayload common.Wra
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
},
})
}
+32 -32
View File
@@ -11,38 +11,6 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
type HTTPResponseCreate struct {
Status int
BodyTmpl *template.Template
config config.ProcessorConfig
}
type HTTPResponse struct {
Status int
Body []byte
}
func (hrc *HTTPResponseCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
templateData := wrappedPayload
var bodyBuffer bytes.Buffer
err := hrc.BodyTmpl.Execute(&bodyBuffer, templateData)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
wrappedPayload.Payload = HTTPResponse{
Status: hrc.Status,
Body: bodyBuffer.Bytes(),
}
return wrappedPayload, nil
}
func (hrc *HTTPResponseCreate) Type() string {
return hrc.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "http.response.create",
@@ -86,3 +54,35 @@ func init() {
},
})
}
type HTTPResponseCreate struct {
Status int
BodyTmpl *template.Template
config config.ProcessorConfig
}
type HTTPResponse struct {
Status int
Body []byte
}
func (hrc *HTTPResponseCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
templateData := wrappedPayload
var bodyBuffer bytes.Buffer
err := hrc.BodyTmpl.Execute(&bodyBuffer, templateData)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
wrappedPayload.Payload = HTTPResponse{
Status: hrc.Status,
Body: bodyBuffer.Bytes(),
}
return wrappedPayload, nil
}
func (hrc *HTTPResponseCreate) Type() string {
return hrc.config.Type
}
+28 -28
View File
@@ -12,34 +12,6 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
type IntParse struct {
Base int
BitSize int
config config.ProcessorConfig
}
func (ip *IntParse) 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("int.parse processor only accepts a string")
}
payloadInt, err := strconv.ParseInt(payloadString, ip.Base, ip.BitSize)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
wrappedPayload.Payload = payloadInt
return wrappedPayload, nil
}
func (ip *IntParse) Type() string {
return ip.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "int.parse",
@@ -86,3 +58,31 @@ func init() {
},
})
}
type IntParse struct {
Base int
BitSize int
config config.ProcessorConfig
}
func (ip *IntParse) 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("int.parse processor only accepts a string")
}
payloadInt, err := strconv.ParseInt(payloadString, ip.Base, ip.BitSize)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
wrappedPayload.Payload = payloadInt
return wrappedPayload, nil
}
func (ip *IntParse) Type() string {
return ip.config.Type
}
+16 -16
View File
@@ -11,22 +11,6 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
type IntRandom struct {
Min int
Max int
config config.ProcessorConfig
}
func (ir *IntRandom) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
payloadInt := rand.IntN(ir.Max-ir.Min+1) + ir.Min
wrappedPayload.Payload = payloadInt
return wrappedPayload, nil
}
func (ir *IntRandom) Type() string {
return ir.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "int.random",
@@ -67,3 +51,19 @@ func init() {
},
})
}
type IntRandom struct {
Min int
Max int
config config.ProcessorConfig
}
func (ir *IntRandom) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
payloadInt := rand.IntN(ir.Max-ir.Min+1) + ir.Min
wrappedPayload.Payload = payloadInt
return wrappedPayload, nil
}
func (ir *IntRandom) Type() string {
return ir.config.Type
}
+25 -25
View File
@@ -10,31 +10,6 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
type IntScale struct {
OutMin int
OutMax int
InMin int
InMax int
config config.ProcessorConfig
}
func (is *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-is.InMin)*(is.OutMax-is.OutMin)/(is.InMax-is.InMin) + is.OutMin
wrappedPayload.Payload = payloadInt
return wrappedPayload, nil
}
func (is *IntScale) Type() string {
return is.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "int.scale",
@@ -97,3 +72,28 @@ func init() {
},
})
}
type IntScale struct {
OutMin int
OutMax int
InMin int
InMax int
config config.ProcessorConfig
}
func (is *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-is.InMin)*(is.OutMax-is.OutMin)/(is.InMax-is.InMin) + is.OutMin
wrappedPayload.Payload = payloadInt
return wrappedPayload, nil
}
func (is *IntScale) Type() string {
return is.config.Type
}
+10 -10
View File
@@ -9,6 +9,16 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "json.decode",
Title: "Decode JSON",
New: func(config config.ProcessorConfig) (Processor, error) {
return &JsonDecode{config: config}, nil
},
})
}
type JsonDecode struct {
config config.ProcessorConfig
}
@@ -43,13 +53,3 @@ func (jd *JsonDecode) Process(ctx context.Context, wrappedPayload common.Wrapped
func (jd *JsonDecode) Type() string {
return jd.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "json.decode",
Title: "Decode JSON",
New: func(config config.ProcessorConfig) (Processor, error) {
return &JsonDecode{config: config}, nil
},
})
}
+10 -10
View File
@@ -9,6 +9,16 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "json.encode",
Title: "Encode JSON",
New: func(config config.ProcessorConfig) (Processor, error) {
return &JsonEncode{config: config}, nil
},
})
}
type JsonEncode struct {
config config.ProcessorConfig
}
@@ -35,13 +45,3 @@ func (je *JsonEncode) Process(ctx context.Context, wrappedPayload common.Wrapped
func (je *JsonEncode) Type() string {
return je.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "json.encode",
Title: "Encode JSON",
New: func(config config.ProcessorConfig) (Processor, error) {
return &JsonEncode{config: config}, nil
},
})
}
+37 -37
View File
@@ -11,6 +11,43 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
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
},
})
}
type KVGet struct {
config config.ProcessorConfig
ModuleId string
@@ -53,40 +90,3 @@ func (kvg *KVGet) Process(ctx context.Context, wrappedPayload common.WrappedPayl
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
},
})
}
+38 -38
View File
@@ -11,6 +11,44 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
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",
},
},
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.set module error: %w", err)
}
keyString, err := params.GetString("key")
if err != nil {
return nil, fmt.Errorf("kv.set key error: %w", err)
}
return &KVSet{config: config, ModuleId: moduleIdString, Key: keyString, logger: slog.Default().With("component", "processor", "type", config.Type)}, nil
},
})
}
type KVSet struct {
config config.ProcessorConfig
ModuleId string
@@ -52,41 +90,3 @@ func (kvs *KVSet) Process(ctx context.Context, wrappedPayload common.WrappedPayl
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",
},
},
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.set module error: %w", err)
}
keyString, err := params.GetString("key")
if err != nil {
return nil, fmt.Errorf("kv.set key error: %w", err)
}
return &KVSet{config: config, ModuleId: moduleIdString, Key: keyString, logger: slog.Default().With("component", "processor", "type", config.Type)}, nil
},
})
}
@@ -15,70 +15,6 @@ import (
"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)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
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)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
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)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
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",
@@ -147,3 +83,67 @@ func init() {
},
})
}
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)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
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)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
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)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
payloadMessage := midi.ControlChange(uint8(channelValue), uint8(controlValue), uint8(valueValue))
wrappedPayload.Payload = payloadMessage
return wrappedPayload, nil
}
func (mccc *MIDIControlChangeCreate) Type() string {
return mccc.config.Type
}
+10 -10
View File
@@ -11,6 +11,16 @@ import (
"gitlab.com/gomidi/midi/v2"
)
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "midi.message.decode",
Title: "Decode MIDI Message",
New: func(config config.ProcessorConfig) (Processor, error) {
return &MIDIMessageDecode{config: config}, nil
},
})
}
type MIDIMessageDecode struct {
config config.ProcessorConfig
}
@@ -33,13 +43,3 @@ func (mmd *MIDIMessageDecode) Process(ctx context.Context, wrappedPayload common
func (mmd *MIDIMessageDecode) Type() string {
return mmd.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "midi.message.decode",
Title: "Decode MIDI Message",
New: func(config config.ProcessorConfig) (Processor, error) {
return &MIDIMessageDecode{config: config}, nil
},
})
}
+10 -10
View File
@@ -11,6 +11,16 @@ import (
"gitlab.com/gomidi/midi/v2"
)
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "midi.message.encode",
Title: "Encode MIDI Message",
New: func(config config.ProcessorConfig) (Processor, error) {
return &MIDIMessageEncode{config: config}, nil
},
})
}
type MIDIMessageEncode struct {
config config.ProcessorConfig
}
@@ -31,13 +41,3 @@ func (mme *MIDIMessageEncode) Process(ctx context.Context, wrappedPayload common
func (mme *MIDIMessageEncode) Type() string {
return mme.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "midi.message.encode",
Title: "Encode MIDI Message",
New: func(config config.ProcessorConfig) (Processor, error) {
return &MIDIMessageEncode{config: config}, nil
},
})
}
+10 -10
View File
@@ -12,6 +12,16 @@ import (
"gitlab.com/gomidi/midi/v2"
)
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "midi.message.unpack",
Title: "Unpack MIDI Message",
New: func(config config.ProcessorConfig) (Processor, error) {
return &MIDIMessageUnpack{config: config}, nil
},
})
}
type MIDIMessageUnpack struct {
config config.ProcessorConfig
}
@@ -89,13 +99,3 @@ func (mmu *MIDIMessageUnpack) Process(ctx context.Context, wrappedPayload common
func (mmu *MIDIMessageUnpack) Type() string {
return mmu.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "midi.message.unpack",
Title: "Unpack MIDI Message",
New: func(config config.ProcessorConfig) (Processor, error) {
return &MIDIMessageUnpack{config: config}, nil
},
})
}
+64 -64
View File
@@ -15,70 +15,6 @@ import (
"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)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
var noteBuffer bytes.Buffer
err = mnoc.Note.Execute(&noteBuffer, templateData)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
noteValue, err := strconv.ParseUint(noteBuffer.String(), 10, 8)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
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)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
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",
@@ -146,3 +82,67 @@ func init() {
},
})
}
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)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
var noteBuffer bytes.Buffer
err = mnoc.Note.Execute(&noteBuffer, templateData)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
noteValue, err := strconv.ParseUint(noteBuffer.String(), 10, 8)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
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)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
payloadMessage := midi.NoteOffVelocity(uint8(channelValue), uint8(noteValue), uint8(velocityValue))
wrappedPayload.Payload = payloadMessage
return wrappedPayload, nil
}
func (mnoc *MIDINoteOffCreate) Type() string {
return mnoc.config.Type
}
+63 -63
View File
@@ -15,69 +15,6 @@ import (
"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)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
var noteBuffer bytes.Buffer
err = mnoc.Note.Execute(&noteBuffer, templateData)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
noteValue, err := strconv.ParseUint(noteBuffer.String(), 10, 8)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
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)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
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",
@@ -145,3 +82,66 @@ func init() {
},
})
}
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)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
var noteBuffer bytes.Buffer
err = mnoc.Note.Execute(&noteBuffer, templateData)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
noteValue, err := strconv.ParseUint(noteBuffer.String(), 10, 8)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
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)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
payloadMessage := midi.NoteOn(uint8(channelValue), uint8(noteValue), uint8(velocityValue))
wrappedPayload.Payload = payloadMessage
return wrappedPayload, nil
}
func (mnoc *MIDINoteOnCreate) Type() string {
return mnoc.config.Type
}
@@ -15,54 +15,6 @@ import (
"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)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
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)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
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",
@@ -114,3 +66,51 @@ func init() {
},
})
}
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)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
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)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
payloadMessage := midi.ProgramChange(uint8(channelValue), uint8(programValue))
wrappedPayload.Payload = payloadMessage
return wrappedPayload, nil
}
func (mpcc *MIDIProgramChangeCreate) Type() string {
return mpcc.config.Type
}
+31 -31
View File
@@ -11,6 +11,37 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "module.output",
Title: "Module Output",
ParamsSchema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"module": {
Title: "Module ID",
Type: "string",
Description: "ID of module to send output to",
},
},
Required: []string{"module"},
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
},
New: func(config config.ProcessorConfig) (Processor, error) {
params := config.Params
moduleId, err := params.GetString("module")
if err != nil {
return nil, fmt.Errorf("module.output module error: %w", err)
}
return &ModuleOutput{config: config, ModuleId: moduleId, logger: slog.Default().With("component", "processor", "type", config.Type)}, nil
},
})
}
type ModuleOutput struct {
config config.ProcessorConfig
ModuleId string
@@ -53,34 +84,3 @@ func (mo *ModuleOutput) Process(ctx context.Context, wrappedPayload common.Wrapp
func (mo *ModuleOutput) Type() string {
return mo.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "module.output",
Title: "Module Output",
ParamsSchema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"module": {
Title: "Module ID",
Type: "string",
Description: "ID of module to send output to",
},
},
Required: []string{"module"},
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
},
New: func(config config.ProcessorConfig) (Processor, error) {
params := config.Params
moduleId, err := params.GetString("module")
if err != nil {
return nil, fmt.Errorf("module.output module error: %w", err)
}
return &ModuleOutput{config: config, ModuleId: moduleId, logger: slog.Default().With("component", "processor", "type", config.Type)}, nil
},
})
}
+70 -70
View File
@@ -15,76 +15,6 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
type OSCMessageCreate struct {
config config.ProcessorConfig
Address *template.Template
Args []*template.Template
Types string
}
func (omc *OSCMessageCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
templateData := wrappedPayload
var addressBuffer bytes.Buffer
err := omc.Address.Execute(&addressBuffer, templateData)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
addressString := addressBuffer.String()
if len(addressString) == 0 {
wrappedPayload.End = true
return wrappedPayload, errors.New("osc.message.create address must not be empty")
}
if addressString[0] != '/' {
wrappedPayload.End = true
return wrappedPayload, errors.New("osc.message.create address must start with '/'")
}
payloadMessage := &osc.OSCMessage{
Address: addressString,
}
args := []osc.OSCArg{}
for argIndex, argTemplate := range omc.Args {
var argBuffer bytes.Buffer
err := argTemplate.Execute(&argBuffer, templateData)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
argString := argBuffer.String()
typedArg, err := argToTypedArg(argString, omc.Types[argIndex])
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
args = append(args, typedArg)
}
if len(args) > 0 {
payloadMessage.Args = args
}
wrappedPayload.Payload = payloadMessage
return wrappedPayload, nil
}
func (omc *OSCMessageCreate) Type() string {
return omc.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "osc.message.create",
@@ -158,6 +88,76 @@ func init() {
})
}
type OSCMessageCreate struct {
config config.ProcessorConfig
Address *template.Template
Args []*template.Template
Types string
}
func (omc *OSCMessageCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
templateData := wrappedPayload
var addressBuffer bytes.Buffer
err := omc.Address.Execute(&addressBuffer, templateData)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
addressString := addressBuffer.String()
if len(addressString) == 0 {
wrappedPayload.End = true
return wrappedPayload, errors.New("osc.message.create address must not be empty")
}
if addressString[0] != '/' {
wrappedPayload.End = true
return wrappedPayload, errors.New("osc.message.create address must start with '/'")
}
payloadMessage := &osc.OSCMessage{
Address: addressString,
}
args := []osc.OSCArg{}
for argIndex, argTemplate := range omc.Args {
var argBuffer bytes.Buffer
err := argTemplate.Execute(&argBuffer, templateData)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
argString := argBuffer.String()
typedArg, err := argToTypedArg(argString, omc.Types[argIndex])
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
args = append(args, typedArg)
}
if len(args) > 0 {
payloadMessage.Args = args
}
wrappedPayload.Payload = payloadMessage
return wrappedPayload, nil
}
func (omc *OSCMessageCreate) Type() string {
return omc.config.Type
}
func argToTypedArg(rawArg string, oscType byte) (osc.OSCArg, error) {
switch oscType {
+10 -10
View File
@@ -10,6 +10,16 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "osc.message.decode",
Title: "Decode OSC Message",
New: func(config config.ProcessorConfig) (Processor, error) {
return &OSCMessageDecode{config: config}, nil
},
})
}
type OSCMessageDecode struct {
config config.ProcessorConfig
}
@@ -45,13 +55,3 @@ func (omd *OSCMessageDecode) Process(ctx context.Context, wrappedPayload common.
func (omd *OSCMessageDecode) Type() string {
return omd.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "osc.message.decode",
Title: "Decode OSC Message",
New: func(config config.ProcessorConfig) (Processor, error) {
return &OSCMessageDecode{config: config}, nil
},
})
}
+10 -10
View File
@@ -14,6 +14,16 @@ type OSCMessageEncode struct {
config config.ProcessorConfig
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "osc.message.encode",
Title: "Encode OSC Message",
New: func(config config.ProcessorConfig) (Processor, error) {
return &OSCMessageEncode{config: config}, nil
},
})
}
func (ome *OSCMessageEncode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
payload := wrappedPayload.Payload
payloadMessage, ok := common.GetAnyAs[*osc.OSCMessage](payload)
@@ -35,13 +45,3 @@ func (ome *OSCMessageEncode) Process(ctx context.Context, wrappedPayload common.
func (ome *OSCMessageEncode) Type() string {
return ome.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "osc.message.encode",
Title: "Encode OSC Message",
New: func(config config.ProcessorConfig) (Processor, error) {
return &OSCMessageEncode{config: config}, nil
},
})
}
+45 -45
View File
@@ -13,6 +13,51 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "pubsub.publish",
Title: "Publish to Pub/Sub Topic",
ParamsSchema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"module": {
Title: "Module ID",
Type: "string",
Description: "ID of the module to publish to",
},
"topic": {
Title: "Topic",
Type: "string",
Description: "Topic to publish to",
},
},
Required: []string{"module", "topic"},
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("pubsub.publish module error: %w", err)
}
topicString, err := params.GetString("topic")
if err != nil {
return nil, fmt.Errorf("pubsub.publish topic error: %w", err)
}
topicTemplate, err := template.New("topic").Parse(topicString)
if err != nil {
return nil, err
}
return &PubSubPublish{config: config, ModuleId: moduleIdString, Topic: topicTemplate, logger: slog.Default().With("component", "processor", "type", config.Type)}, nil
},
})
}
type PubSubPublish struct {
config config.ProcessorConfig
ModuleId string
@@ -62,48 +107,3 @@ func (psp *PubSubPublish) Process(ctx context.Context, wrappedPayload common.Wra
func (psp *PubSubPublish) Type() string {
return psp.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "pubsub.publish",
Title: "Publish to Pub/Sub Topic",
ParamsSchema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"module": {
Title: "Module ID",
Type: "string",
Description: "ID of the module to publish to",
},
"topic": {
Title: "Topic",
Type: "string",
Description: "Topic to publish to",
},
},
Required: []string{"module", "topic"},
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("pubsub.publish module error: %w", err)
}
topicString, err := params.GetString("topic")
if err != nil {
return nil, fmt.Errorf("pubsub.publish topic error: %w", err)
}
topicTemplate, err := template.New("topic").Parse(topicString)
if err != nil {
return nil, err
}
return &PubSubPublish{config: config, ModuleId: moduleIdString, Topic: topicTemplate, logger: slog.Default().With("component", "processor", "type", config.Type)}, nil
},
})
}
+30 -30
View File
@@ -11,36 +11,6 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
type RouterInput struct {
config config.ProcessorConfig
SourceId string
logger *slog.Logger
}
func (ri *RouterInput) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
payload := wrappedPayload.Payload
if wrappedPayload.InputHandler == nil {
wrappedPayload.End = true
return wrappedPayload, errors.New("router.input no input handler found")
}
_, err := wrappedPayload.InputHandler(ctx, ri.SourceId, payload)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, errors.New("router.input failed to send input")
}
wrappedPayload.Payload = payload
return wrappedPayload, nil
}
func (ri *RouterInput) Type() string {
return ri.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "router.input",
@@ -71,3 +41,33 @@ func init() {
},
})
}
type RouterInput struct {
config config.ProcessorConfig
SourceId string
logger *slog.Logger
}
func (ri *RouterInput) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
payload := wrappedPayload.Payload
if wrappedPayload.InputHandler == nil {
wrappedPayload.End = true
return wrappedPayload, errors.New("router.input no input handler found")
}
_, err := wrappedPayload.InputHandler(ctx, ri.SourceId, payload)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, errors.New("router.input failed to send input")
}
wrappedPayload.Payload = payload
return wrappedPayload, nil
}
func (ri *RouterInput) Type() string {
return ri.config.Type
}
+18 -18
View File
@@ -17,24 +17,6 @@ type ScriptExpr struct {
Program *vm.Program
}
func (se *ScriptExpr) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
exprEnv := wrappedPayload
output, err := expr.Run(se.Program, exprEnv)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
wrappedPayload.Payload = output
return wrappedPayload, nil
}
func (se *ScriptExpr) Type() string {
return se.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "script.expr",
@@ -67,3 +49,21 @@ func init() {
},
})
}
func (se *ScriptExpr) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
exprEnv := wrappedPayload
output, err := expr.Run(se.Program, exprEnv)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
wrappedPayload.Payload = output
return wrappedPayload, nil
}
func (se *ScriptExpr) Type() string {
return se.config.Type
}
+44 -44
View File
@@ -10,6 +10,50 @@ import (
"modernc.org/quickjs"
)
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "script.js",
Title: "Run JavaScript",
ParamsSchema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"program": {
Title: "Program",
Type: "string",
},
},
Required: []string{"program"},
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
},
New: func(config config.ProcessorConfig) (Processor, error) {
params := config.Params
programString, err := params.GetString("program")
if err != nil {
return nil, fmt.Errorf("script.js program error: %w", err)
}
vm, err := quickjs.NewVM()
if err != nil {
return nil, err
}
payloadAtom, err := vm.NewAtom("payload")
if err != nil {
return nil, err
}
senderAtom, err := vm.NewAtom("sender")
if err != nil {
return nil, err
}
return &ScriptJS{config: config, Program: programString, vm: vm, payloadAtom: payloadAtom, senderAtom: senderAtom}, nil
},
})
}
type ScriptJS struct {
config config.ProcessorConfig
vm *quickjs.VM
@@ -93,47 +137,3 @@ func (sj *ScriptJS) Process(ctx context.Context, wrappedPayload common.WrappedPa
func (sj *ScriptJS) Type() string {
return sj.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "script.js",
Title: "Run JavaScript",
ParamsSchema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"program": {
Title: "Program",
Type: "string",
},
},
Required: []string{"program"},
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
},
New: func(config config.ProcessorConfig) (Processor, error) {
params := config.Params
programString, err := params.GetString("program")
if err != nil {
return nil, fmt.Errorf("script.js program error: %w", err)
}
vm, err := quickjs.NewVM()
if err != nil {
return nil, err
}
payloadAtom, err := vm.NewAtom("payload")
if err != nil {
return nil, err
}
senderAtom, err := vm.NewAtom("sender")
if err != nil {
return nil, err
}
return &ScriptJS{config: config, Program: programString, vm: vm, payloadAtom: payloadAtom, senderAtom: senderAtom}, nil
},
})
}
+31 -31
View File
@@ -12,37 +12,6 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
type ScriptWASM struct {
config config.ProcessorConfig
Program *extism.Plugin
Function string
}
func (sw *ScriptWASM) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
payload := wrappedPayload.Payload
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
if !ok {
wrappedPayload.End = true
return wrappedPayload, fmt.Errorf("script.wasm can only process a byte array")
}
_, output, err := sw.Program.Call(sw.Function, payloadBytes)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
wrappedPayload.Payload = output
return wrappedPayload, nil
}
func (sw *ScriptWASM) Type() string {
return sw.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "script.wasm",
@@ -120,3 +89,34 @@ func init() {
},
})
}
type ScriptWASM struct {
config config.ProcessorConfig
Program *extism.Plugin
Function string
}
func (sw *ScriptWASM) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
payload := wrappedPayload.Payload
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
if !ok {
wrappedPayload.End = true
return wrappedPayload, fmt.Errorf("script.wasm can only process a byte array")
}
_, output, err := sw.Program.Call(sw.Function, payloadBytes)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
wrappedPayload.Payload = output
return wrappedPayload, nil
}
func (sw *ScriptWASM) Type() string {
return sw.config.Type
}
+39 -39
View File
@@ -11,45 +11,6 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
type SipResponseAudioCreate struct {
config config.ProcessorConfig
PreWait int
PostWait int
AudioFile *template.Template
}
type SipAudioFileResponse struct {
PreWait int
PostWait int
AudioFile string
}
func (srac *SipResponseAudioCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
templateData := wrappedPayload
var audioFileBuffer bytes.Buffer
err := srac.AudioFile.Execute(&audioFileBuffer, templateData)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
audioFileString := audioFileBuffer.String()
wrappedPayload.Payload = SipAudioFileResponse{
PreWait: srac.PreWait,
PostWait: srac.PostWait,
AudioFile: audioFileString,
}
return wrappedPayload, nil
}
func (srac *SipResponseAudioCreate) Type() string {
return srac.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "sip.response.audio.create",
@@ -99,3 +60,42 @@ func init() {
},
})
}
type SipResponseAudioCreate struct {
config config.ProcessorConfig
PreWait int
PostWait int
AudioFile *template.Template
}
type SipAudioFileResponse struct {
PreWait int
PostWait int
AudioFile string
}
func (srac *SipResponseAudioCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
templateData := wrappedPayload
var audioFileBuffer bytes.Buffer
err := srac.AudioFile.Execute(&audioFileBuffer, templateData)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
audioFileString := audioFileBuffer.String()
wrappedPayload.Payload = SipAudioFileResponse{
PreWait: srac.PreWait,
PostWait: srac.PostWait,
AudioFile: audioFileString,
}
return wrappedPayload, nil
}
func (srac *SipResponseAudioCreate) Type() string {
return srac.config.Type
}
+47 -47
View File
@@ -13,53 +13,6 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
type SipResponseDTMFCreate struct {
config config.ProcessorConfig
PreWait int
PostWait int
Digits *template.Template
validDTMF *regexp.Regexp
}
type SipDTMFResponse struct {
PreWait int
PostWait int
Digits string
}
var validDTMFRegex = regexp.MustCompile(`^[0-9*#A-Da-d]+$`)
func (srdc *SipResponseDTMFCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
templateData := wrappedPayload
var digitsBuffer bytes.Buffer
err := srdc.Digits.Execute(&digitsBuffer, templateData)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
digitsString := digitsBuffer.String()
if !srdc.validDTMF.MatchString(digitsString) {
wrappedPayload.End = true
return wrappedPayload, errors.New("sip.response.dtmf.create result of digits template contains invalid characters")
}
wrappedPayload.Payload = SipDTMFResponse{
PreWait: srdc.PreWait,
PostWait: srdc.PostWait,
Digits: digitsString,
}
return wrappedPayload, nil
}
func (srdc *SipResponseDTMFCreate) Type() string {
return srdc.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "sip.response.dtmf.create",
@@ -109,3 +62,50 @@ func init() {
},
})
}
type SipResponseDTMFCreate struct {
config config.ProcessorConfig
PreWait int
PostWait int
Digits *template.Template
validDTMF *regexp.Regexp
}
type SipDTMFResponse struct {
PreWait int
PostWait int
Digits string
}
var validDTMFRegex = regexp.MustCompile(`^[0-9*#A-Da-d]+$`)
func (srdc *SipResponseDTMFCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
templateData := wrappedPayload
var digitsBuffer bytes.Buffer
err := srdc.Digits.Execute(&digitsBuffer, templateData)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
digitsString := digitsBuffer.String()
if !srdc.validDTMF.MatchString(digitsString) {
wrappedPayload.End = true
return wrappedPayload, errors.New("sip.response.dtmf.create result of digits template contains invalid characters")
}
wrappedPayload.Payload = SipDTMFResponse{
PreWait: srdc.PreWait,
PostWait: srdc.PostWait,
Digits: digitsString,
}
return wrappedPayload, nil
}
func (srdc *SipResponseDTMFCreate) Type() string {
return srdc.config.Type
}
+25 -25
View File
@@ -11,31 +11,6 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
type StringCreate struct {
config config.ProcessorConfig
Template *template.Template
}
func (sc *StringCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
templateData := wrappedPayload
var templateBuffer bytes.Buffer
err := sc.Template.Execute(&templateBuffer, templateData)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
wrappedPayload.Payload = templateBuffer.String()
return wrappedPayload, nil
}
func (sc *StringCreate) Type() string {
return sc.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "string.create",
@@ -67,3 +42,28 @@ func init() {
},
})
}
type StringCreate struct {
config config.ProcessorConfig
Template *template.Template
}
func (sc *StringCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
templateData := wrappedPayload
var templateBuffer bytes.Buffer
err := sc.Template.Execute(&templateBuffer, templateData)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
wrappedPayload.Payload = templateBuffer.String()
return wrappedPayload, nil
}
func (sc *StringCreate) Type() string {
return sc.config.Type
}
+10 -10
View File
@@ -8,6 +8,16 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "string.decode",
Title: "Decode String",
New: func(config config.ProcessorConfig) (Processor, error) {
return &StringDecode{config: config}, nil
},
})
}
type StringDecode struct {
config config.ProcessorConfig
}
@@ -30,13 +40,3 @@ func (sd *StringDecode) Process(ctx context.Context, wrappedPayload common.Wrapp
func (sd *StringDecode) Type() string {
return sd.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "string.decode",
Title: "Decode String",
New: func(config config.ProcessorConfig) (Processor, error) {
return &StringDecode{config: config}, nil
},
})
}
+10 -10
View File
@@ -8,6 +8,16 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "string.encode",
Title: "Encode String",
New: func(config config.ProcessorConfig) (Processor, error) {
return &StringEncode{config: config}, nil
},
})
}
type StringEncode struct {
config config.ProcessorConfig
}
@@ -29,13 +39,3 @@ func (se *StringEncode) Process(ctx context.Context, wrappedPayload common.Wrapp
func (se *StringEncode) Type() string {
return se.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "string.encode",
Title: "Encode String",
New: func(config config.ProcessorConfig) (Processor, error) {
return &StringEncode{config: config}, nil
},
})
}
+23 -23
View File
@@ -11,29 +11,6 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
type StringSplit struct {
config config.ProcessorConfig
Separator string
}
func (ss *StringSplit) 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("string.split only accepts a string")
}
wrappedPayload.Payload = strings.Split(payloadString, ss.Separator)
return wrappedPayload, nil
}
func (ss *StringSplit) Type() string {
return ss.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "string.split",
@@ -61,3 +38,26 @@ func init() {
},
})
}
type StringSplit struct {
config config.ProcessorConfig
Separator string
}
func (ss *StringSplit) 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("string.split only accepts a string")
}
wrappedPayload.Payload = strings.Split(payloadString, ss.Separator)
return wrappedPayload, nil
}
func (ss *StringSplit) Type() string {
return ss.config.Type
}
+27 -27
View File
@@ -11,6 +11,33 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "struct.field.get",
Title: "Get Struct Field",
ParamsSchema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"name": {
Title: "Field Name",
Type: "string",
},
},
Required: []string{"name"},
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
},
New: func(config config.ProcessorConfig) (Processor, error) {
params := config.Params
nameString, err := params.GetString("name")
if err != nil {
return nil, fmt.Errorf("struct.field.get name error: %w", err)
}
return &StructFieldGet{config: config, Name: nameString}, nil
},
})
}
type StructFieldGet struct {
config config.ProcessorConfig
Name string
@@ -42,30 +69,3 @@ func (sfg *StructFieldGet) Process(ctx context.Context, wrappedPayload common.Wr
func (sfg *StructFieldGet) Type() string {
return sfg.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "struct.field.get",
Title: "Get Struct Field",
ParamsSchema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"name": {
Title: "Field Name",
Type: "string",
},
},
Required: []string{"name"},
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
},
New: func(config config.ProcessorConfig) (Processor, error) {
params := config.Params
nameString, err := params.GetString("name")
if err != nil {
return nil, fmt.Errorf("struct.field.get name error: %w", err)
}
return &StructFieldGet{config: config, Name: nameString}, nil
},
})
}
+27 -27
View File
@@ -11,6 +11,33 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "struct.method.get",
Title: "Get Struct Method",
ParamsSchema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"name": {
Title: "Method Name",
Type: "string",
},
},
Required: []string{"name"},
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
},
New: func(config config.ProcessorConfig) (Processor, error) {
params := config.Params
nameString, err := params.GetString("name")
if err != nil {
return nil, fmt.Errorf("struct.method.get name error: %w", err)
}
return &StructMethodGet{config: config, Name: nameString}, nil
},
})
}
type StructMethodGet struct {
config config.ProcessorConfig
Name string
@@ -61,30 +88,3 @@ func (smg *StructMethodGet) Process(ctx context.Context, wrappedPayload common.W
func (smg *StructMethodGet) Type() string {
return smg.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "struct.method.get",
Title: "Get Struct Method",
ParamsSchema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"name": {
Title: "Method Name",
Type: "string",
},
},
Required: []string{"name"},
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
},
New: func(config config.ProcessorConfig) (Processor, error) {
params := config.Params
nameString, err := params.GetString("name")
if err != nil {
return nil, fmt.Errorf("struct.method.get name error: %w", err)
}
return &StructMethodGet{config: config, Name: nameString}, nil
},
})
}
+14 -14
View File
@@ -10,20 +10,6 @@ import (
"github.com/jwetzell/showbridge-go/internal/config"
)
type TimeSleep struct {
config config.ProcessorConfig
Duration time.Duration
}
func (ts *TimeSleep) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
time.Sleep(ts.Duration)
return wrappedPayload, nil
}
func (ts *TimeSleep) Type() string {
return ts.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "time.sleep",
@@ -52,3 +38,17 @@ func init() {
},
})
}
type TimeSleep struct {
config config.ProcessorConfig
Duration time.Duration
}
func (ts *TimeSleep) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
time.Sleep(ts.Duration)
return wrappedPayload, nil
}
func (ts *TimeSleep) Type() string {
return ts.config.Type
}