123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- package http
- import (
- "strconv"
- "go-common/app/admin/main/aegis/model/common"
- "go-common/app/admin/main/aegis/model/net"
- "go-common/library/ecode"
- "go-common/library/log"
- bm "go-common/library/net/http/blademaster"
- )
- func listFlow(c *bm.Context) {
- pm := new(net.ListNetElementParam)
- if err := c.Bind(pm); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if pm.Sort != "desc" && pm.Sort != "asc" {
- pm.Sort = "desc"
- }
- c.JSON(srv.GetFlowList(c, pm))
- }
- func getFlowByNet(c *bm.Context) {
- pm := c.Request.Form.Get("net_id")
- id, err := strconv.ParseInt(pm, 10, 64)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- c.JSON(srv.GetFlowByNet(c, id))
- }
- func showFlow(c *bm.Context) {
- pm := c.Request.Form.Get("id")
- id, err := strconv.ParseInt(pm, 10, 64)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- c.JSON(srv.ShowFlow(c, id))
- }
- func preFlow(pm *net.FlowEditParam) (invalid bool) {
- pm.ChName = common.FilterChname(pm.ChName)
- pm.Name = common.FilterName(pm.Name)
- invalid = pm.ChName == "" || pm.Name == ""
- return
- }
- func addFlow(c *bm.Context) {
- pm := new(net.FlowEditParam)
- if err := c.Bind(pm); err != nil || pm.NetID <= 0 {
- log.Error("addFlow bind params error(%v) pm(%+v)", err, pm)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if preFlow(pm) {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- admin := uid(c)
- id, err, msg := srv.AddFlow(c, admin, pm)
- c.JSONMap(map[string]interface{}{
- "id": id,
- "message": msg,
- }, err)
- }
- func updateFlow(c *bm.Context) {
- pm := new(net.FlowEditParam)
- if err := c.Bind(pm); err != nil || pm.ID <= 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if preFlow(pm) {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- admin := uid(c)
- err, msg := srv.UpdateFlow(c, admin, pm)
- c.JSONMap(map[string]interface{}{"message": msg}, err)
- }
- func switchFlow(c *bm.Context) {
- pm := new(net.SwitchParam)
- if err := c.Bind(pm); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- c.JSON(nil, srv.SwitchFlow(c, pm.ID, pm.Disable))
- }
|