fix configuration
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2023-12-05 16:21:30 +01:00
parent 00a9eceea8
commit a5209dad8f
11 changed files with 94 additions and 15 deletions

View File

@ -21,11 +21,37 @@ var archiverChannel chan handler.MessageT = make(chan handler.MessageT, 100)
func InitDispatcher() {
log.Printf("Initializing dispatcher")
go archiver()
handlerMap["TTN"] = ttn.NewTTNHandler()
handlerMap["IoT"] = iot.NewIoTHandler()
handlerMap["PV"] = pv.NewPvHandler(config.Config.Handlers["PV"])
handlerMap["MBGW3"] = mbgw3.NewMbgw3Handler(config.Config.Handlers["MBGW3"])
handlerMap["SVE"] = sve.NewSveHandler(config.Config.Handlers["SVE"])
for _, mapping := range config.Config.TopicMappings {
log.Printf("Trying to initialize %s", mapping)
var factory interface{}
switch mapping.Handler {
case "TTN":
factory = ttn.NewTTNHandler
case "IoT":
factory = iot.NewIoTHandler
case "PV":
factory = pv.NewPvHandler
case "MBGW3":
factory = mbgw3.NewMbgw3Handler
case "SVE":
factory = sve.NewSveHandler
default:
factory = nil
log.Printf("No handler %s found, ignore mapping", mapping.Handler)
}
fn, ok := factory.(func(config.HandlerConfigT) handler.Handler)
if ! ok {
log.Println("Typ Assertion failed")
break
}
handler := fn(mapping.Config)
handlerMap[mapping.Id] = handler
}
log.Printf("handlerMap: %s", handlerMap)
}
func storeMessage(filename string, item handler.MessageT) {
@ -85,13 +111,13 @@ func handleMessage(message handler.MessageT) {
for _, subscribedTopic := range mapping.Topics {
// log.Printf("Testing %s in %s", message.Topic, subscribedTopic)
if mqtt.TopicMatchesSubscription(message.Topic, subscribedTopic) {
log.Printf("Handle message in handler %s", mapping.Handler)
handler, exists := handlerMap[mapping.Handler]
log.Printf("Handle message in handler %s", mapping.Id)
handler, exists := handlerMap[mapping.Id]
if exists {
handler.Handle(message)
return
} else {
log.Printf("Handler %s not found, message %s is lost", mapping.Handler, message)
log.Printf("Handler %s not found, message %s is lost", mapping.Id, message)
}
}
}