ureport.go 915 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package ureport
  2. import (
  3. "fmt"
  4. "git.qianqiusoft.com/qianqiusoft/light-apiengine/entitys"
  5. )
  6. var _ureportHandlerMap map[string]func(ctx *entitys.CtrlContext)interface{} = make(map[string]func(ctx *entitys.CtrlContext)interface{})
  7. func RegisterUreportHandler(key string, handler func(ctx *entitys.CtrlContext)interface{}){
  8. if handler == nil{
  9. return
  10. }
  11. if _, ok := _ureportHandlerMap[key]; ok{
  12. fmt.Println("---------------------->key is already exists")
  13. return
  14. }
  15. _ureportHandlerMap[key] = handler
  16. }
  17. func CallUreportHanlder(ctx *entitys.CtrlContext){
  18. if _ureportHandlerMap == nil{
  19. fmt.Println("-------------------------handler is nil>")
  20. return
  21. }
  22. key := ctx.Ctx.DefaultQuery("key", "")
  23. if handler, ok := _ureportHandlerMap[key]; ok{
  24. ret := handler(ctx)
  25. ctx.Ctx.JSON(200, ret)
  26. }else{
  27. ctx.Ctx.JSON(200, map[string]interface{}{"code": 500, "msg": "key is not exists", "data": nil})
  28. }
  29. }