flow.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/admin/main/aegis/model/common"
  5. "go-common/app/admin/main/aegis/model/net"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. )
  10. func listFlow(c *bm.Context) {
  11. pm := new(net.ListNetElementParam)
  12. if err := c.Bind(pm); err != nil {
  13. c.JSON(nil, ecode.RequestErr)
  14. return
  15. }
  16. if pm.Sort != "desc" && pm.Sort != "asc" {
  17. pm.Sort = "desc"
  18. }
  19. c.JSON(srv.GetFlowList(c, pm))
  20. }
  21. func getFlowByNet(c *bm.Context) {
  22. pm := c.Request.Form.Get("net_id")
  23. id, err := strconv.ParseInt(pm, 10, 64)
  24. if err != nil {
  25. c.JSON(nil, ecode.RequestErr)
  26. return
  27. }
  28. c.JSON(srv.GetFlowByNet(c, id))
  29. }
  30. func showFlow(c *bm.Context) {
  31. pm := c.Request.Form.Get("id")
  32. id, err := strconv.ParseInt(pm, 10, 64)
  33. if err != nil {
  34. c.JSON(nil, ecode.RequestErr)
  35. return
  36. }
  37. c.JSON(srv.ShowFlow(c, id))
  38. }
  39. func preFlow(pm *net.FlowEditParam) (invalid bool) {
  40. pm.ChName = common.FilterChname(pm.ChName)
  41. pm.Name = common.FilterName(pm.Name)
  42. invalid = pm.ChName == "" || pm.Name == ""
  43. return
  44. }
  45. func addFlow(c *bm.Context) {
  46. pm := new(net.FlowEditParam)
  47. if err := c.Bind(pm); err != nil || pm.NetID <= 0 {
  48. log.Error("addFlow bind params error(%v) pm(%+v)", err, pm)
  49. c.JSON(nil, ecode.RequestErr)
  50. return
  51. }
  52. if preFlow(pm) {
  53. c.JSON(nil, ecode.RequestErr)
  54. return
  55. }
  56. admin := uid(c)
  57. id, err, msg := srv.AddFlow(c, admin, pm)
  58. c.JSONMap(map[string]interface{}{
  59. "id": id,
  60. "message": msg,
  61. }, err)
  62. }
  63. func updateFlow(c *bm.Context) {
  64. pm := new(net.FlowEditParam)
  65. if err := c.Bind(pm); err != nil || pm.ID <= 0 {
  66. c.JSON(nil, ecode.RequestErr)
  67. return
  68. }
  69. if preFlow(pm) {
  70. c.JSON(nil, ecode.RequestErr)
  71. return
  72. }
  73. admin := uid(c)
  74. err, msg := srv.UpdateFlow(c, admin, pm)
  75. c.JSONMap(map[string]interface{}{"message": msg}, err)
  76. }
  77. func switchFlow(c *bm.Context) {
  78. pm := new(net.SwitchParam)
  79. if err := c.Bind(pm); err != nil {
  80. c.JSON(nil, ecode.RequestErr)
  81. return
  82. }
  83. c.JSON(nil, srv.SwitchFlow(c, pm.ID, pm.Disable))
  84. }