From 1f888194287e44bc74582383105d22557b4037c2 Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Mon, 2 Mar 2026 14:01:20 -0600 Subject: [PATCH] use params methods iin mqtt.message.create --- internal/processor/mqtt-message-create.go | 31 ++++++++++------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/internal/processor/mqtt-message-create.go b/internal/processor/mqtt-message-create.go index 4affb97..ad06c60 100644 --- a/internal/processor/mqtt-message-create.go +++ b/internal/processor/mqtt-message-create.go @@ -80,8 +80,8 @@ func (mmc *MQTTMessageCreate) Type() string { func init() { RegisterProcessor(ProcessorRegistration{ Type: "mqtt.message.create", - New: func(config config.ProcessorConfig) (Processor, error) { - params := config.Params + New: func(processorConfig config.ProcessorConfig) (Processor, error) { + params := processorConfig.Params topicString, err := params.GetString("topic") if err != nil { return nil, fmt.Errorf("mqtt.message.create topic error: %w", err) @@ -98,25 +98,22 @@ func init() { } //TODO(jwetzell): convert payload into []byte or string for sending - payload, ok := params["payload"] - - if !ok { - return nil, errors.New("mqtt.message.create payload error: not found") - } - - if payloadBytes, ok := GetAnyAs[[]byte](payload); ok { - return &MQTTMessageCreate{config: config, Topic: topicString, QoS: byte(qosByte), Retained: retainedBool, Payload: payloadBytes}, nil - } - - payloadString, ok := GetAnyAs[string](payload) - - if !ok { - return nil, errors.New("mqtt.message.create payload error: not a string or byte array") + payloadString, err := params.GetString("payload") + if err != nil { + if errors.Is(err, config.ErrParamNotString) { + payloadBytes, err := params.GetByteSlice("payload") + if err != nil { + return nil, fmt.Errorf("mqtt.message.create payload error: %w", err) + } + 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) + } } 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 }, }) }