diff --git a/http/api/client.go b/http/api/client.go index de3efce..05493a8 100644 --- a/http/api/client.go +++ b/http/api/client.go @@ -44,6 +44,7 @@ func (ClientApi) Save(c *gin.Context) { return } + component.Wireguard().ServerControl("E:\\Workspace\\Go\\wireguard-ui\\template\\tmp\\wg0.conf") response.R(c).OK() } @@ -63,6 +64,7 @@ func (ClientApi) Delete(c *gin.Context) { return } + component.Wireguard().ServerControl("E:\\Workspace\\Go\\wireguard-ui\\template\\tmp\\wg0.conf") response.R(c).OK() } diff --git a/http/api/dashboard.go b/http/api/dashboard.go index faaa903..f02a4d7 100644 --- a/http/api/dashboard.go +++ b/http/api/dashboard.go @@ -60,32 +60,13 @@ func (DashboardApi) DailyPoetry(c *gin.Context) { // @receiver DashboardApi // @param c func (DashboardApi) ConnectionList(c *gin.Context) { - var connections []vo.DataTraffic peers, err := component.Wireguard().GetClients() if err != nil { - if len(connections) == 0 { - for i := 0; i < 10; i++ { - var online bool - if i%2 == 0 { - online = true - } - connections = append(connections, vo.DataTraffic{ - Name: fmt.Sprintf("客户端: %d", i+1), - Email: fmt.Sprintf("%d@qq.com", i+1), - IpAllocation: fmt.Sprintf("10.100.25.%d/32", i+1), - Online: online, - ReceiveBytes: utils.FlowCalculation().Parse(12212), - TransmitBytes: utils.FlowCalculation().Parse(322212), - ConnectEndpoint: "1.14.30.133", - LastHandAt: time.Now().Format("2006-01-02 15:04:05"), - }) - } - response.R(c).OkWithData(connections) - return - } + response.R(c).FailedWithError("获取失败") return } + var connections []vo.DataTraffic for _, peer := range peers { // 获取客户端链接信息 clientInfo, err := service.Client().GetByPublicKey(peer.PublicKey.String()) diff --git a/utils/paginate.go b/utils/paginate.go index eff66e1..25a6a70 100644 --- a/utils/paginate.go +++ b/utils/paginate.go @@ -6,6 +6,12 @@ func Paginate() paginate { return paginate{} } +// Generate +// @description: 生成页码 +// @receiver paginate +// @param count +// @param size +// @return int func (paginate) Generate(count int64, size int) int { totalPage := 0 if count > 0 { diff --git a/utils/rand.go b/utils/rand.go index da4f49b..d6c7b15 100644 --- a/utils/rand.go +++ b/utils/rand.go @@ -12,6 +12,11 @@ func Random() random { return random{} } +// RandStr +// @description: 随机字符串 +// @receiver random +// @param len +// @return string func (random) RandStr(len int) string { var container string var str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" diff --git a/utils/website.go b/utils/website.go index 7dc533b..55e7f30 100644 --- a/utils/website.go +++ b/utils/website.go @@ -7,6 +7,12 @@ type website struct{} func WebSite() website { return website{} } + +// GetHost +// @description: 获取主机host +// @receiver website +// @param addr +// @return string func (website) GetHost(addr string) string { uu, err := url.Parse(addr) if err != nil {