Explorar el Código

add report factory

huangrf hace 5 años
padre
commit
5d554e6700
Se han modificado 1 ficheros con 25 adiciones y 6 borrados
  1. 25 6
      third/ureport/ureport.go

+ 25 - 6
third/ureport/ureport.go

@@ -1,19 +1,38 @@
 package ureport
 
-import "git.qianqiusoft.com/qianqiusoft/light-apiengine/entitys"
+import (
+	"fmt"
+	"git.qianqiusoft.com/qianqiusoft/light-apiengine/entitys"
+)
 
-var _ureportHandler func(ctx *entitys.CtrlContext) = nil
+var _ureportHandlerMap map[string]func(ctx *entitys.CtrlContext)interface{} = make(map[string]func(ctx *entitys.CtrlContext)interface{})
 
-func RegisterUreportHandler(handler func(ctx *entitys.CtrlContext)){
+func RegisterUreportHandler(key string, handler func(ctx *entitys.CtrlContext)interface{}){
 	if handler == nil{
 		return
 	}
-	_ureportHandler = handler
+
+	if _, ok := _ureportHandlerMap[key]; ok{
+		fmt.Println("---------------------->key is already exists")
+		return
+	}
+
+	_ureportHandlerMap[key] = handler
  }
 
+
 func CallUreportHanlder(ctx *entitys.CtrlContext){
-	if _ureportHandler == nil{
+	if _ureportHandlerMap == nil{
+		fmt.Println("-------------------------handler is nil>")
 		return
 	}
-	_ureportHandler(ctx)
+
+	key := ctx.Ctx.DefaultQuery("key", "")
+
+	if handler, ok := _ureportHandlerMap[key]; ok{
+		ret := handler(ctx)
+		ctx.Ctx.JSON(200, ret)
+	}else{
+		ctx.Ctx.JSON(200, map[string]interface{}{"code": 500, "msg": "key is not exists", "data": nil})
+	}
 }