|
@@ -1,19 +1,38 @@
|
|
|
package ureport
|
|
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{
|
|
if handler == nil{
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- _ureportHandler = handler
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if _, ok := _ureportHandlerMap[key]; ok{
|
|
|
|
|
+ fmt.Println("---------------------->key is already exists")
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ _ureportHandlerMap[key] = handler
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
func CallUreportHanlder(ctx *entitys.CtrlContext){
|
|
func CallUreportHanlder(ctx *entitys.CtrlContext){
|
|
|
- if _ureportHandler == nil{
|
|
|
|
|
|
|
+ if _ureportHandlerMap == nil{
|
|
|
|
|
+ fmt.Println("-------------------------handler is nil>")
|
|
|
return
|
|
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})
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|