mirror of
https://github.com/tnb-labs/panel.git
synced 2026-10-30 18:21:30 +08:00
依赖注入:
- 移除 google/wire(含 wire.go/wire_gen.go 与全部 ProviderSet),
改用 samber/do v2 单注入器 + 双入口惰性构建
- 贡献模型替代命令式注册:路由 routes:、命令 commands:、
任务 jobs: 前缀经 internal/registry 收集与校验
- 构造函数统一 func NewXxx(i do.Injector) (T, error)
三层架构:
- 补全用例层:每个 biz.XxxRepo 配 XxxUsecase,
service/command/job 表现层只依赖用例,不再直接引用仓储
路由与文档:
- route/http.go 按域拆为声明式 Endpoint 贡献,
Endpoint 承载登录白名单与端点限流语义
- 调试模式下提供 OpenAPI 3.1 文档:/openapi.json 与 /docs(Scalar),
从 validate 标签生成
目录与依赖:
- internal/http/{middleware,request,rule} 拍平至 internal/*
- CLI 命令拆至 internal/command
- 日志轮转 timberjack 换为 libtnb/logrotate
- 升级 validator/cron/sessions/gormstore/sqlite/securecookie
- 数据库迁移保持 gormigrate 不变
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
79 lines
4.2 KiB
Go
79 lines
4.2 KiB
Go
package route
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/samber/do/v2"
|
|
|
|
"github.com/acepanel/panel/v3/internal/biz"
|
|
"github.com/acepanel/panel/v3/internal/request"
|
|
"github.com/acepanel/panel/v3/internal/service"
|
|
)
|
|
|
|
// FirewallRoutes 防火墙路由
|
|
func FirewallRoutes(i do.Injector) (Endpoints, error) {
|
|
svc := do.MustInvoke[*service.FirewallService](i)
|
|
scan := do.MustInvoke[*service.FirewallScanService](i)
|
|
|
|
return Endpoints{
|
|
// /api/firewall
|
|
{Method: http.MethodGet, Path: "/api/firewall/status", Handler: svc.GetStatus,
|
|
Summary: "获取防火墙状态", Tags: []string{"防火墙"}},
|
|
{Method: http.MethodPost, Path: "/api/firewall/status", Handler: svc.UpdateStatus,
|
|
Summary: "设置防火墙状态", Tags: []string{"防火墙"},
|
|
Request: request.FirewallStatus{}},
|
|
{Method: http.MethodGet, Path: "/api/firewall/rule", Handler: svc.GetRules,
|
|
Summary: "获取端口规则", Tags: []string{"防火墙"}},
|
|
{Method: http.MethodGet, Path: "/api/firewall/rule/port_usage", Handler: svc.GetPortUsage,
|
|
Summary: "获取端口占用", Tags: []string{"防火墙"}},
|
|
{Method: http.MethodPost, Path: "/api/firewall/rule", Handler: svc.CreateRule,
|
|
Summary: "创建端口规则", Tags: []string{"防火墙"},
|
|
Request: request.FirewallRule{}},
|
|
{Method: http.MethodDelete, Path: "/api/firewall/rule", Handler: svc.DeleteRule,
|
|
Summary: "删除端口规则", Tags: []string{"防火墙"},
|
|
Request: request.FirewallRule{}},
|
|
{Method: http.MethodGet, Path: "/api/firewall/ip_rule", Handler: svc.GetIPRules,
|
|
Summary: "获取 IP 规则", Tags: []string{"防火墙"}},
|
|
{Method: http.MethodPost, Path: "/api/firewall/ip_rule", Handler: svc.CreateIPRule,
|
|
Summary: "创建 IP 规则", Tags: []string{"防火墙"},
|
|
Request: request.FirewallIPRule{}},
|
|
{Method: http.MethodDelete, Path: "/api/firewall/ip_rule", Handler: svc.DeleteIPRule,
|
|
Summary: "删除 IP 规则", Tags: []string{"防火墙"},
|
|
Request: request.FirewallIPRule{}},
|
|
{Method: http.MethodGet, Path: "/api/firewall/forward", Handler: svc.GetForwards,
|
|
Summary: "获取端口转发", Tags: []string{"防火墙"}},
|
|
{Method: http.MethodPost, Path: "/api/firewall/forward", Handler: svc.CreateForward,
|
|
Summary: "创建端口转发", Tags: []string{"防火墙"},
|
|
Request: request.FirewallForward{}},
|
|
{Method: http.MethodDelete, Path: "/api/firewall/forward", Handler: svc.DeleteForward,
|
|
Summary: "删除端口转发", Tags: []string{"防火墙"},
|
|
Request: request.FirewallForward{}},
|
|
// /api/firewall/scan
|
|
{Method: http.MethodGet, Path: "/api/firewall/scan/setting", Handler: scan.GetSetting,
|
|
Summary: "获取扫描感知设置", Tags: []string{"防火墙"},
|
|
Response: service.Envelope[biz.ScanSetting]{}},
|
|
{Method: http.MethodPost, Path: "/api/firewall/scan/setting", Handler: scan.UpdateSetting,
|
|
Summary: "更新扫描感知设置", Tags: []string{"防火墙"},
|
|
Request: request.FirewallScanSetting{}},
|
|
{Method: http.MethodGet, Path: "/api/firewall/scan/interfaces", Handler: scan.GetInterfaces,
|
|
Summary: "获取可用网卡", Tags: []string{"防火墙"}},
|
|
{Method: http.MethodGet, Path: "/api/firewall/scan/summary", Handler: scan.GetSummary,
|
|
Summary: "获取扫描汇总", Tags: []string{"防火墙"},
|
|
Response: service.Envelope[biz.ScanSummary]{}},
|
|
{Method: http.MethodGet, Path: "/api/firewall/scan/trend", Handler: scan.GetTrend,
|
|
Summary: "获取扫描趋势", Tags: []string{"防火墙"},
|
|
Response: service.Envelope[[]*biz.ScanDayTrend]{}},
|
|
{Method: http.MethodGet, Path: "/api/firewall/scan/top_ips", Handler: scan.GetTopSourceIPs,
|
|
Summary: "获取 Top 扫描源 IP", Tags: []string{"防火墙"},
|
|
Response: service.Envelope[[]*biz.ScanSourceRank]{}},
|
|
{Method: http.MethodGet, Path: "/api/firewall/scan/top_ports", Handler: scan.GetTopPorts,
|
|
Summary: "获取 Top 被扫描端口", Tags: []string{"防火墙"},
|
|
Response: service.Envelope[[]*biz.ScanPortRank]{}},
|
|
{Method: http.MethodGet, Path: "/api/firewall/scan/events", Handler: scan.ListEvents,
|
|
Summary: "获取扫描事件列表", Tags: []string{"防火墙"},
|
|
Response: service.Envelope[service.Page[*biz.ScanEvent]]{}},
|
|
{Method: http.MethodPost, Path: "/api/firewall/scan/clear", Handler: scan.Clear,
|
|
Summary: "清空扫描数据", Tags: []string{"防火墙"}},
|
|
}, nil
|
|
}
|