2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 10:17:17 +08:00

chore: fix lint

This commit is contained in:
耗子
2024-05-30 02:27:35 +08:00
parent 73cc5a35ad
commit 76e992cc9e
8 changed files with 73 additions and 60 deletions

View File

@@ -1,6 +1,8 @@
package services
import (
"errors"
"fmt"
"strings"
"github.com/TheTNB/panel/app/models"
@@ -17,43 +19,39 @@ func NewCronImpl() *CronImpl {
// AddToSystem 添加到系统
func (r *CronImpl) AddToSystem(cron models.Cron) error {
if tools.IsRHEL() {
if _, err := tools.Exec("echo \"" + cron.Time + " " + cron.Shell + " >> " + cron.Log + " 2>&1\" >> /var/spool/cron/root"); err != nil {
return err
}
if _, err := tools.Exec("systemctl restart crond"); err != nil {
return err
}
} else {
if _, err := tools.Exec("echo \"" + cron.Time + " " + cron.Shell + " >> " + cron.Log + " 2>&1\" >> /var/spool/cron/crontabs/root"); err != nil {
return err
}
if _, err := tools.Exec("systemctl restart cron"); err != nil {
if _, err := tools.Exec(fmt.Sprintf(`echo "%s %s >> %s 2>&1" >> /var/spool/cron/root`, cron.Time, cron.Shell, cron.Log)); err != nil {
return err
}
return tools.ServiceRestart("crond")
}
return nil
if tools.IsDebian() {
if _, err := tools.Exec(fmt.Sprintf(`echo "%s %s >> %s 2>&1" >> /var/spool/cron/crontabs/root`, cron.Time, cron.Shell, cron.Log)); err != nil {
return err
}
return tools.ServiceRestart("cron")
}
return errors.New("不支持的系统")
}
// DeleteFromSystem 从系统中删除
func (r *CronImpl) DeleteFromSystem(cron models.Cron) error {
// 需要转义Shell路径的/为\/
// 需要转义 shell 路径的/为\/
cron.Shell = strings.ReplaceAll(cron.Shell, "/", "\\/")
if tools.IsRHEL() {
if _, err := tools.Exec("sed -i '/" + cron.Shell + "/d' /var/spool/cron/root"); err != nil {
return err
}
if _, err := tools.Exec("systemctl restart crond"); err != nil {
return err
}
} else {
return tools.ServiceRestart("crond")
}
if tools.IsDebian() {
if _, err := tools.Exec("sed -i '/" + cron.Shell + "/d' /var/spool/cron/crontabs/root"); err != nil {
return err
}
if _, err := tools.Exec("systemctl restart cron"); err != nil {
return err
}
return tools.ServiceRestart("cron")
}
return nil
return errors.New("不支持的系统")
}

View File

@@ -58,7 +58,7 @@ func (r *PluginImpl) All() []types.Plugin {
return plugins
}
// GetBySlug 根据slug获取插件
// GetBySlug 根据 slug 获取插件
func (r *PluginImpl) GetBySlug(slug string) types.Plugin {
for _, item := range r.All() {
if item.Slug == slug {
@@ -69,7 +69,7 @@ func (r *PluginImpl) GetBySlug(slug string) types.Plugin {
return types.Plugin{}
}
// GetInstalledBySlug 根据slug获取已安装的插件
// GetInstalledBySlug 根据 slug 获取已安装的插件
func (r *PluginImpl) GetInstalledBySlug(slug string) models.Plugin {
var plugin models.Plugin
if err := facades.Orm().Query().Where("slug", slug).Get(&plugin); err != nil {

View File

@@ -2,8 +2,10 @@
package services
import (
"github.com/TheTNB/panel/app/models"
"github.com/goravel/framework/facades"
"github.com/TheTNB/panel/app/models"
"github.com/TheTNB/panel/pkg/tools"
)
type SettingImpl struct {
@@ -17,19 +19,11 @@ func NewSettingImpl() *SettingImpl {
func (r *SettingImpl) Get(key string, defaultValue ...string) string {
var setting models.Setting
if err := facades.Orm().Query().Where("key", key).FirstOrFail(&setting); err != nil {
if len(defaultValue) == 0 {
return ""
}
return defaultValue[0]
return tools.FirstElement(defaultValue)
}
if len(setting.Value) == 0 {
if len(defaultValue) == 0 {
return ""
}
return defaultValue[0]
return tools.FirstElement(defaultValue)
}
return setting.Value

View File

@@ -460,8 +460,7 @@ func (r *WebsiteImpl) SaveConfig(config requests.SaveConfig) error {
return err
}
_, err = tools.Exec("systemctl reload openresty")
return err
return tools.ServiceReload("openresty")
}
// Delete 删除网站
@@ -495,8 +494,7 @@ func (r *WebsiteImpl) Delete(id uint) error {
return err
}
_, err := tools.Exec("systemctl reload openresty")
return err
return tools.ServiceReload("openresty")
}
// GetConfig 获取网站配置