Files
pangolin/server
wangjia 0b33f12400 feat: 近实时远程下线 — 客户端轮询会话有效性(~15s),服务端 GET /v1/me/session
控制面无推送通道,access token 是无状态 JWT(15min),强制退出后被踢设备要等 token 过期
(≤15min)才登出。改成客户端每 15s 轮询会话是否仍有效,被强制退出即登出 → 延迟压到 ~15s。
- 服务端:sessions.HasActiveSession(user,device) + devices.SessionActive(按 UUID,fail-open)
  + GET /v1/me/session?device_id= 返回 {active}(恒 200,判据在 body)。无新迁移。
- 客户端:account_api.sessionActive + main.dart _RootFlowState 15s 轮询,active=false 即 logout
  (网络/鉴权异常不据此登出,fail-safe)。
- 测试:TestSQLite_SessionHasActiveSession(建会话=活跃→RevokeByDevice→非活跃)。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-30 07:25:16 +08:00
..

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