mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 05:15:47 +00:00
use params methods iin mqtt.message.create
This commit is contained in:
@@ -80,8 +80,8 @@ 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) {
|
New: func(processorConfig config.ProcessorConfig) (Processor, error) {
|
||||||
params := config.Params
|
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 +98,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)
|
||||||
}
|
}
|
||||||
|
return &MQTTMessageCreate{config: processorConfig, Topic: topicString, QoS: byte(qosByte), Retained: retainedBool, Payload: payloadBytes}, nil
|
||||||
if payloadBytes, ok := GetAnyAs[[]byte](payload); ok {
|
} else {
|
||||||
return &MQTTMessageCreate{config: config, Topic: topicString, QoS: byte(qosByte), Retained: retainedBool, Payload: payloadBytes}, nil
|
return nil, fmt.Errorf("mqtt.message.create payload error: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadString, ok := GetAnyAs[string](payload)
|
|
||||||
|
|
||||||
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
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user