monitor.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package http
  2. import (
  3. "go-common/app/admin/main/member/model"
  4. bm "go-common/library/net/http/blademaster"
  5. )
  6. func monitors(ctx *bm.Context) {
  7. arg := &model.ArgMonitor{}
  8. if err := ctx.Bind(arg); err != nil {
  9. return
  10. }
  11. if arg.Pn <= 0 {
  12. arg.Pn = 1
  13. }
  14. if arg.Ps <= 0 {
  15. arg.Ps = 10
  16. }
  17. mns, total, err := svc.Monitors(ctx, arg)
  18. if err != nil {
  19. ctx.JSON(nil, err)
  20. return
  21. }
  22. res := map[string]interface{}{
  23. "monitors": mns,
  24. "page": map[string]int{
  25. "num": arg.Pn,
  26. "size": arg.Ps,
  27. "total": total,
  28. },
  29. }
  30. ctx.JSON(res, nil)
  31. }
  32. func addMonitor(ctx *bm.Context) {
  33. arg := &model.ArgAddMonitor{}
  34. if err := ctx.Bind(arg); err != nil {
  35. return
  36. }
  37. arg.OperatorID = operatorID(ctx)
  38. ctx.JSON(nil, svc.AddMonitor(ctx, arg))
  39. }
  40. func delMonitor(ctx *bm.Context) {
  41. arg := &model.ArgDelMonitor{}
  42. if err := ctx.Bind(arg); err != nil {
  43. return
  44. }
  45. arg.OperatorID = operatorID(ctx)
  46. ctx.JSON(nil, svc.DelMonitor(ctx, arg))
  47. }
  48. func operatorID(ctx *bm.Context) int64 {
  49. uidI, ok := ctx.Get("uid")
  50. if !ok {
  51. return 0
  52. }
  53. uid, _ := uidI.(int64)
  54. return uid
  55. }