🎨解决template渲染时遇到转移字符问题

This commit is contained in:
coward
2024-03-08 10:43:22 +08:00
parent 4597a1d442
commit d41a6e9ba2
8 changed files with 769 additions and 8 deletions

View File

@@ -3,11 +3,13 @@ package script
import (
"encoding/json"
"gitee.ltd/lxh/logger/log"
"github.com/spf13/cast"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"wireguard-dashboard/client"
"wireguard-dashboard/component"
"wireguard-dashboard/constant"
"wireguard-dashboard/model/entity"
"wireguard-dashboard/model/template_data"
"wireguard-dashboard/repository"
"wireguard-dashboard/utils"
)
@@ -130,9 +132,7 @@ func (s Script) InitServer() error {
// 根据密钥生成公钥
publicKey := privateKey.PublicKey()
// 没有服务端,开始初始化
if err := repository.Server().Save(&entity.Server{
serverEnt := &entity.Server{
IpScope: "10.10.10.1/24",
ListenPort: 51820,
PrivateKey: privateKey.String(),
@@ -140,13 +140,32 @@ func (s Script) InitServer() error {
PostUpScript: "",
PreDownScript: "",
PostDownScript: "",
}); err != nil {
}
// 没有服务端,开始初始化
if err := repository.Server().Save(serverEnt); err != nil {
return err
}
// 处理一下要渲染到配置文件上的数据
serverConfig := template_data.Server{
Address: serverEnt.IpScope,
ListenPort: serverEnt.ListenPort,
PrivateKey: serverEnt.PrivateKey,
MTU: cast.ToInt(data["MTU"]),
PostUp: serverEnt.PostUpScript,
PreDown: serverEnt.PreDownScript,
PostDown: serverEnt.PostDownScript,
Table: cast.ToString(data["table"]),
}
execData := map[string]any{
"Server": serverConfig,
}
// 数据库保存完毕,应用配置到配置文件当中
err = component.Wireguard().Apply("E:\\Workspace\\Go\\wireguard-dashboard\\template\\wg.conf",
"E:\\Workspace\\Go\\wireguard-dashboard\\wg0.conf", nil)
"E:\\Workspace\\Go\\wireguard-dashboard\\wg0.conf", execData)
if err != nil {
log.Errorf("应用配置文件失败: %v", err.Error())
return err