:new:新增接口控制服务端、命令控制服务端

This commit is contained in:
coward
2024-03-22 10:42:36 +08:00
parent a988b66ccd
commit 86c76add17
10 changed files with 142 additions and 44 deletions

View File

@@ -5,6 +5,7 @@ import (
"github.com/gin-gonic/gin"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"strings"
"wireguard-dashboard/command"
"wireguard-dashboard/http/param"
"wireguard-dashboard/model/entity"
"wireguard-dashboard/queues"
@@ -89,3 +90,26 @@ func (server) GetServer(c *gin.Context) {
utils.GinResponse(c).OKWithData(data)
}
// ControlServer
// @description: 服务端控制器
// @receiver server
// @param c
func (server) ControlServer(c *gin.Context) {
var p param.ControlServer
if err := c.ShouldBind(&p); err != nil {
utils.GinResponse(c).FailedWithErr("参数错误", err)
return
}
switch p.Status {
case "START":
command.StartWireguard()
case "STOP":
command.StopWireguard()
case "RESTART":
command.RestartWireguard(false)
}
utils.GinResponse(c).OK()
}