1Panel/backend/app/service/setting.go

46 lines
981 B
Go
Raw Normal View History

2022-09-15 10:44:43 +08:00
package service
import (
"encoding/json"
"time"
2022-09-15 10:44:43 +08:00
"github.com/1Panel-dev/1Panel/app/dto"
"github.com/1Panel-dev/1Panel/constant"
)
type SettingService struct{}
type ISettingService interface {
GetSettingInfo() (*dto.SettingInfo, error)
Update(key, value string) error
}
func NewISettingService() ISettingService {
return &SettingService{}
}
func (u *SettingService) GetSettingInfo() (*dto.SettingInfo, error) {
setting, err := settingRepo.Get()
if err != nil {
return nil, constant.ErrRecordNotFound
}
settingMap := make(map[string]string)
for _, set := range setting {
settingMap[set.Key] = set.Value
}
var info dto.SettingInfo
arr, err := json.Marshal(settingMap)
if err != nil {
return nil, err
}
if err := json.Unmarshal(arr, &info); err != nil {
return nil, err
}
info.LocalTime = time.Now().Format("2006.01.02 15:04:05")
2022-09-15 10:44:43 +08:00
return &info, err
}
func (u *SettingService) Update(key, value string) error {
return settingRepo.Update(key, value)
}