param.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/interface/main/app-resource/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. // getParam get param data.
  10. func getParam(c *bm.Context) {
  11. params := c.Request.Form
  12. mobiApp := params.Get("mobi_app")
  13. platStr := params.Get("plat")
  14. ver := params.Get("ver")
  15. buildStr := params.Get("build")
  16. // check params
  17. build, err := strconv.Atoi(buildStr)
  18. if err != nil {
  19. log.Error("stronv.ParseInt(%s) error(%v)", buildStr, err)
  20. c.JSON(nil, ecode.RequestErr)
  21. return
  22. }
  23. var plat int8
  24. if mobiApp != "" {
  25. device := params.Get("device")
  26. plat = model.Plat(mobiApp, device)
  27. } else if platStr != "" { // android have not mobi_app when 4.18
  28. var platInt int64
  29. platInt, err = strconv.ParseInt(platStr, 10, 64)
  30. if err != nil {
  31. log.Error("stronv.ParseInt(%s) error(%v)", platStr, err)
  32. c.JSON(nil, ecode.RequestErr)
  33. return
  34. }
  35. plat = int8(platInt)
  36. }
  37. // service
  38. data, version, err := paramSvc.Param(plat, build, ver)
  39. res := map[string]interface{}{
  40. "data": data,
  41. "ver": version,
  42. }
  43. c.JSONMap(res, err)
  44. }