|
@@ -8,7 +8,9 @@ import (
|
|
|
"git.sxidc.com/go-tools/api_binding/mqtt_binding/request"
|
|
|
"git.sxidc.com/go-tools/api_binding/mqtt_binding/response"
|
|
|
"git.sxidc.com/go-tools/api_binding/utils"
|
|
|
+ "git.sxidc.com/service-supports/fslog"
|
|
|
"reflect"
|
|
|
+ "strings"
|
|
|
)
|
|
|
|
|
|
type BusinessFunc[I any, O any] func(c *mqtt_client.MqttClient, inputModel I) (O, error)
|
|
@@ -52,6 +54,22 @@ func (binding *Binding) AddHandler(topic string, handlers ...router.Handler) err
|
|
|
return errors.New("没有传递处理函数")
|
|
|
}
|
|
|
|
|
|
+ err := binding.router.RangeItem(func(existItem *router.Item) error {
|
|
|
+ if existItem.Topic == binding.router.Group+topic {
|
|
|
+ return errors.New("主题已存在: " + existItem.Topic)
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ if strings.Contains(err.Error(), "主题已存在: ") {
|
|
|
+ fslog.Error(err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
return binding.router.AddTopic(binding.router.Group+topic, handlers...)
|
|
|
}
|
|
|
|
|
@@ -73,6 +91,17 @@ func (item *BindItem[I, O]) bind(r *router.Router, bindingResponseIdentifier res
|
|
|
panic("需要指定响应函数")
|
|
|
}
|
|
|
|
|
|
+ err := r.RangeItem(func(existItem *router.Item) error {
|
|
|
+ if existItem.Topic == r.Group+item.Topic {
|
|
|
+ return errors.New("主题已存在: " + existItem.Topic)
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+
|
|
|
var inputCheckModel I
|
|
|
inputType := reflect.TypeOf(inputCheckModel)
|
|
|
if inputType != nil {
|