type WorkFlow struct {
gorm.Model
Name string `json:"name"`
Namespace string `json:"namespace"`
Ingress string `json:"ingress"`
Service string `json:"service"`
Deployment string `json:"deployment"`
Replicas int32 `json:"replicas"`
ServiceType string `json:"service_type" gorm:"column:service_type"`
}
//定义返回数据结构
type WorkFlowResp struct {
Items []*model.WorkFlow `json:"items"`
Total int64 `json:"total"`
}
//查询workflow列表 通过page 和 limit
func (w *WorkFlow) GetListWorFlow(name string, page, limit int) (*WorkFlowResp, error) {
var workFlow []*model.WorkFlow
var total int64
err := DBConn.Model(&model.WorkFlow{}).Where("name like ?", "%"+name+"%").Count(&total).Limit(limit).Offset((page - 1) * limit).Find(&workFlow).Error
if err != nil {
fmt.Println("查询workflow列表失败:", err)
return nil, err
}
// }
resp := &WorkFlowResp{
Items: workFlow,
Total: total,
}
return resp, nil