소스 검색

修改bug

yjp 4 달 전
부모
커밋
241af2f096
3개의 변경된 파일10개의 추가작업 그리고 4개의 파일을 삭제
  1. 5 3
      framework/core/mqtt_api/context.go
  2. 1 1
      framework/core/mqtt_api/router.go
  3. 4 0
      test/mqtt_binding_test.go

+ 5 - 3
framework/core/mqtt_api/context.go

@@ -48,10 +48,12 @@ func destroyContext(c *Context) {
 	}
 	}
 }
 }
 
 
-func (c *Context) callHandlers(data []byte) {
+func (c *Context) callHandlers() {
 	c.currentHandlerIndex = 0
 	c.currentHandlerIndex = 0
-	c.Data = data
+	for c.currentHandlerIndex < len(c.handlers) {
-	c.handlers[c.currentHandlerIndex](c)
+		c.handlers[c.currentHandlerIndex](c)
+		c.currentHandlerIndex++
+	}
 }
 }
 
 
 func (c *Context) Response(responseIdentifier string, data []byte) error {
 func (c *Context) Response(responseIdentifier string, data []byte) error {

+ 1 - 1
framework/core/mqtt_api/router.go

@@ -138,7 +138,7 @@ func (router *Router) subscribeMqttClient(client *MqttClient, topic string, hand
 			return
 			return
 		}
 		}
 
 
-		c.callHandlers(data)
+		c.callHandlers()
 
 
 		c.Next()
 		c.Next()
 	})
 	})

+ 4 - 0
test/mqtt_binding_test.go

@@ -69,6 +69,8 @@ func TestMqttBinding(t *testing.T) {
 		},
 		},
 	}, func(c *mqtt_api.Context, i *infrastructure.Infrastructure) {
 	}, func(c *mqtt_api.Context, i *infrastructure.Infrastructure) {
 		fmt.Println("Version Middleware")
 		fmt.Println("Version Middleware")
+		c.Next()
+		fmt.Println("Version Middleware After")
 	})
 	})
 
 
 	mqtt_binding.Bind(mqttBinder, &mqtt_binding.BindItem[map[string]any]{
 	mqtt_binding.Bind(mqttBinder, &mqtt_binding.BindItem[map[string]any]{
@@ -93,6 +95,8 @@ func TestMqttBinding(t *testing.T) {
 		},
 		},
 	}, func(c *mqtt_api.Context, i *infrastructure.Infrastructure) {
 	}, func(c *mqtt_api.Context, i *infrastructure.Infrastructure) {
 		fmt.Println("Hello Middleware")
 		fmt.Println("Hello Middleware")
+		c.Next()
+		fmt.Println("Hello Middleware After")
 	})
 	})
 
 
 	for {
 	for {