Exemplo n.º 1
0
// @Title List
// @Description find networks by condition
// @Param	body		body 	models.CommonRequestBody	true		"the networks you want to get"
// @Success 200 {object} models.IPtable
// @Failure 400 invalid request message
// @router /list [post]
func (self *NetworkController) List() {
	var body models.CommonRequestBody
	err := json.Unmarshal(self.Ctx.Input.CopyBody(beego.BConfig.MaxMemory), &body)
	if err != nil {
		self.Data["json"] = models.NewInternalError(400, err)
		self.Ctx.Output.SetStatus(403)
		self.ServeJSON()
		return
	}

	if body.All {
		list := models.GetAllIPtable()
		self.Data["json"] = list
		self.ServeJSON()
		return
	}

	list := make([]interface{}, len(body.ID))
	for i, cid := range body.ID {
		if strings.TrimSpace(cid) == "" {
			continue
		}
		if err, c := models.GetIPtable(cid); err == nil {
			list[i] = c
		} else {
			list[i] = models.IPtable{
				ID:    cid,
				Error: ErrNotFound.Error(),
			}
		}
	}
	self.Data["json"] = list
	self.ServeJSON()
}
Exemplo n.º 2
0
// @Title GetAll
// @Description find all networks
// @Success 200 {object} models.IPtable
// @router / [get]
func (self *NetworkController) GetAll() {
	iptables := models.GetAllIPtable()

	self.Data["json"] = iptables
	self.ServeJSON()
	return
}