dynamic.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/interface/main/web/conf"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. func dynamicRegion(c *bm.Context) {
  9. var (
  10. rid, pn, ps int
  11. err error
  12. )
  13. params := c.Request.Form
  14. ridStr := params.Get("rid")
  15. pnStr := params.Get("pn")
  16. psStr := params.Get("ps")
  17. if rid, err = strconv.Atoi(ridStr); err != nil {
  18. c.JSON(nil, ecode.RequestErr)
  19. return
  20. }
  21. if pn, err = strconv.Atoi(pnStr); err != nil || pn < 1 {
  22. pn = 1
  23. }
  24. if ps, err = strconv.Atoi(psStr); err != nil || ps < 1 {
  25. ps = conf.Conf.Rule.DynamicNumArcs
  26. } else if ps > conf.Conf.Rule.MaxArcsPageSize {
  27. ps = conf.Conf.Rule.MaxArcsPageSize
  28. }
  29. c.JSON(webSvc.DynamicRegion(c, int32(rid), pn, ps))
  30. }
  31. func dynamicRegionTag(c *bm.Context) {
  32. var (
  33. tagID int64
  34. rid, pn, ps int
  35. err error
  36. )
  37. params := c.Request.Form
  38. ridStr := params.Get("rid")
  39. tagIDStr := params.Get("tag_id")
  40. pnStr := params.Get("pn")
  41. psStr := params.Get("ps")
  42. if rid, err = strconv.Atoi(ridStr); err != nil {
  43. c.JSON(nil, ecode.RequestErr)
  44. return
  45. }
  46. if tagID, err = strconv.ParseInt(tagIDStr, 10, 64); err != nil {
  47. c.JSON(nil, ecode.RequestErr)
  48. return
  49. }
  50. if pn, err = strconv.Atoi(pnStr); err != nil || pn < 1 {
  51. pn = 1
  52. }
  53. if ps, err = strconv.Atoi(psStr); err != nil || ps < 1 {
  54. ps = conf.Conf.Rule.DynamicNumArcs
  55. } else if ps > conf.Conf.Rule.MaxArcsPageSize {
  56. ps = conf.Conf.Rule.MaxArcsPageSize
  57. }
  58. c.JSON(webSvc.DynamicRegionTag(c, tagID, int32(rid), pn, ps))
  59. }
  60. func dynamicRegionTotal(c *bm.Context) {
  61. c.JSON(webSvc.DynamicRegionTotal(c))
  62. }
  63. func dynamicRegions(c *bm.Context) {
  64. c.JSON(webSvc.DynamicRegions(c))
  65. }