From 40019568f064ebea95a8f6837b112d741b951e22 Mon Sep 17 00:00:00 2001 From: coward Date: Mon, 4 Nov 2024 16:50:50 +0800 Subject: [PATCH] =?UTF-8?q?:art:=E5=A4=87=E4=BB=BD=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E3=80=81=E5=AF=BC=E5=85=A5=E6=96=B0=E5=A2=9E=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- http/vo/setting.go | 15 +++++++++++++++ service/setting.go | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) 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 }