1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-02-07 17:10:07 +08:00

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() websites, _ := websiteRepo.GetBy()
for _, website := range websites { for _, website := range websites {
res = append(res, dto.AppResource{ 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() databases, _ := mysqlRepo.List()
for _, database := range databases { for _, database := range databases {
res = append(res, dto.AppResource{ res = append(res, dto.AppResource{
@ -324,13 +324,13 @@ func (a AppInstallService) GetDefaultConfigByKey(key string) (string, error) {
return "", err return "", err
} }
filePath := path.Join(constant.AppResourceDir, appInstall.App.Key, "versions", appInstall.Version, "conf") 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") filePath = path.Join(filePath, "my.cnf")
} }
if key == "redis" { if key == constant.AppRedis {
filePath = path.Join(filePath, "redis.conf") filePath = path.Join(filePath, "redis.conf")
} }
if key == "nginx" { if key == constant.AppNginx {
filePath = path.Join(filePath, "nginx.conf") filePath = path.Join(filePath, "nginx.conf")
} }
contentByte, err := os.ReadFile(filePath) contentByte, err := os.ReadFile(filePath)

View File

@ -19,11 +19,11 @@ type NginxService struct {
} }
func (n NginxService) GetNginxConfig() (dto.FileInfo, error) { func (n NginxService) GetNginxConfig() (dto.FileInfo, error) {
nginxInstall, err := getAppInstallByKey("nginx") nginxInstall, err := getAppInstallByKey(constant.AppNginx)
if err != nil { if err != nil {
return dto.FileInfo{}, err 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{ info, err := files.NewFileInfo(files.FileOption{
Path: configPath, Path: configPath,
Expand: true, 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 { if err := fileOp.WriteFile(req.FilePath, strings.NewReader(req.Content), 0644); err != nil {
return err return err
} }
nginxInstall, err := getAppInstallByKey("nginx") nginxInstall, err := getAppInstallByKey(constant.AppNginx)
if err != nil { if err != nil {
return err return err
} }

View File

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

View File

@ -388,7 +388,7 @@ func (w WebsiteService) GetWebsiteNginxConfig(websiteId uint) (dto.FileInfo, err
return 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 { if err != nil {
return dto.FileInfo{}, err return dto.FileInfo{}, err
} }
@ -397,7 +397,7 @@ func (w WebsiteService) GetWebsiteNginxConfig(websiteId uint) (dto.FileInfo, err
return 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{ info, err := files.NewFileInfo(files.FileOption{
Path: configPath, Path: configPath,
@ -524,7 +524,7 @@ func (w WebsiteService) PreInstallCheck(req request.WebsiteInstallCheckReq) ([]r
showErr = false showErr = false
) )
app, err := appRepo.GetFirst(appRepo.WithKey("nginx")) app, err := appRepo.GetFirst(appRepo.WithKey(constant.AppNginx))
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -67,11 +67,11 @@ func (w WebsiteSSLService) Create(create dto.WebsiteSSLCreate) (dto.WebsiteSSLCr
return res, err return res, err
} }
case dto.Http: case dto.Http:
appInstall, err := getAppInstallByKey("nginx") appInstall, err := getAppInstallByKey(constant.AppNginx)
if err != nil { if err != nil {
return dto.WebsiteSSLCreate{}, err 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 return res, err
} }
case dto.DnsManual: case dto.DnsManual:
@ -138,11 +138,11 @@ func (w WebsiteSSLService) Renew(sslId uint) error {
return err return err
} }
case dto.Http: case dto.Http:
appInstall, err := getAppInstallByKey("nginx") appInstall, err := getAppInstallByKey(constant.AppNginx)
if err != nil { if err != nil {
return err 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 return err
} }
case dto.DnsManual: case dto.DnsManual:

View File

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

View File

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

View File

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