Beispiel #1
0
// @Title List
// @Description find cluster by conditions
// @Param	body		body 	models.CommonRequestBody	true		"the rule you want to get"
// @Success 200 {object} models.ClusterInfo
// @Failure 400 invalid request message
// @router /list [post]
func (self *ClusterController) 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(400)
		self.ServeJSON()
		return
	}

	if body.All {
		list := models.GetAllCluster()
		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.GetCluster(cid); err == nil {
			list[i] = c
		} else {
			list[i] = models.ClusterInfo{
				ID:    cid,
				Error: ErrNotFound.Error(),
			}
		}
	}
	self.Data["json"] = list
	self.ServeJSON()
}
Beispiel #2
0
// @Title GetAll
// @Description find all cluster
// @Success 200 {object} models.ClusterInfo
// @router / [get]
func (self *ClusterController) GetAll() {
	clusterInfos := models.GetAllCluster()
	self.Data["json"] = clusterInfos
	self.ServeJSON()
	return
}