Пример #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()
}
Пример #2
0
// @Title Get
// @Description find cluster by cluster_ID
// @Param	clusterID		path 	string	true		"The clusterID you want to get"
// @Success 200 {object} models.ClusterInfo
// @Failure 403 :clusterID is empty
// @router /:clusterID [get]
func (self *ClusterController) Get() {
	id := self.GetString(":clusterID")

	if strings.TrimSpace(id) != "" {
		err, clusterInfo := models.GetCluster(id)

		if err != nil {
			self.Data["json"] = models.NewInternalError(403, err)
			self.Ctx.Output.SetStatus(403)
		} else {
			self.Data["json"] = clusterInfo
		}

	} else {
		self.Data["json"] = models.NewInternalError(403,
			fmt.Errorf("%s cluster_id is empty", id))
		self.Ctx.Output.SetStatus(403)
	}
	self.ServeJSON()
}