Files
panel/internal/route/website_stat.go
T
耗子andClaude Opus 4.8 443516a2cf refactor!: 迁移至 samber/do 依赖注入与三层架构
依赖注入:
- 移除 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>
2026-07-09 21:54:22 +08:00

45 lines
2.6 KiB
Go

package route
import (
"net/http"
"github.com/samber/do/v2"
"github.com/acepanel/panel/v3/internal/request"
"github.com/acepanel/panel/v3/internal/service"
)
// WebsiteStatRoutes 网站统计相关路由
func WebsiteStatRoutes(i do.Injector) (Endpoints, error) {
svc := do.MustInvoke[*service.WebsiteStatService](i)
return Endpoints{
{Method: http.MethodGet, Path: "/api/website/stat/overview", Handler: svc.Overview,
Summary: "统计概览", Tags: []string{"网站统计"}, Request: request.WebsiteStatDateRange{}},
{Method: http.MethodGet, Path: "/api/website/stat/realtime", Handler: svc.Realtime,
Summary: "实时统计", Tags: []string{"网站统计"}},
{Method: http.MethodGet, Path: "/api/website/stat/sites", Handler: svc.SiteStats,
Summary: "网站维度汇总", Tags: []string{"网站统计"}, Request: request.WebsiteStatDateRange{}},
{Method: http.MethodGet, Path: "/api/website/stat/spiders", Handler: svc.SpiderStats,
Summary: "蜘蛛统计", Tags: []string{"网站统计"}, Request: request.WebsiteStatDateRange{}},
{Method: http.MethodGet, Path: "/api/website/stat/clients", Handler: svc.ClientStats,
Summary: "客户端统计", Tags: []string{"网站统计"}, Request: request.WebsiteStatDateRange{}},
{Method: http.MethodGet, Path: "/api/website/stat/ips", Handler: svc.IPStats,
Summary: "IP 统计", Tags: []string{"网站统计"}, Request: request.WebsiteStatPaginate{}},
{Method: http.MethodGet, Path: "/api/website/stat/geos", Handler: svc.GeoStats,
Summary: "地理位置统计", Tags: []string{"网站统计"}, Request: request.WebsiteStatGeo{}},
{Method: http.MethodGet, Path: "/api/website/stat/uris", Handler: svc.URIStats,
Summary: "URI 统计", Tags: []string{"网站统计"}, Request: request.WebsiteStatPaginate{}},
{Method: http.MethodGet, Path: "/api/website/stat/slow_uris", Handler: svc.SlowURIStats,
Summary: "慢请求 URI 统计", Tags: []string{"网站统计"}, Request: request.WebsiteStatSlowURIs{}},
{Method: http.MethodGet, Path: "/api/website/stat/errors", Handler: svc.ErrorStats,
Summary: "错误统计", Tags: []string{"网站统计"}, Request: request.WebsiteStatErrors{}},
{Method: http.MethodGet, Path: "/api/website/stat/setting", Handler: svc.GetSetting,
Summary: "获取统计设置", Tags: []string{"网站统计"}},
{Method: http.MethodPost, Path: "/api/website/stat/setting", Handler: svc.UpdateSetting,
Summary: "保存统计设置", Tags: []string{"网站统计"}, Request: request.WebsiteStatSetting{}},
{Method: http.MethodPost, Path: "/api/website/stat/clear", Handler: svc.Clear,
Summary: "清空统计", Tags: []string{"网站统计"}},
}, nil
}