mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-26 20:19:15 +08:00
44 lines
914 B
Go
44 lines
914 B
Go
package service
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"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
|
|
}
|
|
return &info, err
|
|
}
|
|
|
|
func (u *SettingService) Update(key, value string) error {
|
|
return settingRepo.Update(key, value)
|
|
}
|