share.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/service/main/share/model"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/metadata"
  8. "go-common/library/xstr"
  9. )
  10. func add(ctx *bm.Context) {
  11. p := &model.ShareParams{}
  12. if err := ctx.Bind(p); err != nil {
  13. return
  14. }
  15. p.IP = metadata.String(ctx, metadata.RemoteIP)
  16. ctx.JSON(svr.Add(ctx, p))
  17. }
  18. func stat(ctx *bm.Context) {
  19. var (
  20. oid int64
  21. tp int64
  22. err error
  23. )
  24. params := ctx.Request.Form
  25. oidStr := params.Get("oid")
  26. if oid, err = strconv.ParseInt(oidStr, 10, 64); err != nil || oid <= 0 {
  27. ctx.JSON(nil, ecode.RequestErr)
  28. return
  29. }
  30. tpStr := params.Get("tp")
  31. if tp, err = strconv.ParseInt(tpStr, 10, 64); err != nil || tp <= 0 {
  32. ctx.JSON(nil, ecode.RequestErr)
  33. return
  34. }
  35. ctx.JSON(svr.Stat(ctx, oid, int(tp)))
  36. }
  37. func stats(ctx *bm.Context) {
  38. var (
  39. oids []int64
  40. tp int64
  41. err error
  42. )
  43. params := ctx.Request.Form
  44. oidsStr := params.Get("oids")
  45. if oids, err = xstr.SplitInts(oidsStr); err != nil || len(oids) == 0 || len(oids) > 30 {
  46. ctx.JSON(nil, ecode.RequestErr)
  47. return
  48. }
  49. tpStr := params.Get("tp")
  50. if tp, err = strconv.ParseInt(tpStr, 10, 64); err != nil || tp <= 0 {
  51. ctx.JSON(nil, ecode.RequestErr)
  52. return
  53. }
  54. ctx.JSON(svr.Stats(ctx, oids, int(tp)))
  55. }