package proxy import ( "github.com/astaxie/beego/logs" "github.com/astaxie/beego/orm" "nginx-ui/server/models" ) type Service struct { } func NewProxyService() *Service { return &Service{} } func (u *Service) GetAll(req *GetProxyListReq) []*models.ProxyEntity { o := orm.NewOrm() qs := o.QueryTable(&models.ProxyEntity{}) if req.Enable { qs = qs.Filter("Enable", true) } if req.Ref != "" { qs = qs.Filter("Ref", req.Ref) } if req.Uid > 0 { qs = qs.Filter("UserId", req.Uid) } list := make([]*models.ProxyEntity, 0) _, err := qs.All(&list) if err != nil { logs.Error("query proxies fail: %v", err) return make([]*models.ProxyEntity, 0) } return list } func (u *Service) Update(req *models.ProxyEntity) (*models.ProxyEntity, error) { o := orm.NewOrm() _, err := models.InsertOrUpdate(o, req) if err != nil { return nil, err } return req, nil } func (u *Service) Delete(req *models.ProxyEntity) (*models.ProxyEntity, error) { o := orm.NewOrm() _, err := o.Delete(&models.ProxyEntity{Id: req.Id}) if err != nil { return nil, err } return req, nil }