Files
pangolin/server
wangjia 6e2657049e feat(proto): add agent.proto contract + buf toolchain (tsk_V9IrIk2g5Q78)
Introduces the frozen control-plane ↔ agent gRPC contract and the full
buf v2 code-generation pipeline that task #6/#14/#15 depend on.

Changes:
- server/proto/pangolin/agent/v1/agent.proto: AgentService with 6 RPCs
  (Enroll, Register, Heartbeat, Subscribe, Ack, ReportUsage) and all
  supporting message types (Command + 5 payload variants, ConfigSnapshot,
  CredentialEntry, NodeLoad, UsageItem).  Red-line comments prohibit
  user_id/email and destination-address fields per privacy policy.
- server/buf.yaml: v2 format, STANDARD lint + FILE breaking rules.
- server/buf.gen.yaml: remote protoc-gen-go v1.36.4 + protoc-gen-go-grpc
  v1.5.1 plugins, out=internal/pb, paths=source_relative.
- server/internal/pb/pangolin/agent/v1/: generated agent.pb.go +
  agent_grpc.pb.go committed to repo (CI diff-clean verified).
- server/Makefile: proto / proto-lint / proto-breaking targets added.
- server/tools.go: buf v1.70.0, protoc-gen-go, protoc-gen-go-grpc pinned.
- server/go.mod / go.sum: buf and grpc tool deps added via go mod tidy.

Acceptance verified:
  buf lint  → zero warnings
  buf generate × 2 → git diff clean (idempotent)
  go build ./... → passes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-13 12:13:43 +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