mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-26 21:05:30 +00:00
39 lines
688 B
Go
39 lines
688 B
Go
package processor
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"github.com/jwetzell/showbridge-go/internal/config"
|
|
)
|
|
|
|
type JsonEncode struct {
|
|
config config.ProcessorConfig
|
|
}
|
|
|
|
func (je *JsonEncode) Process(ctx context.Context, payload any) (any, error) {
|
|
var payloadBuffer bytes.Buffer
|
|
|
|
err := json.NewEncoder(&payloadBuffer).Encode(payload)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return payloadBuffer.Bytes(), nil
|
|
}
|
|
|
|
func (je *JsonEncode) Type() string {
|
|
return je.config.Type
|
|
}
|
|
|
|
func init() {
|
|
RegisterProcessor(ProcessorRegistration{
|
|
Type: "json.encode",
|
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
|
return &JsonEncode{config: config}, nil
|
|
},
|
|
})
|
|
}
|