package settings import ( "errors" "nginx-ui/server/base" "nginx-ui/server/models" "nginx-ui/server/utils" ) type RouteController struct { base.Controller } // List 查看全部路由 func (c *RouteController) List() { current := c.RequiredUser() if current == nil { return } listVo := RouteListVo{} if !c.ReadBody(&listVo) { return } if listVo.Uid == -1 { listVo.Uid = current.Id } list, err := Route.GetList(listVo) if err != nil { c.ErrorJson(err) return } c.SetData(list).Json() } // Save 新增或者修改用户 func (c *RouteController) Save() { current := c.RequiredUser() if current == nil { return } route := models.SettingRoute{} if !c.ReadBody(&route) { return } if route.Uid == -1 { route.Uid = current.Id if route.Id == "" { route.Id = utils.NextIdStr() } } if route.Id == "" { c.ErrorJson(errors.New("ID不能为空")) return } resp, err := Route.Save(&route) if err != nil { c.ErrorJson(err) return } c.SetData(resp).Json() } func (c *RouteController) Delete() { current := c.RequiredUser() if current == nil { return } route := models.SettingRoute{} if !c.ReadBody(&route) { return } err := Route.Delete(route.Id) if err != nil { c.ErrorJson(err) return } c.Json() }