diff --git a/http/vo/setting.go b/http/vo/setting.go index a45c4d9..c881e5b 100644 --- a/http/vo/setting.go +++ b/http/vo/setting.go @@ -14,8 +14,11 @@ type Export struct { Global *Global `json:"global" label:"全局配置" binding:"required"` Server *Server `json:"server" label:"服务端配置" binding:"required"` Clients []Client `json:"clients" label:"客户端" binding:"omitempty"` + Other []Other `json:"other" label:"其他" binding:"omitempty"` } +// Global +// @description: 全局配置 type Global struct { MTU int `json:"MTU" label:"MTU" binding:"required"` ConfigFilePath string `json:"configFilePath" label:"配置文件路径" binding:"required"` @@ -26,6 +29,8 @@ type Global struct { Table string `json:"table" label:"table" binding:"omitempty"` } +// Server +// @description: 服务端信息 type Server struct { IpScope []string `json:"ipScope" label:"ipScope" binding:"min=1,dive,required"` ListenPort int `json:"listenPort" label:"listenPort" binding:"required"` @@ -35,6 +40,8 @@ type Server struct { PostDownScript string `json:"postDownScript" label:"postDownScript" binding:"omitempty"` } +// Client +// @description: 客户端信息 type Client struct { Name string `json:"name" label:"name" binding:"required"` Email string `json:"email" label:"email" binding:"omitempty"` @@ -52,3 +59,11 @@ type Client struct { Enabled *constant.Status `json:"enabled" label:"enabled" binding:"required"` OfflineMonitoring *constant.Status `json:"offlineMonitoring" label:"offlineMonitoring" binding:"required"` } + +// Other +// @description: 其他配置 +type Other struct { + Code string `json:"code" label:"code" binding:"required"` + Data string `json:"data" label:"data" binding:"required"` + Describe string `json:"describe" label:"describe" binding:"omitempty"` +} diff --git a/service/setting.go b/service/setting.go index e5e62e0..68c978b 100644 --- a/service/setting.go +++ b/service/setting.go @@ -152,6 +152,13 @@ func (s setting) Export() (data vo.Export, err error) { } } + // 查询其他配置 + var others []vo.Other + if err = s.Model(&model.Setting{}).Where("code not in ?", []string{"WG_SETTING", "WG_SERVER"}).Find(&others).Error; err != nil { + return + } + + data.Other = others cj, _ := json.Marshal(clients) _ = json.Unmarshal(cj, &data.Clients) @@ -219,5 +226,17 @@ func (s setting) Import(data *vo.Export, loginUser *vo.User) (err error) { } } + // 其他配置写入 + for _, v := range data.Other { + if err = s.SetData(&model.Setting{ + Code: v.Code, + Data: v.Data, + Describe: v.Describe, + }); err != nil { + slog.Errorf("其他配置[%s]导入失败: %v", v.Code, err) + continue + } + } + return nil }