重构连接监听与处理代码逻辑,连接信息存储于全局通过接口展示
This commit is contained in:
@@ -6,12 +6,12 @@ import (
|
||||
"proxy-server/gateway/core"
|
||||
)
|
||||
|
||||
type AuthReq struct {
|
||||
type PermitReq struct {
|
||||
Id int32 `json:"id"`
|
||||
core.Permit
|
||||
}
|
||||
|
||||
func Auth(ctx *fiber.Ctx) (err error) {
|
||||
func Permit(ctx *fiber.Ctx) (err error) {
|
||||
|
||||
// 安全验证
|
||||
var sec core.SecuredReq
|
||||
@@ -20,7 +20,7 @@ func Auth(ctx *fiber.Ctx) (err error) {
|
||||
}
|
||||
|
||||
// 获取请求参数
|
||||
req, err := core.Decrypt[AuthReq](&sec, app.PlatformSecret)
|
||||
req, err := core.Decrypt[PermitReq](&sec, app.PlatformSecret)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
53
gateway/web/handlers/info.go
Normal file
53
gateway/web/handlers/info.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"proxy-server/gateway/app"
|
||||
"proxy-server/gateway/core"
|
||||
)
|
||||
|
||||
type InfoResp struct {
|
||||
Id int32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
|
||||
FwdListeners int `json:"fwd_listeners"`
|
||||
UserConnections int `json:"user_connections"`
|
||||
CtrlConnections int `json:"ctrl_connections"`
|
||||
DataConnections int `json:"data_connections"`
|
||||
|
||||
Edges []EdgeResp `json:"edges"`
|
||||
}
|
||||
|
||||
type EdgeResp struct {
|
||||
Id int32 `json:"id"`
|
||||
Port uint16 `json:"port"`
|
||||
Permit *core.Permit `json:"permit"`
|
||||
}
|
||||
|
||||
func Info(c *fiber.Ctx) error {
|
||||
|
||||
var edges = make([]EdgeResp, 0)
|
||||
app.Edges.Range(func(id int32, port uint16) bool {
|
||||
permit, ok := app.Permits.Load(id)
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
|
||||
edges = append(edges, EdgeResp{
|
||||
Id: id,
|
||||
Port: port,
|
||||
Permit: permit,
|
||||
})
|
||||
return true
|
||||
})
|
||||
|
||||
return c.JSON(InfoResp{
|
||||
Id: app.Id,
|
||||
Name: app.Name,
|
||||
FwdListeners: int(app.FwdLesWg.Count()),
|
||||
UserConnections: int(app.UserConnWg.Count()),
|
||||
CtrlConnections: int(app.CtrlConnWg.Count()),
|
||||
DataConnections: int(app.DataConnWg.Count()),
|
||||
Edges: edges,
|
||||
})
|
||||
}
|
||||
@@ -7,6 +7,10 @@ import (
|
||||
|
||||
func Router(r *fiber.App) {
|
||||
var debug = r.Group("/debug")
|
||||
debug.Get("/debug/consuming/list", handlers.GetConsuming)
|
||||
debug.Get("/debug/consuming/reset", handlers.RestConsuming)
|
||||
debug.Get("/info", handlers.Info)
|
||||
debug.Get("/consuming/list", handlers.GetConsuming)
|
||||
debug.Get("/consuming/reset", handlers.RestConsuming)
|
||||
|
||||
var api = r.Group("/api")
|
||||
api.Post("/permit", handlers.Permit)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user