mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 05:15:47 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38857f7a29 | ||
|
|
45965a4eac | ||
|
|
b372b53422 | ||
|
|
97cf721abc |
@@ -31,6 +31,10 @@ func (sj *ScriptJS) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
|
|
||||||
_, err = vm.Eval(sj.Program, quickjs.EvalGlobal)
|
_, err = vm.Eval(sj.Program, quickjs.EvalGlobal)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
output, err := vm.GetProperty(vm.GlobalObject(), payloadAtom)
|
output, err := vm.GetProperty(vm.GlobalObject(), payloadAtom)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
57
internal/processing/string-create.go
Normal file
57
internal/processing/string-create.go
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
package processing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"text/template"
|
||||||
|
)
|
||||||
|
|
||||||
|
type StringCreate struct {
|
||||||
|
config ProcessorConfig
|
||||||
|
Template *template.Template
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sc *StringCreate) Process(ctx context.Context, payload any) (any, error) {
|
||||||
|
var templateBuffer bytes.Buffer
|
||||||
|
err := sc.Template.Execute(&templateBuffer, payload)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
payloadString := templateBuffer.String()
|
||||||
|
|
||||||
|
return payloadString, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sc *StringCreate) Type() string {
|
||||||
|
return sc.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterProcessor(ProcessorRegistration{
|
||||||
|
Type: "string.create",
|
||||||
|
New: func(config ProcessorConfig) (Processor, error) {
|
||||||
|
params := config.Params
|
||||||
|
tmpl, ok := params["template"]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("string.create requires a template parameter")
|
||||||
|
}
|
||||||
|
|
||||||
|
templateString, ok := tmpl.(string)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("string.create template must be a string")
|
||||||
|
}
|
||||||
|
|
||||||
|
templateTemplate, err := template.New("template").Parse(templateString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &StringCreate{config: config, Template: templateTemplate}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user