split out from net and misc module namespaces

This commit is contained in:
Joel Wetzell
2025-12-11 19:34:57 -06:00
parent b59da597ba
commit 00f78b5a50
7 changed files with 49 additions and 49 deletions

View File

@@ -22,43 +22,43 @@ type MQTTClient struct {
func init() {
RegisterModule(ModuleRegistration{
Type: "net.mqtt.client",
Type: "mqtt.client",
New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) {
params := config.Params
broker, ok := params["broker"]
if !ok {
return nil, fmt.Errorf("net.mqtt.client requires a broker parameter")
return nil, fmt.Errorf("mqtt.client requires a broker parameter")
}
brokerString, ok := broker.(string)
if !ok {
return nil, fmt.Errorf("net.mqtt.client broker must be string")
return nil, fmt.Errorf("mqtt.client broker must be string")
}
topic, ok := params["topic"]
if !ok {
return nil, fmt.Errorf("net.mqtt.client requires a topic parameter")
return nil, fmt.Errorf("mqtt.client requires a topic parameter")
}
topicString, ok := topic.(string)
if !ok {
return nil, fmt.Errorf("net.mqtt.client topic must be string")
return nil, fmt.Errorf("mqtt.client topic must be string")
}
clientId, ok := params["clientId"]
if !ok {
return nil, fmt.Errorf("net.mqtt.client requires a clientId parameter")
return nil, fmt.Errorf("mqtt.client requires a clientId parameter")
}
clientIdString, ok := clientId.(string)
if !ok {
return nil, fmt.Errorf("net.mqtt.client clientId must be string")
return nil, fmt.Errorf("mqtt.client clientId must be string")
}
return &MQTTClient{config: config, Broker: brokerString, Topic: topicString, ClientID: clientIdString, ctx: ctx, router: router}, nil
@@ -109,15 +109,15 @@ func (mc *MQTTClient) Output(payload any) error {
fmt.Printf("payload type: %T\n", payload)
if !ok {
return fmt.Errorf("net.mqtt.client is only able to output a MQTTMessage")
return fmt.Errorf("mqtt.client is only able to output a MQTTMessage")
}
if mc.client == nil {
return fmt.Errorf("net.mqtt.client client is not setup")
return fmt.Errorf("mqtt.client client is not setup")
}
if !mc.client.IsConnected() {
return fmt.Errorf("net.mqtt.client is not connected")
return fmt.Errorf("mqtt.client is not connected")
}
token := mc.client.Publish(payloadMessage.Topic(), payloadMessage.Qos(), payloadMessage.Retained(), payloadMessage.Payload())