feat : add site custom setting
This commit is contained in:
@@ -10,12 +10,9 @@ import (
|
||||
"message-nest/service/send_message_service"
|
||||
)
|
||||
|
||||
type CronService struct {
|
||||
}
|
||||
|
||||
var ClearLogsTaskId cron.EntryID
|
||||
|
||||
// 清除日志的定时任务
|
||||
// ClearLogs 清除日志的定时任务
|
||||
func ClearLogs() {
|
||||
var errStr string
|
||||
sm := send_message_service.SendMessageService{TaskID: constant.CleanLogsTaskId}
|
||||
@@ -42,8 +39,11 @@ func ClearLogs() {
|
||||
sm.RecordSendLog()
|
||||
}
|
||||
|
||||
// 启动注册清除任务定时任务
|
||||
func (cs *CronService) InitLogsCronRun() {
|
||||
type CronService struct {
|
||||
}
|
||||
|
||||
// StartLogsCronRun 启动注册清除任务定时任务
|
||||
func (cs *CronService) StartLogsCronRun() {
|
||||
// 注册任务
|
||||
setting, err := models.GetSettingByKey(constant.LogsCleanSectionName, constant.LogsCleanCronKeyName)
|
||||
if err != nil {
|
||||
@@ -61,7 +61,7 @@ func (cs *CronService) InitLogsCronRun() {
|
||||
}
|
||||
}
|
||||
|
||||
// 更新清除任务定时任务
|
||||
// UpdateLogsCronRun 更新清除任务定时任务
|
||||
func (cs *CronService) UpdateLogsCronRun(cron string) {
|
||||
RemoveTask(ClearLogsTaskId)
|
||||
ClearLogsTaskId = AddTask(ScheduledTask{
|
||||
@@ -73,7 +73,8 @@ func (cs *CronService) UpdateLogsCronRun(cron string) {
|
||||
|
||||
}
|
||||
|
||||
func Setup() {
|
||||
// StartLogsCronRun 启动的时候开启定时任务
|
||||
func StartLogsCronRun() {
|
||||
cs := CronService{}
|
||||
cs.InitLogsCronRun()
|
||||
cs.StartLogsCronRun()
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package env_service
|
||||
package settings_service
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -6,10 +6,11 @@ import (
|
||||
"message-nest/pkg/constant"
|
||||
)
|
||||
|
||||
type EnvService struct {
|
||||
// 初始化环境的设置数据
|
||||
type InitSettingService struct {
|
||||
}
|
||||
|
||||
func (es *EnvService) CommonAdd(section string, key string, value string) {
|
||||
func (es *InitSettingService) CommonAddSetting(section string, key string, value string) {
|
||||
setting, _ := models.GetSettingByKey(section, key)
|
||||
if setting.ID <= 0 {
|
||||
err := models.AddOneSetting(models.Settings{
|
||||
@@ -26,23 +27,17 @@ func (es *EnvService) CommonAdd(section string, key string, value string) {
|
||||
}
|
||||
|
||||
// InitSiteConfig 初始化、重置站点信息设置
|
||||
func (es *EnvService) InitSiteConfig() {
|
||||
func (es *InitSettingService) InitSiteConfig() {
|
||||
section := constant.SiteSettingSectionName
|
||||
for key, value := range constant.SiteSiteDefaultValueMap {
|
||||
es.CommonAdd(section, key, value)
|
||||
es.CommonAddSetting(section, key, value)
|
||||
}
|
||||
}
|
||||
|
||||
// InitLogConfig 初始化日志清理设置
|
||||
func (es *EnvService) InitLogConfig() {
|
||||
func (es *InitSettingService) InitLogConfig() {
|
||||
section := constant.LogsCleanSectionName
|
||||
for key, value := range constant.LogsCleanDefaultValueMap {
|
||||
es.CommonAdd(section, key, value)
|
||||
es.CommonAddSetting(section, key, value)
|
||||
}
|
||||
}
|
||||
|
||||
func Setup() {
|
||||
es := EnvService{}
|
||||
es.InitSiteConfig()
|
||||
es.InitLogConfig()
|
||||
}
|
||||
Reference in New Issue
Block a user