🎨同步配置文件改为队列
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
"wireguard-dashboard/http/param"
|
||||
"wireguard-dashboard/model/entity"
|
||||
"wireguard-dashboard/queues"
|
||||
"wireguard-dashboard/repository"
|
||||
"wireguard-dashboard/utils"
|
||||
)
|
||||
@@ -28,7 +29,9 @@ func (server) SaveServer(c *gin.Context) {
|
||||
}
|
||||
|
||||
var err error
|
||||
var serverId string
|
||||
if p.Id != "" {
|
||||
serverId = p.Id
|
||||
if err = repository.Server().Update(p); err != nil {
|
||||
log.Errorf("更改服务端信息失败: %v", err.Error())
|
||||
}
|
||||
@@ -39,7 +42,7 @@ func (server) SaveServer(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
publicKey := privateKey.PublicKey()
|
||||
if err = repository.Server().Save(&entity.Server{
|
||||
serverInfo := &entity.Server{
|
||||
IpScope: p.IpScope,
|
||||
ListenPort: p.ListenPort,
|
||||
PrivateKey: privateKey.String(),
|
||||
@@ -47,9 +50,12 @@ func (server) SaveServer(c *gin.Context) {
|
||||
PostUpScript: p.PostUpScript,
|
||||
PreDownScript: p.PreDownScript,
|
||||
PostDownScript: p.PostDownScript,
|
||||
}); err != nil {
|
||||
}
|
||||
if err = repository.Server().Save(serverInfo); err != nil {
|
||||
log.Errorf("新增服务端失败: %v", err.Error())
|
||||
}
|
||||
|
||||
serverId = serverInfo.Id
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@@ -57,6 +63,13 @@ func (server) SaveServer(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
go func() {
|
||||
if err = queues.PutAsyncWireguardConfigFile(serverId); err != nil {
|
||||
log.Errorf("投递同步配置文件任务失败: %s", err.Error())
|
||||
}
|
||||
}()
|
||||
|
||||
utils.GinResponse(c).OK()
|
||||
}
|
||||
|
||||
// GetServer
|
||||
|
Reference in New Issue
Block a user