a6b35268ab
sing-box 该构建未编入 v2ray_api、clash /connections 也不暴露用户,故无法做 准确 per-user 计费。改取节点累计总量(clash downloadTotal/uploadTotal)做 窗口增量,按当前 dp_uuid 均摊上报(单用户=准确,多用户近似,已注释标注)。 - render.go:节点 sing-box 配置加 experimental.clash_api(loopback+secret)。 - ClashUsageSource:轮询 /connections 总量,delta + 重启回绕保护;clash 的 up/down 是代理视角,对调为用户视角(下载→bytes_down)。 - SingBox.DpUUIDs() 供归属;Agent.UseClashUsage() 在 cmd/agent 接上。 已节点 live 验证:usage_daily 实时入库,下载增量正确落 bytes_down。 局限:多 dp_uuid 时均摊(准确计费需重编 sing-box 带 with_v2ray_api)。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Pangolin Server
Go 后端控制面,负责账户、套餐、激活码、设备与节点目录管理。架构详见 ../design/server/ARCHITECTURE.md。
目录结构
server/
├── cmd/
│ ├── server/ # HTTP 服务入口(chi router,/healthz,/v1 挂载归 1d)
│ └── migrate/ # 数据库迁移 CLI 入口(实现归 1e)
├── internal/
│ ├── config/ # 配置加载(env + 文件,归 1e)
│ ├── store/ # 数据库访问层 Postgres(归 1e)
│ ├── apierr/ # 统一错误体 {code, message_zh, message_en}(归 1f)
│ ├── idgen/ # UUID + Crockford Base32 激活码(归 1f)
│ ├── auth/ # 验证码、argon2id、JWT RS256(归 1c/1d)
│ ├── codes/ # 激活码批次、兑换、审计(归 1d)
│ ├── devices/ # 设备管理(归 1d)
│ ├── nodes/ # 节点目录、connect/disconnect(归 1d)
│ ├── usage/ # 用量统计(归 1d)
│ └── admin/ # 内部管理端(归 1d)
├── Makefile
├── go.mod
├── go.sum
├── tools.go # //go:build tools — 锁定 oapi-codegen / migrate 版本
└── .golangci.yml
常用命令
make build # go build ./...
make test # go test ./...
make vet # go vet ./...
make lint # golangci-lint run ./...
make generate # oapi-codegen 代码生成(1d 填充)
make migrate-up # 执行迁移(1e 填充)
make migrate-down # 回滚迁移(1e 填充)
# 快速启动(默认监听 :8080)
go run ./cmd/server
# 指定地址
go run ./cmd/server -addr :9090
# 或通过环境变量
ADDR=:9090 go run ./cmd/server