使用 base32 解码传入的密钥;优化调试接口返回内容;新增 RUN_MODE,根据环境变量确定是否要公开调试接口
This commit is contained in:
@@ -15,7 +15,10 @@ type InfoResp struct {
|
||||
CtrlConnections int `json:"ctrl_connections"`
|
||||
DataConnections int `json:"data_connections"`
|
||||
|
||||
Edges []EdgeResp `json:"edges"`
|
||||
// Edges []EdgeResp `json:"edges"`
|
||||
Assigns map[uint16]int32 `json:"assigns"`
|
||||
Edges map[int32]uint16 `json:"edges"`
|
||||
Permits map[int32]*core.Permit `json:"permits"`
|
||||
}
|
||||
|
||||
type EdgeResp struct {
|
||||
@@ -26,18 +29,36 @@ type EdgeResp struct {
|
||||
|
||||
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
|
||||
}
|
||||
// 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
|
||||
// })
|
||||
|
||||
edges = append(edges, EdgeResp{
|
||||
Id: id,
|
||||
Port: port,
|
||||
Permit: permit,
|
||||
})
|
||||
var assigns = make(map[uint16]int32)
|
||||
app.Assigns.Range(func(port uint16, id int32) bool {
|
||||
assigns[port] = id
|
||||
return true
|
||||
})
|
||||
|
||||
var edges = make(map[int32]uint16)
|
||||
app.Edges.Range(func(id int32, port uint16) bool {
|
||||
edges[id] = port
|
||||
return true
|
||||
})
|
||||
|
||||
var permits = make(map[int32]*core.Permit)
|
||||
app.Permits.Range(func(id int32, permit *core.Permit) bool {
|
||||
permits[id] = permit
|
||||
return true
|
||||
})
|
||||
|
||||
@@ -48,6 +69,8 @@ func Info(c *fiber.Ctx) error {
|
||||
UserConnections: int(app.UserConnWg.Count()),
|
||||
CtrlConnections: int(app.CtrlConnWg.Count()),
|
||||
DataConnections: int(app.DataConnWg.Count()),
|
||||
Assigns: assigns,
|
||||
Edges: edges,
|
||||
Permits: permits,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,15 +2,18 @@ package web
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"proxy-server/gateway/env"
|
||||
"proxy-server/gateway/web/handlers"
|
||||
)
|
||||
|
||||
func Router(r *fiber.App) {
|
||||
var debug = r.Group("/debug")
|
||||
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)
|
||||
|
||||
if env.RunMode == "dev" {
|
||||
var debug = r.Group("/debug")
|
||||
debug.Get("/info", handlers.Info)
|
||||
debug.Get("/consuming/list", handlers.GetConsuming)
|
||||
debug.Get("/consuming/reset", handlers.RestConsuming)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2/middleware/logger"
|
||||
"github.com/gofiber/fiber/v2/middleware/recover"
|
||||
"log/slog"
|
||||
"proxy-server/gateway/env"
|
||||
"strconv"
|
||||
@@ -23,6 +25,8 @@ func (s *Server) Run() error {
|
||||
})
|
||||
|
||||
// 配置中间件和路由
|
||||
s.web.Use(recover.New())
|
||||
s.web.Use(logger.New())
|
||||
Router(s.web)
|
||||
|
||||
// 启动服务
|
||||
|
||||
Reference in New Issue
Block a user