getConfig.go 854 B

123456789101112131415161718192021222324252627282930313233
  1. package activity
  2. import (
  3. "app.yhyue.com/moapp/jybase/api"
  4. "app.yhyue.com/moapp/jybase/go-xweb/xweb"
  5. "encoding/json"
  6. "fmt"
  7. "github.com/gogf/gf/v2/os/gcfg"
  8. "github.com/gogf/gf/v2/os/gctx"
  9. "github.com/gogf/gf/v2/util/gconv"
  10. "log"
  11. )
  12. type ConfigRouter struct {
  13. *xweb.Action
  14. getConfig xweb.Mapper `xweb:"/getConfig/info"`
  15. }
  16. func (c *ConfigRouter) GetConfig() {
  17. rData, errMsg := func() (interface{}, error) {
  18. reqParam := map[string]interface{}{}
  19. if err := json.Unmarshal(c.Body(), &reqParam); err != nil || len(reqParam) == 0 {
  20. return nil, fmt.Errorf("请求参数异常")
  21. }
  22. code := gconv.String(reqParam["code"])
  23. data := gcfg.Instance().MustGet(gctx.New(), code, nil).Map()
  24. return data, nil
  25. }()
  26. if errMsg != nil {
  27. log.Printf("ConfigRouter GetConfig error:%s\n", errMsg.Error())
  28. }
  29. c.ServeJson(api.NewResult(rData, errMsg))
  30. }