mirror of https://github.com/1Panel-dev/1Panel
feat: 代码规范性修改
parent
bf9a37623a
commit
8be00dad7f
|
@ -9,41 +9,43 @@ type ApiGroup struct {
|
|||
var ApiGroupApp = new(ApiGroup)
|
||||
|
||||
var (
|
||||
authService = service.ServiceGroupApp.AuthService
|
||||
dashboardService = service.ServiceGroupApp.DashboardService
|
||||
authService = service.NewIAuthService()
|
||||
dashboardService = service.NewIDashboardService()
|
||||
|
||||
appService = service.NewIAppService()
|
||||
appInstallService = service.ServiceGroupApp.AppInstallService
|
||||
appInstallService = service.NewIAppInstalledService()
|
||||
|
||||
containerService = service.ServiceGroupApp.ContainerService
|
||||
composeTemplateService = service.ServiceGroupApp.ComposeTemplateService
|
||||
imageRepoService = service.ServiceGroupApp.ImageRepoService
|
||||
imageService = service.ServiceGroupApp.ImageService
|
||||
dockerService = service.ServiceGroupApp.DockerService
|
||||
containerService = service.NewIContainerService()
|
||||
composeTemplateService = service.NewIComposeTemplateService()
|
||||
imageRepoService = service.NewIImageRepoService()
|
||||
imageService = service.NewIImageService()
|
||||
dockerService = service.NewIDockerService()
|
||||
|
||||
mysqlService = service.ServiceGroupApp.MysqlService
|
||||
redisService = service.ServiceGroupApp.RedisService
|
||||
mysqlService = service.NewIMysqlService()
|
||||
redisService = service.NewIRedisService()
|
||||
|
||||
cronjobService = service.ServiceGroupApp.CronjobService
|
||||
cronjobService = service.NewICronjobService()
|
||||
|
||||
hostService = service.ServiceGroupApp.HostService
|
||||
groupService = service.ServiceGroupApp.GroupService
|
||||
fileService = service.ServiceGroupApp.FileService
|
||||
hostService = service.NewIHostService()
|
||||
groupService = service.NewIGroupService()
|
||||
fileService = service.NewIFileService()
|
||||
firewallService = service.NewIFirewallService()
|
||||
|
||||
settingService = service.ServiceGroupApp.SettingService
|
||||
backupService = service.ServiceGroupApp.BackupService
|
||||
settingService = service.NewISettingService()
|
||||
backupService = service.NewIBackupService()
|
||||
|
||||
commandService = service.ServiceGroupApp.CommandService
|
||||
commandService = service.NewICommandService()
|
||||
|
||||
websiteService = service.ServiceGroupApp.WebsiteService
|
||||
websiteDnsAccountService = service.ServiceGroupApp.WebsiteDnsAccountService
|
||||
websiteSSLService = service.ServiceGroupApp.WebsiteSSLService
|
||||
websiteAcmeAccountService = service.ServiceGroupApp.WebsiteAcmeAccountService
|
||||
websiteService = service.NewIWebsiteService()
|
||||
websiteDnsAccountService = service.NewIWebsiteDnsAccountService()
|
||||
websiteSSLService = service.NewIWebsiteSSLService()
|
||||
websiteAcmeAccountService = service.NewIWebsiteAcmeAccountService()
|
||||
|
||||
nginxService = service.ServiceGroupApp.NginxService
|
||||
nginxService = service.NewINginxService()
|
||||
|
||||
logService = service.ServiceGroupApp.LogService
|
||||
snapshotService = service.ServiceGroupApp.SnapshotService
|
||||
upgradeService = service.ServiceGroupApp.UpgradeService
|
||||
logService = service.NewILogService()
|
||||
snapshotService = service.NewISnapshotService()
|
||||
upgradeService = service.NewIUpgradeService()
|
||||
|
||||
runtimeService = service.NewRuntimeService()
|
||||
)
|
||||
|
|
|
@ -11,6 +11,24 @@ import (
|
|||
type AppRepo struct {
|
||||
}
|
||||
|
||||
type IAppRepo interface {
|
||||
WithKey(key string) DBOption
|
||||
WithType(typeStr string) DBOption
|
||||
OrderByRecommend() DBOption
|
||||
GetRecommend() DBOption
|
||||
Page(page, size int, opts ...DBOption) (int64, []model.App, error)
|
||||
GetFirst(opts ...DBOption) (model.App, error)
|
||||
GetBy(opts ...DBOption) ([]model.App, error)
|
||||
BatchCreate(ctx context.Context, apps []model.App) error
|
||||
GetByKey(ctx context.Context, key string) (model.App, error)
|
||||
Create(ctx context.Context, app *model.App) error
|
||||
Save(ctx context.Context, app *model.App) error
|
||||
}
|
||||
|
||||
func NewIAppRepo() IAppRepo {
|
||||
return &AppRepo{}
|
||||
}
|
||||
|
||||
func (a AppRepo) WithKey(key string) DBOption {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
return db.Where("key = ?", key)
|
||||
|
|
|
@ -9,6 +9,21 @@ import (
|
|||
type AppDetailRepo struct {
|
||||
}
|
||||
|
||||
type IAppDetailRepo interface {
|
||||
WithVersion(version string) DBOption
|
||||
WithAppId(id uint) DBOption
|
||||
GetFirst(opts ...DBOption) (model.AppDetail, error)
|
||||
Update(ctx context.Context, detail model.AppDetail) error
|
||||
BatchCreate(ctx context.Context, details []model.AppDetail) error
|
||||
DeleteByAppIds(ctx context.Context, appIds []uint) error
|
||||
GetBy(opts ...DBOption) ([]model.AppDetail, error)
|
||||
BatchUpdateBy(maps map[string]interface{}, opts ...DBOption) error
|
||||
}
|
||||
|
||||
func NewIAppDetailRepo() IAppDetailRepo {
|
||||
return &AppDetailRepo{}
|
||||
}
|
||||
|
||||
func (a AppDetailRepo) WithVersion(version string) DBOption {
|
||||
return func(g *gorm.DB) *gorm.DB {
|
||||
return g.Where("version = ?", version)
|
||||
|
|
|
@ -11,6 +11,30 @@ import (
|
|||
|
||||
type AppInstallRepo struct{}
|
||||
|
||||
type IAppInstallRepo interface {
|
||||
WithDetailIdsIn(detailIds []uint) DBOption
|
||||
WithDetailIdNotIn(detailIds []uint) DBOption
|
||||
WithAppId(appId uint) DBOption
|
||||
WithAppIdsIn(appIds []uint) DBOption
|
||||
WithStatus(status string) DBOption
|
||||
WithServiceName(serviceName string) DBOption
|
||||
WithPort(port int) DBOption
|
||||
WithIdNotInWebsite() DBOption
|
||||
ListBy(opts ...DBOption) ([]model.AppInstall, error)
|
||||
GetFirst(opts ...DBOption) (model.AppInstall, error)
|
||||
Create(ctx context.Context, install *model.AppInstall) error
|
||||
Save(install *model.AppInstall) error
|
||||
DeleteBy(opts ...DBOption) error
|
||||
Delete(ctx context.Context, install model.AppInstall) error
|
||||
Page(page, size int, opts ...DBOption) (int64, []model.AppInstall, error)
|
||||
BatchUpdateBy(maps map[string]interface{}, opts ...DBOption) error
|
||||
LoadBaseInfo(key string, name string) (*RootInfo, error)
|
||||
}
|
||||
|
||||
func NewIAppInstallRepo() IAppInstallRepo {
|
||||
return &AppInstallRepo{}
|
||||
}
|
||||
|
||||
func (a *AppInstallRepo) WithDetailIdsIn(detailIds []uint) DBOption {
|
||||
return func(g *gorm.DB) *gorm.DB {
|
||||
return g.Where("app_detail_id in (?)", detailIds)
|
||||
|
|
|
@ -11,6 +11,20 @@ import (
|
|||
type AppInstallResourceRpo struct {
|
||||
}
|
||||
|
||||
type IAppInstallResourceRpo interface {
|
||||
WithAppInstallId(appInstallId uint) DBOption
|
||||
WithLinkId(linkId uint) DBOption
|
||||
WithResourceId(resourceId uint) DBOption
|
||||
GetBy(opts ...DBOption) ([]model.AppInstallResource, error)
|
||||
GetFirst(opts ...DBOption) (model.AppInstallResource, error)
|
||||
Create(ctx context.Context, resource *model.AppInstallResource) error
|
||||
DeleteBy(ctx context.Context, opts ...DBOption) error
|
||||
}
|
||||
|
||||
func NewIAppInstallResourceRpo() IAppInstallResourceRpo {
|
||||
return &AppInstallResourceRpo{}
|
||||
}
|
||||
|
||||
func (a AppInstallResourceRpo) WithAppInstallId(appInstallId uint) DBOption {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
return db.Where("app_install_id = ?", appInstallId)
|
||||
|
|
|
@ -8,6 +8,18 @@ import (
|
|||
type AppTagRepo struct {
|
||||
}
|
||||
|
||||
type IAppTagRepo interface {
|
||||
BatchCreate(ctx context.Context, tags []*model.AppTag) error
|
||||
DeleteByAppIds(ctx context.Context, appIds []uint) error
|
||||
DeleteAll(ctx context.Context) error
|
||||
GetByAppId(appId uint) ([]model.AppTag, error)
|
||||
GetByTagIds(tagIds []uint) ([]model.AppTag, error)
|
||||
}
|
||||
|
||||
func NewIAppTagRepo() IAppTagRepo {
|
||||
return &AppTagRepo{}
|
||||
}
|
||||
|
||||
func (a AppTagRepo) BatchCreate(ctx context.Context, tags []*model.AppTag) error {
|
||||
return getTx(ctx).Create(&tags).Error
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ type IBackupRepo interface {
|
|||
Delete(opts ...DBOption) error
|
||||
DeleteRecord(ctx context.Context, opts ...DBOption) error
|
||||
WithByDetailName(detailName string) DBOption
|
||||
WithByFileName(fileName string) DBOption
|
||||
WithByType(backupType string) DBOption
|
||||
}
|
||||
|
||||
func NewIBackupRepo() IBackupRepo {
|
||||
|
|
|
@ -15,6 +15,7 @@ type ICommandRepo interface {
|
|||
Create(command *model.Command) error
|
||||
Update(id uint, vars map[string]interface{}) error
|
||||
Delete(opts ...DBOption) error
|
||||
Get(opts ...DBOption) (model.Command, error)
|
||||
}
|
||||
|
||||
func NewICommandRepo() ICommandRepo {
|
||||
|
|
|
@ -21,10 +21,15 @@ type ICommonRepo interface {
|
|||
WithIdsIn(ids []uint) DBOption
|
||||
WithByDate(startTime, endTime time.Time) DBOption
|
||||
WithByStartDate(startTime time.Time) DBOption
|
||||
WithByStatus(status string) DBOption
|
||||
}
|
||||
|
||||
type CommonRepo struct{}
|
||||
|
||||
func NewCommonRepo() ICommonRepo {
|
||||
return &CommonRepo{}
|
||||
}
|
||||
|
||||
func (c *CommonRepo) WithByID(id uint) DBOption {
|
||||
return func(g *gorm.DB) *gorm.DB {
|
||||
return g.Where("id = ?", id)
|
||||
|
|
|
@ -17,6 +17,7 @@ type IComposeTemplateRepo interface {
|
|||
|
||||
CreateRecord(compose *model.Compose) error
|
||||
DeleteRecord(opts ...DBOption) error
|
||||
ListRecord() ([]model.Compose, error)
|
||||
}
|
||||
|
||||
func NewIComposeTemplateRepo() IComposeTemplateRepo {
|
||||
|
|
|
@ -26,6 +26,7 @@ type ICronjobRepo interface {
|
|||
DeleteRecord(opts ...DBOption) error
|
||||
StartRecords(cronjobID uint, fromLocal bool, targetPath string) model.JobRecords
|
||||
EndRecords(record model.JobRecords, status, message, records string)
|
||||
PageRecords(page, size int, opts ...DBOption) (int64, []model.JobRecords, error)
|
||||
}
|
||||
|
||||
func NewICronjobRepo() ICronjobRepo {
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
package repo
|
||||
|
||||
type RepoGroup struct {
|
||||
CommonRepo
|
||||
AppRepo
|
||||
AppTagRepo
|
||||
TagRepo
|
||||
AppDetailRepo
|
||||
AppInstallRepo
|
||||
AppInstallResourceRpo
|
||||
ImageRepoRepo
|
||||
ComposeTemplateRepo
|
||||
MysqlRepo
|
||||
CronjobRepo
|
||||
HostRepo
|
||||
CommandRepo
|
||||
GroupRepo
|
||||
SettingRepo
|
||||
BackupRepo
|
||||
WebsiteRepo
|
||||
WebsiteDomainRepo
|
||||
WebsiteDnsAccountRepo
|
||||
WebsiteSSLRepo
|
||||
WebsiteAcmeAccountRepo
|
||||
LogRepo
|
||||
SnapshotRepo
|
||||
}
|
||||
|
||||
var RepoGroupApp = new(RepoGroup)
|
|
@ -25,7 +25,7 @@ func NewIHostRepo() IHostRepo {
|
|||
return &HostRepo{}
|
||||
}
|
||||
|
||||
func (u *HostRepo) Get(opts ...DBOption) (model.Host, error) {
|
||||
func (h *HostRepo) Get(opts ...DBOption) (model.Host, error) {
|
||||
var host model.Host
|
||||
db := global.DB
|
||||
for _, opt := range opts {
|
||||
|
@ -35,7 +35,7 @@ func (u *HostRepo) Get(opts ...DBOption) (model.Host, error) {
|
|||
return host, err
|
||||
}
|
||||
|
||||
func (u *HostRepo) GetList(opts ...DBOption) ([]model.Host, error) {
|
||||
func (h *HostRepo) GetList(opts ...DBOption) ([]model.Host, error) {
|
||||
var hosts []model.Host
|
||||
db := global.DB.Model(&model.Host{})
|
||||
for _, opt := range opts {
|
||||
|
@ -45,7 +45,7 @@ func (u *HostRepo) GetList(opts ...DBOption) ([]model.Host, error) {
|
|||
return hosts, err
|
||||
}
|
||||
|
||||
func (u *HostRepo) Page(page, size int, opts ...DBOption) (int64, []model.Host, error) {
|
||||
func (h *HostRepo) Page(page, size int, opts ...DBOption) (int64, []model.Host, error) {
|
||||
var users []model.Host
|
||||
db := global.DB.Model(&model.Host{})
|
||||
for _, opt := range opts {
|
||||
|
@ -57,7 +57,7 @@ func (u *HostRepo) Page(page, size int, opts ...DBOption) (int64, []model.Host,
|
|||
return count, users, err
|
||||
}
|
||||
|
||||
func (c *HostRepo) WithByInfo(info string) DBOption {
|
||||
func (h *HostRepo) WithByInfo(info string) DBOption {
|
||||
return func(g *gorm.DB) *gorm.DB {
|
||||
if len(info) == 0 {
|
||||
return g
|
||||
|
@ -67,22 +67,22 @@ func (c *HostRepo) WithByInfo(info string) DBOption {
|
|||
}
|
||||
}
|
||||
|
||||
func (u *HostRepo) WithByPort(port uint) DBOption {
|
||||
func (h *HostRepo) WithByPort(port uint) DBOption {
|
||||
return func(g *gorm.DB) *gorm.DB {
|
||||
return g.Where("port = ?", port)
|
||||
}
|
||||
}
|
||||
func (u *HostRepo) WithByUser(user string) DBOption {
|
||||
func (h *HostRepo) WithByUser(user string) DBOption {
|
||||
return func(g *gorm.DB) *gorm.DB {
|
||||
return g.Where("user = ?", user)
|
||||
}
|
||||
}
|
||||
func (u *HostRepo) WithByAddr(addr string) DBOption {
|
||||
func (h *HostRepo) WithByAddr(addr string) DBOption {
|
||||
return func(g *gorm.DB) *gorm.DB {
|
||||
return g.Where("addr = ?", addr)
|
||||
}
|
||||
}
|
||||
func (u *HostRepo) WithByGroup(group string) DBOption {
|
||||
func (h *HostRepo) WithByGroup(group string) DBOption {
|
||||
return func(g *gorm.DB) *gorm.DB {
|
||||
if len(group) == 0 {
|
||||
return g
|
||||
|
@ -91,15 +91,15 @@ func (u *HostRepo) WithByGroup(group string) DBOption {
|
|||
}
|
||||
}
|
||||
|
||||
func (u *HostRepo) Create(host *model.Host) error {
|
||||
func (h *HostRepo) Create(host *model.Host) error {
|
||||
return global.DB.Create(host).Error
|
||||
}
|
||||
|
||||
func (u *HostRepo) Update(id uint, vars map[string]interface{}) error {
|
||||
func (h *HostRepo) Update(id uint, vars map[string]interface{}) error {
|
||||
return global.DB.Model(&model.Host{}).Where("id = ?", id).Updates(vars).Error
|
||||
}
|
||||
|
||||
func (u *HostRepo) Delete(opts ...DBOption) error {
|
||||
func (h *HostRepo) Delete(opts ...DBOption) error {
|
||||
db := global.DB
|
||||
for _, opt := range opts {
|
||||
db = opt(db)
|
||||
|
|
|
@ -8,6 +8,19 @@ import (
|
|||
type TagRepo struct {
|
||||
}
|
||||
|
||||
type ITagRepo interface {
|
||||
BatchCreate(ctx context.Context, tags []*model.Tag) error
|
||||
DeleteAll(ctx context.Context) error
|
||||
All() ([]model.Tag, error)
|
||||
GetByIds(ids []uint) ([]model.Tag, error)
|
||||
GetByKeys(keys []string) ([]model.Tag, error)
|
||||
GetByAppId(appId uint) ([]model.Tag, error)
|
||||
}
|
||||
|
||||
func NewITagRepo() ITagRepo {
|
||||
return &TagRepo{}
|
||||
}
|
||||
|
||||
func (t TagRepo) BatchCreate(ctx context.Context, tags []*model.Tag) error {
|
||||
return getTx(ctx).Create(&tags).Error
|
||||
}
|
||||
|
|
|
@ -7,6 +7,19 @@ import (
|
|||
type WebsiteDnsAccountRepo struct {
|
||||
}
|
||||
|
||||
type IWebsiteDnsAccountRepo interface {
|
||||
Page(page, size int, opts ...DBOption) (int64, []model.WebsiteDnsAccount, error)
|
||||
GetFirst(opts ...DBOption) (*model.WebsiteDnsAccount, error)
|
||||
List(opts ...DBOption) ([]model.WebsiteDnsAccount, error)
|
||||
Create(account model.WebsiteDnsAccount) error
|
||||
Save(account model.WebsiteDnsAccount) error
|
||||
DeleteBy(opts ...DBOption) error
|
||||
}
|
||||
|
||||
func NewIWebsiteDnsAccountRepo() IWebsiteDnsAccountRepo {
|
||||
return &WebsiteDnsAccountRepo{}
|
||||
}
|
||||
|
||||
func (w WebsiteDnsAccountRepo) Page(page, size int, opts ...DBOption) (int64, []model.WebsiteDnsAccount, error) {
|
||||
var accounts []model.WebsiteDnsAccount
|
||||
db := getDb(opts...).Model(&model.WebsiteDnsAccount{})
|
||||
|
|
|
@ -10,6 +10,23 @@ import (
|
|||
type WebsiteDomainRepo struct {
|
||||
}
|
||||
|
||||
type IWebsiteDomainRepo interface {
|
||||
WithWebsiteId(websiteId uint) DBOption
|
||||
WithPort(port int) DBOption
|
||||
WithDomain(domain string) DBOption
|
||||
Page(page, size int, opts ...DBOption) (int64, []model.WebsiteDomain, error)
|
||||
GetFirst(opts ...DBOption) (model.WebsiteDomain, error)
|
||||
GetBy(opts ...DBOption) ([]model.WebsiteDomain, error)
|
||||
BatchCreate(ctx context.Context, domains []model.WebsiteDomain) error
|
||||
Create(ctx context.Context, app *model.WebsiteDomain) error
|
||||
Save(ctx context.Context, app *model.WebsiteDomain) error
|
||||
DeleteBy(ctx context.Context, opts ...DBOption) error
|
||||
}
|
||||
|
||||
func NewIWebsiteDomainRepo() IWebsiteDomainRepo {
|
||||
return &WebsiteDomainRepo{}
|
||||
}
|
||||
|
||||
func (w WebsiteDomainRepo) WithWebsiteId(websiteId uint) DBOption {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
return db.Where("website_id = ?", websiteId)
|
||||
|
|
|
@ -26,6 +26,7 @@ type IAuthService interface {
|
|||
SafeEntrance(c *gin.Context, code string) error
|
||||
Login(c *gin.Context, info dto.Login) (*dto.UserLoginInfo, error)
|
||||
LogOut(c *gin.Context) error
|
||||
MFALogin(c *gin.Context, info dto.MFALogin) (*dto.UserLoginInfo, error)
|
||||
}
|
||||
|
||||
func NewIAuthService() IAuthService {
|
||||
|
|
|
@ -47,6 +47,8 @@ type IContainerService interface {
|
|||
CreateNetwork(req dto.NetworkCreat) error
|
||||
DeleteVolume(req dto.BatchDelete) error
|
||||
CreateVolume(req dto.VolumeCreat) error
|
||||
TestCompose(req dto.ComposeCreate) (bool, error)
|
||||
ComposeUpdate(req dto.ComposeUpdate) error
|
||||
}
|
||||
|
||||
func NewIContainerService() IContainerService {
|
||||
|
|
|
@ -25,6 +25,8 @@ type ICronjobService interface {
|
|||
Update(id uint, req dto.CronjobUpdate) error
|
||||
UpdateStatus(id uint, status string) error
|
||||
Delete(ids []uint) error
|
||||
Download(down dto.CronjobDownload) (string, error)
|
||||
StartJob(cronjob *model.Cronjob) (int, error)
|
||||
}
|
||||
|
||||
func NewICronjobService() ICronjobService {
|
||||
|
|
|
@ -2,77 +2,38 @@ package service
|
|||
|
||||
import "github.com/1Panel-dev/1Panel/backend/app/repo"
|
||||
|
||||
type ServiceGroup struct {
|
||||
AuthService
|
||||
DashboardService
|
||||
|
||||
AppService
|
||||
AppInstallService
|
||||
|
||||
ContainerService
|
||||
ImageService
|
||||
ImageRepoService
|
||||
ComposeTemplateService
|
||||
DockerService
|
||||
|
||||
MysqlService
|
||||
RedisService
|
||||
|
||||
CronjobService
|
||||
|
||||
HostService
|
||||
GroupService
|
||||
CommandService
|
||||
FileService
|
||||
FirewallService
|
||||
|
||||
SettingService
|
||||
BackupService
|
||||
|
||||
WebsiteService
|
||||
WebsiteDnsAccountService
|
||||
WebsiteSSLService
|
||||
WebsiteAcmeAccountService
|
||||
|
||||
NginxService
|
||||
|
||||
LogService
|
||||
SnapshotService
|
||||
UpgradeService
|
||||
}
|
||||
|
||||
var ServiceGroupApp = new(ServiceGroup)
|
||||
|
||||
var (
|
||||
commonRepo = repo.RepoGroupApp.CommonRepo
|
||||
commonRepo = repo.NewCommonRepo()
|
||||
|
||||
appRepo = repo.RepoGroupApp.AppRepo
|
||||
appTagRepo = repo.RepoGroupApp.AppTagRepo
|
||||
appDetailRepo = repo.RepoGroupApp.AppDetailRepo
|
||||
tagRepo = repo.RepoGroupApp.TagRepo
|
||||
appInstallRepo = repo.RepoGroupApp.AppInstallRepo
|
||||
appInstallResourceRepo = repo.RepoGroupApp.AppInstallResourceRpo
|
||||
appRepo = repo.NewIAppRepo()
|
||||
appTagRepo = repo.NewIAppTagRepo()
|
||||
appDetailRepo = repo.NewIAppDetailRepo()
|
||||
tagRepo = repo.NewITagRepo()
|
||||
appInstallRepo = repo.NewIAppInstallRepo()
|
||||
appInstallResourceRepo = repo.NewIAppInstallResourceRpo()
|
||||
|
||||
mysqlRepo = repo.RepoGroupApp.MysqlRepo
|
||||
mysqlRepo = repo.NewIMysqlRepo()
|
||||
|
||||
imageRepoRepo = repo.RepoGroupApp.ImageRepoRepo
|
||||
composeRepo = repo.RepoGroupApp.ComposeTemplateRepo
|
||||
imageRepoRepo = repo.NewIImageRepoRepo()
|
||||
composeRepo = repo.NewIComposeTemplateRepo()
|
||||
|
||||
cronjobRepo = repo.RepoGroupApp.CronjobRepo
|
||||
cronjobRepo = repo.NewICronjobRepo()
|
||||
|
||||
hostRepo = repo.RepoGroupApp.HostRepo
|
||||
groupRepo = repo.RepoGroupApp.GroupRepo
|
||||
commandRepo = repo.RepoGroupApp.CommandRepo
|
||||
hostRepo = repo.NewIHostRepo()
|
||||
groupRepo = repo.NewIGroupRepo()
|
||||
commandRepo = repo.NewICommandRepo()
|
||||
|
||||
settingRepo = repo.RepoGroupApp.SettingRepo
|
||||
backupRepo = repo.RepoGroupApp.BackupRepo
|
||||
settingRepo = repo.NewISettingRepo()
|
||||
backupRepo = repo.NewIBackupRepo()
|
||||
|
||||
websiteRepo = repo.NewIWebsiteRepo()
|
||||
websiteDomainRepo = repo.RepoGroupApp.WebsiteDomainRepo
|
||||
websiteDnsRepo = repo.RepoGroupApp.WebsiteDnsAccountRepo
|
||||
websiteDomainRepo = repo.NewIWebsiteDomainRepo()
|
||||
websiteDnsRepo = repo.NewIWebsiteDnsAccountRepo()
|
||||
websiteSSLRepo = repo.NewISSLRepo()
|
||||
websiteAcmeRepo = repo.NewIAcmeAccountRepo()
|
||||
|
||||
logRepo = repo.RepoGroupApp.LogRepo
|
||||
logRepo = repo.NewILogRepo()
|
||||
snapshotRepo = repo.NewISnapshotRepo()
|
||||
|
||||
runtimeRepo = repo.NewIRunTimeRepo()
|
||||
)
|
||||
|
|
|
@ -22,7 +22,30 @@ import (
|
|||
type FileService struct {
|
||||
}
|
||||
|
||||
func (f FileService) GetFileList(op request.FileOption) (response.FileInfo, error) {
|
||||
type IFileService interface {
|
||||
GetFileList(op request.FileOption) (response.FileInfo, error)
|
||||
SearchUploadWithPage(req request.SearchUploadWithPage) (int64, interface{}, error)
|
||||
GetFileTree(op request.FileOption) ([]response.FileTree, error)
|
||||
Create(op request.FileCreate) error
|
||||
Delete(op request.FileDelete) error
|
||||
BatchDelete(op request.FileBatchDelete) error
|
||||
ChangeMode(op request.FileCreate) error
|
||||
Compress(c request.FileCompress) error
|
||||
DeCompress(c request.FileDeCompress) error
|
||||
GetContent(op request.FileOption) (response.FileInfo, error)
|
||||
SaveContent(edit request.FileEdit) error
|
||||
FileDownload(d request.FileDownload) (string, error)
|
||||
DirSize(req request.DirSizeReq) (response.DirSizeRes, error)
|
||||
ChangeName(req request.FileRename) error
|
||||
Wget(w request.FileWget) (string, error)
|
||||
MvFile(m request.FileMove) error
|
||||
}
|
||||
|
||||
func NewIFileService() IFileService {
|
||||
return &FileService{}
|
||||
}
|
||||
|
||||
func (f *FileService) GetFileList(op request.FileOption) (response.FileInfo, error) {
|
||||
var fileInfo response.FileInfo
|
||||
if _, err := os.Stat(op.Path); err != nil && os.IsNotExist(err) {
|
||||
return fileInfo, nil
|
||||
|
@ -35,7 +58,7 @@ func (f FileService) GetFileList(op request.FileOption) (response.FileInfo, erro
|
|||
return fileInfo, nil
|
||||
}
|
||||
|
||||
func (f FileService) SearchUploadWithPage(req request.SearchUploadWithPage) (int64, interface{}, error) {
|
||||
func (f *FileService) SearchUploadWithPage(req request.SearchUploadWithPage) (int64, interface{}, error) {
|
||||
var (
|
||||
files []response.UploadInfo
|
||||
backData []response.UploadInfo
|
||||
|
@ -65,7 +88,7 @@ func (f FileService) SearchUploadWithPage(req request.SearchUploadWithPage) (int
|
|||
return int64(total), backData, nil
|
||||
}
|
||||
|
||||
func (f FileService) GetFileTree(op request.FileOption) ([]response.FileTree, error) {
|
||||
func (f *FileService) GetFileTree(op request.FileOption) ([]response.FileTree, error) {
|
||||
var treeArray []response.FileTree
|
||||
info, err := files.NewFileInfo(op.FileOption)
|
||||
if err != nil {
|
||||
|
@ -88,7 +111,7 @@ func (f FileService) GetFileTree(op request.FileOption) ([]response.FileTree, er
|
|||
return append(treeArray, node), nil
|
||||
}
|
||||
|
||||
func (f FileService) Create(op request.FileCreate) error {
|
||||
func (f *FileService) Create(op request.FileCreate) error {
|
||||
fo := files.NewFileOp()
|
||||
if fo.Stat(op.Path) {
|
||||
return buserr.New(constant.ErrFileIsExit)
|
||||
|
@ -107,7 +130,7 @@ func (f FileService) Create(op request.FileCreate) error {
|
|||
}
|
||||
}
|
||||
|
||||
func (f FileService) Delete(op request.FileDelete) error {
|
||||
func (f *FileService) Delete(op request.FileDelete) error {
|
||||
fo := files.NewFileOp()
|
||||
if op.IsDir {
|
||||
return fo.DeleteDir(op.Path)
|
||||
|
@ -116,7 +139,7 @@ func (f FileService) Delete(op request.FileDelete) error {
|
|||
}
|
||||
}
|
||||
|
||||
func (f FileService) BatchDelete(op request.FileBatchDelete) error {
|
||||
func (f *FileService) BatchDelete(op request.FileBatchDelete) error {
|
||||
fo := files.NewFileOp()
|
||||
if op.IsDir {
|
||||
for _, file := range op.Paths {
|
||||
|
@ -134,12 +157,12 @@ func (f FileService) BatchDelete(op request.FileBatchDelete) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (f FileService) ChangeMode(op request.FileCreate) error {
|
||||
func (f *FileService) ChangeMode(op request.FileCreate) error {
|
||||
fo := files.NewFileOp()
|
||||
return fo.Chmod(op.Path, fs.FileMode(op.Mode))
|
||||
}
|
||||
|
||||
func (f FileService) Compress(c request.FileCompress) error {
|
||||
func (f *FileService) Compress(c request.FileCompress) error {
|
||||
fo := files.NewFileOp()
|
||||
if !c.Replace && fo.Stat(filepath.Join(c.Dst, c.Name)) {
|
||||
return buserr.New(constant.ErrFileIsExit)
|
||||
|
@ -147,12 +170,12 @@ func (f FileService) Compress(c request.FileCompress) error {
|
|||
return fo.Compress(c.Files, c.Dst, c.Name, files.CompressType(c.Type))
|
||||
}
|
||||
|
||||
func (f FileService) DeCompress(c request.FileDeCompress) error {
|
||||
func (f *FileService) DeCompress(c request.FileDeCompress) error {
|
||||
fo := files.NewFileOp()
|
||||
return fo.Decompress(c.Path, c.Dst, files.CompressType(c.Type))
|
||||
}
|
||||
|
||||
func (f FileService) GetContent(op request.FileOption) (response.FileInfo, error) {
|
||||
func (f *FileService) GetContent(op request.FileOption) (response.FileInfo, error) {
|
||||
info, err := files.NewFileInfo(op.FileOption)
|
||||
if err != nil {
|
||||
return response.FileInfo{}, err
|
||||
|
@ -160,7 +183,7 @@ func (f FileService) GetContent(op request.FileOption) (response.FileInfo, error
|
|||
return response.FileInfo{FileInfo: *info}, nil
|
||||
}
|
||||
|
||||
func (f FileService) SaveContent(edit request.FileEdit) error {
|
||||
func (f *FileService) SaveContent(edit request.FileEdit) error {
|
||||
info, err := files.NewFileInfo(files.FileOption{
|
||||
Path: edit.Path,
|
||||
Expand: false,
|
||||
|
@ -173,18 +196,18 @@ func (f FileService) SaveContent(edit request.FileEdit) error {
|
|||
return fo.WriteFile(edit.Path, strings.NewReader(edit.Content), info.FileMode)
|
||||
}
|
||||
|
||||
func (f FileService) ChangeName(req request.FileRename) error {
|
||||
func (f *FileService) ChangeName(req request.FileRename) error {
|
||||
fo := files.NewFileOp()
|
||||
return fo.Rename(req.OldName, req.NewName)
|
||||
}
|
||||
|
||||
func (f FileService) Wget(w request.FileWget) (string, error) {
|
||||
func (f *FileService) Wget(w request.FileWget) (string, error) {
|
||||
fo := files.NewFileOp()
|
||||
key := "file-wget-" + common.GetUuid()
|
||||
return key, fo.DownloadFileWithProcess(w.Url, filepath.Join(w.Path, w.Name), key)
|
||||
}
|
||||
|
||||
func (f FileService) MvFile(m request.FileMove) error {
|
||||
func (f *FileService) MvFile(m request.FileMove) error {
|
||||
fo := files.NewFileOp()
|
||||
if !fo.Stat(m.NewPath) {
|
||||
return buserr.New(constant.ErrPathNotFound)
|
||||
|
@ -217,7 +240,7 @@ func (f FileService) MvFile(m request.FileMove) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (f FileService) FileDownload(d request.FileDownload) (string, error) {
|
||||
func (f *FileService) FileDownload(d request.FileDownload) (string, error) {
|
||||
filePath := d.Paths[0]
|
||||
if d.Compress {
|
||||
tempPath := filepath.Join(os.TempDir(), fmt.Sprintf("%d", time.Now().UnixNano()))
|
||||
|
@ -233,7 +256,7 @@ func (f FileService) FileDownload(d request.FileDownload) (string, error) {
|
|||
return filePath, nil
|
||||
}
|
||||
|
||||
func (f FileService) DirSize(req request.DirSizeReq) (response.DirSizeRes, error) {
|
||||
func (f *FileService) DirSize(req request.DirSizeReq) (response.DirSizeRes, error) {
|
||||
fo := files.NewFileOp()
|
||||
size, err := fo.GetDirSize(req.Path)
|
||||
if err != nil {
|
||||
|
|
|
@ -34,6 +34,7 @@ type IImageService interface {
|
|||
ImageSave(req dto.ImageSave) error
|
||||
ImagePush(req dto.ImagePush) (string, error)
|
||||
ImageRemove(req dto.BatchDelete) error
|
||||
ImageTag(req dto.ImageTag) error
|
||||
}
|
||||
|
||||
func NewIImageService() IImageService {
|
||||
|
|
|
@ -18,6 +18,18 @@ import (
|
|||
type NginxService struct {
|
||||
}
|
||||
|
||||
type INginxService interface {
|
||||
GetNginxConfig() (response.FileInfo, error)
|
||||
GetConfigByScope(req request.NginxScopeReq) ([]response.NginxParam, error)
|
||||
UpdateConfigByScope(req request.NginxConfigUpdate) error
|
||||
GetStatus() (response.NginxStatus, error)
|
||||
UpdateConfigFile(req request.NginxConfigFileUpdate) error
|
||||
}
|
||||
|
||||
func NewINginxService() INginxService {
|
||||
return &NginxService{}
|
||||
}
|
||||
|
||||
func (n NginxService) GetNginxConfig() (response.FileInfo, error) {
|
||||
nginxInstall, err := getAppInstallByKey(constant.AppOpenresty)
|
||||
if err != nil {
|
||||
|
|
|
@ -50,9 +50,10 @@ type IWebsiteService interface {
|
|||
UpdateWafConfig(req request.WebsiteWafUpdate) error
|
||||
UpdateNginxConfigFile(req request.WebsiteNginxUpdate) error
|
||||
OpWebsiteLog(req request.WebsiteLogReq) (*response.WebsiteLog, error)
|
||||
ChangeDefaultServer(id uint) error
|
||||
}
|
||||
|
||||
func NewWebsiteService() IWebsiteService {
|
||||
func NewIWebsiteService() IWebsiteService {
|
||||
return &WebsiteService{}
|
||||
}
|
||||
|
||||
|
@ -138,7 +139,7 @@ func (w WebsiteService) CreateWebsite(ctx context.Context, create request.Websit
|
|||
req.Name = create.AppInstall.Name
|
||||
req.AppDetailId = create.AppInstall.AppDetailId
|
||||
req.Params = create.AppInstall.Params
|
||||
install, err := ServiceGroupApp.Install(ctx, req)
|
||||
install, err := NewIAppService().Install(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -13,6 +13,16 @@ import (
|
|||
type WebsiteAcmeAccountService struct {
|
||||
}
|
||||
|
||||
type IWebsiteAcmeAccountService interface {
|
||||
Page(search dto.PageInfo) (int64, []response.WebsiteAcmeAccountDTO, error)
|
||||
Create(create request.WebsiteAcmeAccountCreate) (response.WebsiteAcmeAccountDTO, error)
|
||||
Delete(id uint) error
|
||||
}
|
||||
|
||||
func NewIWebsiteAcmeAccountService() IWebsiteAcmeAccountService {
|
||||
return &WebsiteAcmeAccountService{}
|
||||
}
|
||||
|
||||
func (w WebsiteAcmeAccountService) Page(search dto.PageInfo) (int64, []response.WebsiteAcmeAccountDTO, error) {
|
||||
total, accounts, err := websiteAcmeRepo.Page(search.Page, search.PageSize, commonRepo.WithOrderBy("created_at desc"))
|
||||
var accountDTOs []response.WebsiteAcmeAccountDTO
|
||||
|
|
|
@ -13,6 +13,17 @@ import (
|
|||
type WebsiteDnsAccountService struct {
|
||||
}
|
||||
|
||||
type IWebsiteDnsAccountService interface {
|
||||
Page(search dto.PageInfo) (int64, []response.WebsiteDnsAccountDTO, error)
|
||||
Create(create request.WebsiteDnsAccountCreate) (request.WebsiteDnsAccountCreate, error)
|
||||
Update(update request.WebsiteDnsAccountUpdate) (request.WebsiteDnsAccountUpdate, error)
|
||||
Delete(id uint) error
|
||||
}
|
||||
|
||||
func NewIWebsiteDnsAccountService() IWebsiteDnsAccountService {
|
||||
return &WebsiteDnsAccountService{}
|
||||
}
|
||||
|
||||
func (w WebsiteDnsAccountService) Page(search dto.PageInfo) (int64, []response.WebsiteDnsAccountDTO, error) {
|
||||
total, accounts, err := websiteDnsRepo.Page(search.Page, search.PageSize, commonRepo.WithOrderBy("created_at desc"))
|
||||
var accountDTOs []response.WebsiteDnsAccountDTO
|
||||
|
|
|
@ -45,7 +45,7 @@ func Run() {
|
|||
global.LOG.Errorf("start my cronjob failed, err: %v", err)
|
||||
}
|
||||
for i := 0; i < len(cronJobs); i++ {
|
||||
entryID, err := service.ServiceGroupApp.StartJob(&cronJobs[i])
|
||||
entryID, err := service.NewICronjobService().StartJob(&cronJobs[i])
|
||||
if err != nil {
|
||||
global.LOG.Errorf("start %s job %s failed, err: %v", &cronJobs[i].Type, &cronJobs[i].Name, err)
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ func (w *website) Run() {
|
|||
}
|
||||
|
||||
func stopWebsite(websiteId uint, wg *sync.WaitGroup) {
|
||||
websiteService := service.NewWebsiteService()
|
||||
websiteService := service.NewIWebsiteService()
|
||||
req := request.WebsiteOp{
|
||||
ID: websiteId,
|
||||
Operate: constant.StopWeb,
|
||||
|
|
Loading…
Reference in New Issue