style: 修改nginx的constant

This commit is contained in:
zhengkunwang223 2022-12-13 20:03:54 +08:00 committed by zhengkunwang223
parent f85d17cf65
commit a353adc4b9
8 changed files with 33 additions and 30 deletions

View File

@ -285,7 +285,7 @@ func (a AppInstallService) DeleteCheck(installId uint) ([]dto.AppResource, error
})
}
}
if app.Key == "nginx" {
if app.Key == constant.AppNginx {
websites, _ := websiteRepo.GetBy()
for _, website := range websites {
res = append(res, dto.AppResource{
@ -305,7 +305,7 @@ func (a AppInstallService) DeleteCheck(installId uint) ([]dto.AppResource, error
}
}
if app.Key == "mysql" {
if app.Key == constant.AppMysql {
databases, _ := mysqlRepo.List()
for _, database := range databases {
res = append(res, dto.AppResource{
@ -324,13 +324,13 @@ func (a AppInstallService) GetDefaultConfigByKey(key string) (string, error) {
return "", err
}
filePath := path.Join(constant.AppResourceDir, appInstall.App.Key, "versions", appInstall.Version, "conf")
if key == "mysql" {
if key == constant.AppMysql {
filePath = path.Join(filePath, "my.cnf")
}
if key == "redis" {
if key == constant.AppRedis {
filePath = path.Join(filePath, "redis.conf")
}
if key == "nginx" {
if key == constant.AppNginx {
filePath = path.Join(filePath, "nginx.conf")
}
contentByte, err := os.ReadFile(filePath)

View File

@ -19,11 +19,11 @@ type NginxService struct {
}
func (n NginxService) GetNginxConfig() (dto.FileInfo, error) {
nginxInstall, err := getAppInstallByKey("nginx")
nginxInstall, err := getAppInstallByKey(constant.AppNginx)
if err != nil {
return dto.FileInfo{}, err
}
configPath := path.Join(constant.AppInstallDir, "nginx", nginxInstall.Name, "conf", "nginx.conf")
configPath := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name, "conf", "nginx.conf")
info, err := files.NewFileInfo(files.FileOption{
Path: configPath,
Expand: true,
@ -95,7 +95,7 @@ func (n NginxService) UpdateConfigFile(req request.NginxConfigFileUpdate) error
if err := fileOp.WriteFile(req.FilePath, strings.NewReader(req.Content), 0644); err != nil {
return err
}
nginxInstall, err := getAppInstallByKey("nginx")
nginxInstall, err := getAppInstallByKey(constant.AppNginx)
if err != nil {
return err
}

View File

@ -25,7 +25,7 @@ func getNginxFull(website *model.Website) (dto.NginxFull, error) {
return nginxFull, err
}
nginxFull.Install = nginxInstall
nginxFull.Dir = path.Join(constant.AppInstallDir, "nginx", nginxInstall.Name)
nginxFull.Dir = path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name)
nginxFull.ConfigDir = path.Join(nginxFull.Dir, "conf")
nginxFull.ConfigFile = "nginx.conf"
nginxFull.SiteDir = path.Join(nginxFull.Dir, "www")
@ -47,7 +47,7 @@ func getNginxFull(website *model.Website) (dto.NginxFull, error) {
nginxFull.Website = *website
var siteNginxConfig dto.NginxConfig
nginxFileName := website.Alias + ".conf"
siteConfigPath := path.Join(constant.AppInstallDir, "nginx", nginxInstall.Name, "conf", "conf.d", nginxFileName)
siteConfigPath := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name, "conf", "conf.d", nginxFileName)
siteNginxConfig.FilePath = siteConfigPath
siteNginxContent, err := os.ReadFile(siteConfigPath)
if err != nil {

View File

@ -388,7 +388,7 @@ func (w WebsiteService) GetWebsiteNginxConfig(websiteId uint) (dto.FileInfo, err
return dto.FileInfo{}, err
}
nginxApp, err := appRepo.GetFirst(appRepo.WithKey("nginx"))
nginxApp, err := appRepo.GetFirst(appRepo.WithKey(constant.AppNginx))
if err != nil {
return dto.FileInfo{}, err
}
@ -397,7 +397,7 @@ func (w WebsiteService) GetWebsiteNginxConfig(websiteId uint) (dto.FileInfo, err
return dto.FileInfo{}, err
}
configPath := path.Join(constant.AppInstallDir, "nginx", nginxInstall.Name, "conf", "conf.d", website.Alias+".conf")
configPath := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name, "conf", "conf.d", website.Alias+".conf")
info, err := files.NewFileInfo(files.FileOption{
Path: configPath,
@ -524,7 +524,7 @@ func (w WebsiteService) PreInstallCheck(req request.WebsiteInstallCheckReq) ([]r
showErr = false
)
app, err := appRepo.GetFirst(appRepo.WithKey("nginx"))
app, err := appRepo.GetFirst(appRepo.WithKey(constant.AppNginx))
if err != nil {
return nil, err
}

View File

@ -67,11 +67,11 @@ func (w WebsiteSSLService) Create(create dto.WebsiteSSLCreate) (dto.WebsiteSSLCr
return res, err
}
case dto.Http:
appInstall, err := getAppInstallByKey("nginx")
appInstall, err := getAppInstallByKey(constant.AppNginx)
if err != nil {
return dto.WebsiteSSLCreate{}, err
}
if err := client.UseHTTP(path.Join(constant.AppInstallDir, "nginx", appInstall.Name, "root")); err != nil {
if err := client.UseHTTP(path.Join(constant.AppInstallDir, constant.AppNginx, appInstall.Name, "root")); err != nil {
return res, err
}
case dto.DnsManual:
@ -138,11 +138,11 @@ func (w WebsiteSSLService) Renew(sslId uint) error {
return err
}
case dto.Http:
appInstall, err := getAppInstallByKey("nginx")
appInstall, err := getAppInstallByKey(constant.AppNginx)
if err != nil {
return err
}
if err := client.UseHTTP(path.Join(constant.AppInstallDir, "nginx", appInstall.Name, "root")); err != nil {
if err := client.UseHTTP(path.Join(constant.AppInstallDir, constant.AppNginx, appInstall.Name, "root")); err != nil {
return err
}
case dto.DnsManual:

View File

@ -48,12 +48,12 @@ func getDomain(domainStr string, websiteID uint) (model.WebsiteDomain, error) {
}
func createStaticHtml(website *model.Website) error {
nginxInstall, err := getAppInstallByKey("nginx")
nginxInstall, err := getAppInstallByKey(constant.AppNginx)
if err != nil {
return err
}
indexFolder := path.Join(constant.AppInstallDir, "nginx", nginxInstall.Name, "www", "sites", website.Alias)
indexFolder := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name, "www", "sites", website.Alias)
indexPath := path.Join(indexFolder, "index.html")
indexContent := string(nginx_conf.Index)
fileOp := files.NewFileOp()
@ -74,7 +74,7 @@ func createStaticHtml(website *model.Website) error {
}
func createWebsiteFolder(nginxInstall model.AppInstall, website *model.Website) error {
nginxFolder := path.Join(constant.AppInstallDir, "nginx", nginxInstall.Name)
nginxFolder := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name)
siteFolder := path.Join(nginxFolder, "www", "sites", website.Alias)
fileOp := files.NewFileOp()
if !fileOp.Stat(siteFolder) {
@ -98,7 +98,7 @@ func createWebsiteFolder(nginxInstall model.AppInstall, website *model.Website)
}
func configDefaultNginx(website *model.Website, domains []model.WebsiteDomain) error {
nginxInstall, err := getAppInstallByKey("nginx")
nginxInstall, err := getAppInstallByKey(constant.AppNginx)
if err != nil {
return err
}
@ -107,7 +107,7 @@ func configDefaultNginx(website *model.Website, domains []model.WebsiteDomain) e
}
nginxFileName := website.Alias + ".conf"
configPath := path.Join(constant.AppInstallDir, "nginx", nginxInstall.Name, "conf", "conf.d", nginxFileName)
configPath := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name, "conf", "conf.d", nginxFileName)
nginxContent := string(nginx_conf.WebsiteDefault)
config := parser.NewStringParser(nginxContent).Parse()
servers := config.FindServers()
@ -156,7 +156,7 @@ func configDefaultNginx(website *model.Website, domains []model.WebsiteDomain) e
}
func delNginxConfig(website model.Website, force bool) error {
nginxApp, err := appRepo.GetFirst(appRepo.WithKey("nginx"))
nginxApp, err := appRepo.GetFirst(appRepo.WithKey(constant.AppNginx))
if err != nil {
return err
}
@ -169,7 +169,7 @@ func delNginxConfig(website model.Website, force bool) error {
}
nginxFileName := website.Alias + ".conf"
configPath := path.Join(constant.AppInstallDir, "nginx", nginxInstall.Name, "conf", "conf.d", nginxFileName)
configPath := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name, "conf", "conf.d", nginxFileName)
fileOp := files.NewFileOp()
if !fileOp.Stat(configPath) {
@ -178,7 +178,7 @@ func delNginxConfig(website model.Website, force bool) error {
if err := fileOp.DeleteFile(configPath); err != nil {
return err
}
sitePath := path.Join(constant.AppInstallDir, "nginx", nginxInstall.Name, "www", "sites", website.PrimaryDomain)
sitePath := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name, "www", "sites", website.PrimaryDomain)
if fileOp.Stat(sitePath) {
_ = fileOp.DeleteDir(sitePath)
}
@ -247,7 +247,7 @@ func getKeysFromStaticFile(scope dto.NginxKey) []string {
}
func createPemFile(website model.Website, websiteSSL model.WebsiteSSL) error {
nginxApp, err := appRepo.GetFirst(appRepo.WithKey("nginx"))
nginxApp, err := appRepo.GetFirst(appRepo.WithKey(constant.AppNginx))
if err != nil {
return err
}
@ -256,7 +256,7 @@ func createPemFile(website model.Website, websiteSSL model.WebsiteSSL) error {
return err
}
configDir := path.Join(constant.AppInstallDir, "nginx", nginxInstall.Name, "www", "sites", website.Alias, "ssl")
configDir := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name, "www", "sites", website.Alias, "ssl")
fileOp := files.NewFileOp()
if !fileOp.Stat(configDir) {
@ -397,7 +397,7 @@ func handleWebsiteBackup(backupType, baseDir, backupDir, domain, backupName stri
return err
}
nginxInfo, err := appInstallRepo.LoadBaseInfoByKey("nginx")
nginxInfo, err := appInstallRepo.LoadBaseInfoByKey(constant.AppNginx)
if err != nil {
return err
}
@ -450,7 +450,7 @@ func handleWebsiteBackup(backupType, baseDir, backupDir, domain, backupName stri
}
func handleWebsiteRecover(website *model.Website, fileDir string) error {
nginxInfo, err := appInstallRepo.LoadBaseInfoByKey("nginx")
nginxInfo, err := appInstallRepo.LoadBaseInfoByKey(constant.AppNginx)
if err != nil {
return err
}

View File

@ -12,7 +12,6 @@ type BusinessError struct {
}
func (e BusinessError) Error() string {
content := ""
if e.Detail != nil {
content = i18n.GetErrMsg(e.Msg, map[string]interface{}{"detail": e.Detail})

View File

@ -11,4 +11,8 @@ const (
AppNormal = "Normal"
AppTakeDown = "TakeDown"
AppNginx = "nginx"
AppMysql = "mysql"
AppRedis = "redis"
)