zlimit.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/service/main/location/model"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/xstr"
  8. )
  9. // pgcZone get ip infos by gids.
  10. func pgcZone(c *bm.Context) {
  11. var (
  12. params = c.Request.Form
  13. err error
  14. zoneID int64
  15. zoneIDs = []int64{}
  16. ip *model.InfoComplete
  17. )
  18. zoneStr := params.Get("zone_id")
  19. ipStr := params.Get("ip")
  20. if zoneStr == "" && ipStr == "" {
  21. c.JSON(nil, ecode.RequestErr)
  22. return
  23. }
  24. if zoneID, err = strconv.ParseInt(zoneStr, 10, 64); err != nil || zoneID == 0 {
  25. if ip, err = svr.InfoComplete(c, ipStr); err != nil {
  26. c.JSON(nil, ecode.RequestErr)
  27. return
  28. } else {
  29. zoneIDs = ip.ZoneID
  30. }
  31. }
  32. if len(zoneIDs) == 0 {
  33. if zoneID != 0 {
  34. zoneIDs = append(zoneIDs, 0)
  35. }
  36. zoneIDs = append(zoneIDs, zoneID)
  37. }
  38. c.JSON(svr.PgcZone(c, zoneIDs))
  39. }
  40. // auth get auth by aid & ip & cip & mid.
  41. func auth(c *bm.Context) {
  42. var (
  43. params = c.Request.Form
  44. err error
  45. ipaddr, cdnip string
  46. mid, aid int64
  47. )
  48. aidStr := params.Get("aid")
  49. if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil {
  50. c.JSON(nil, ecode.RequestErr)
  51. return
  52. }
  53. if vmid, ok := c.Get("mid"); !ok {
  54. mid = 0
  55. } else {
  56. mid = vmid.(int64)
  57. }
  58. ipaddr = params.Get("ip")
  59. cdnip = params.Get("cdnip")
  60. if ipaddr == "" && cdnip == "" {
  61. c.JSON(nil, ecode.RequestErr)
  62. return
  63. }
  64. c.JSON(svr.Auth(c, aid, mid, ipaddr, cdnip))
  65. }
  66. // archive2 get auth by aid & ip & cip & mid.
  67. func archive2(c *bm.Context) {
  68. var (
  69. params = c.Request.Form
  70. err error
  71. ipaddr, cdnip string
  72. mid, aid int64
  73. )
  74. aidStr := params.Get("aid")
  75. if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil {
  76. c.JSON(nil, ecode.RequestErr)
  77. return
  78. }
  79. if vmid, ok := c.Get("mid"); !ok {
  80. mid = 0
  81. } else {
  82. mid = vmid.(int64)
  83. }
  84. ipaddr = params.Get("ip")
  85. cdnip = params.Get("cdnip")
  86. if ipaddr == "" && cdnip == "" {
  87. c.JSON(nil, ecode.RequestErr)
  88. return
  89. }
  90. c.JSON(svr.Archive2(c, aid, mid, ipaddr, cdnip))
  91. }
  92. // authGID get auth by gids & ip & cid & mid.
  93. func authGID(c *bm.Context) {
  94. var (
  95. mid, gid int64
  96. ipaddr, cdnip string
  97. params = c.Request.Form
  98. err error
  99. )
  100. gidStr := params.Get("gid")
  101. if gid, err = strconv.ParseInt(gidStr, 10, 64); err != nil {
  102. c.JSON(nil, ecode.RequestErr)
  103. return
  104. }
  105. if vmid, ok := c.Get("mid"); !ok {
  106. mid = 0
  107. } else {
  108. mid = vmid.(int64)
  109. }
  110. ipaddr = params.Get("ip")
  111. cdnip = params.Get("cdnip")
  112. if ipaddr == "" && cdnip == "" {
  113. c.JSON(nil, ecode.RequestErr)
  114. return
  115. }
  116. c.JSON(svr.AuthGID(c, gid, mid, ipaddr, cdnip), nil)
  117. }
  118. // authGIDs get auth by gids & ip & cid & mid.
  119. func authGIDs(c *bm.Context) {
  120. var (
  121. gids []int64
  122. mid int64
  123. ipaddr, cdnip string
  124. params = c.Request.Form
  125. err error
  126. )
  127. gidsStr := params.Get("gids")
  128. if gids, err = xstr.SplitInts(gidsStr); err != nil {
  129. c.JSON(nil, ecode.RequestErr)
  130. return
  131. }
  132. if vmid, ok := c.Get("mid"); !ok {
  133. mid = 0
  134. } else {
  135. mid = vmid.(int64)
  136. }
  137. ipaddr = params.Get("ip")
  138. cdnip = params.Get("cdnip")
  139. if ipaddr == "" && cdnip == "" {
  140. c.JSON(nil, ecode.RequestErr)
  141. return
  142. }
  143. c.JSON(svr.AuthGIDs(c, gids, mid, ipaddr, cdnip), nil)
  144. }