refactor: 项目更名 WeKnora → Academy
Build & Publish (dsh-academy) / End-to-end inside dsh (latest, advisory) (push) Skipped
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Frontend / Docker multi-stage image (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-academy) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-academy) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-academy) / Publish to npm (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Helm / chart (push) Canceled after 0s
Build & Publish (dsh-academy) / End-to-end inside dsh (latest, advisory) (push) Skipped
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Frontend / Docker multi-stage image (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-academy) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-academy) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-academy) / Publish to npm (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Helm / chart (push) Canceled after 0s
- 全量替换代码/配置/文档中的项目名(保留上游 GitHub 链接、weixin 文档域名、Docker Hub 镜像名) - 重命名 32 个含项目名的文件/目录;Go module 路径改为 academy(含 client/cli 子模块) - docreader proto 描述符采用等长替换,保持序列化字节布局有效 - Dockerfile.app 构建网络修复: browserskill 离线产物通道、PyPI/apt 国内镜像 - 运行验证: go build ✓ docker compose up ✓ 健康检查 ✓
This commit is contained in:
1 parent
9097ee699d
commit
9058149576
3136 files changed
+18018
-18004
No files matched your search
@@ -39,7 +39,7 @@ graph TD
|
||||
|
||||
## 依赖注入:internal/container(uber/dig) {#_2-依赖注入-internal-container-uber-dig}
|
||||
|
||||
WeKnora 使用 **`go.uber.org/dig` v1.19.0**(构造函数注入容器,非代码生成的 wire)。入口是 `internal/container/container.go` 的 `BuildContainer`:
|
||||
Academy 使用 **`go.uber.org/dig` v1.19.0**(构造函数注入容器,非代码生成的 wire)。入口是 `internal/container/container.go` 的 `BuildContainer`:
|
||||
|
||||
```go
|
||||
// cmd/server/main.go
|
||||
@@ -93,7 +93,7 @@ if redisAvailable {
|
||||
}
|
||||
```
|
||||
|
||||
6 个 Asynq worker 池的并发度可经 system settings / 环境变量调整(默认 Core=8、PostProcess=2、Enrichment=12、Maintenance=4、Shared=6、Wiki=8,`WEKNORA_ASYNQ_*_CONCURRENCY`);队列拓扑定义在 `internal/types/task.go`(default、chat_attachment、postprocess、summary、multimodal、graph、question、memory、sync、low/maintenance、wiki 等,包含自动标签与记忆抽取)。
|
||||
6 个 Asynq worker 池的并发度可经 system settings / 环境变量调整(默认 Core=8、PostProcess=2、Enrichment=12、Maintenance=4、Shared=6、Wiki=8,`ACADEMY_ASYNQ_*_CONCURRENCY`);队列拓扑定义在 `internal/types/task.go`(default、chat_attachment、postprocess、summary、multimodal、graph、question、memory、sync、low/maintenance、wiki 等,包含自动标签与记忆抽取)。
|
||||
|
||||
### 资源清理与工厂 {#_2-3-资源清理与工厂}
|
||||
|
||||
@@ -113,7 +113,7 @@ flowchart TD
|
||||
D --> E["container.BuildContainer(runtime.GetContainer())<br/>DI 装配: DB 迁移 / Redis / Asynq / Router..."]
|
||||
E --> F["runStartupBootstrap(c) — best-effort, 失败仅告警"]
|
||||
F --> F1["TenantAPIKeyService.BackfillMissingKeyHashes<br/>(迁移 000065 遗留 API Key 哈希回填)"]
|
||||
F --> F2["bootstrapSystemAdmin<br/>WEKNORA_BOOTSTRAP_SYSTEM_ADMIN_EMAIL 指定的用户<br/>在无系统管理员时晋升为超管 (幂等)"]
|
||||
F --> F2["bootstrapSystemAdmin<br/>ACADEMY_BOOTSTRAP_SYSTEM_ADMIN_EMAIL 指定的用户<br/>在无系统管理员时晋升为超管 (幂等)"]
|
||||
F --> G["c.Invoke(cfg, router, resourceCleaner, systemSettingSvc)"]
|
||||
G --> H["listenWithRetry(addr, 10 次, 300ms 指数退避, 上限 3s)"]
|
||||
H --> I["systemSettingSvc.SubscribeRedis(ctx)<br/>订阅 system_settings 变更 (Lite 模式 no-op)"]
|
||||
@@ -139,7 +139,7 @@ flowchart TD
|
||||
|
||||
`internal/router/router.go` 的 `NewRouter(params RouterParams)`(`RouterParams` 为 `dig.In` 结构体)按以下顺序装配,**顺序即安全语义**:
|
||||
|
||||
1. `gin.New()` + `MultipartFormCleanup`(请求结束后删除 multipart 解析落盘的临时文件)+ `SetTrustedProxies`(`WEKNORA_TRUSTED_PROXIES`,默认仅信任回环与私网段,防止伪造 `X-Forwarded-For` 绕过按 IP 限流);
|
||||
1. `gin.New()` + `MultipartFormCleanup`(请求结束后删除 multipart 解析落盘的临时文件)+ `SetTrustedProxies`(`ACADEMY_TRUSTED_PROXIES`,默认仅信任回环与私网段,防止伪造 `X-Forwarded-For` 绕过按 IP 限流);
|
||||
2. 全局中间件:`cors` → `RequestID` → `Language` → `Logger` → `Recovery` → `ErrorHandler`;
|
||||
3. 免认证端点:`GET /health`;非 release 模式挂载 `/swagger/*any`;
|
||||
4. Embed 页面 `frame-ancestors` CSP 中间件;Lite 版内嵌前端静态资源(`handler.Edition == "lite"`);
|
||||
@@ -191,9 +191,9 @@ kb.PUT("/:id", g.OwnedKBOrAdmin(), handler.UpdateKnowledgeBase)
|
||||
| 中间件 | 文件 | 职责与关键逻辑 |
|
||||
| --- | --- | --- |
|
||||
| `MultipartFormCleanup()` | multipart_cleanup.go | 请求结束(含失败与 panic 恢复)后删除 multipart 表单写入系统临时目录的文件,避免容器 `/tmp` 持续增长 |
|
||||
| `cors.New`(gin-contrib) | router.go | 允许 `Authorization`、`X-API-Key`、`X-Tenant-ID`、`X-Embed-Session`、`X-WeKnora-Desktop-Token` 及 MCP Streamable HTTP 所需的 `MCP-Protocol-Version`/`Mcp-Session-Id` 等头;MaxAge 12h |
|
||||
| `cors.New`(gin-contrib) | router.go | 允许 `Authorization`、`X-API-Key`、`X-Tenant-ID`、`X-Embed-Session`、`X-Academy-Desktop-Token` 及 MCP Streamable HTTP 所需的 `MCP-Protocol-Version`/`Mcp-Session-Id` 等头;MaxAge 12h |
|
||||
| `RequestID()` | logger.go | 复用请求头 `X-Request-ID` 或生成 UUID,写入 gin context 与 `Request.Context()`,贯穿日志/追踪 |
|
||||
| `Language()` | language.go | 决定文档处理语言:`WEKNORA_LANGUAGE` 环境变量 > `Accept-Language` 首个标签 > 默认 `zh-CN` |
|
||||
| `Language()` | language.go | 决定文档处理语言:`ACADEMY_LANGUAGE` 环境变量 > `Accept-Language` 首个标签 > 默认 `zh-CN` |
|
||||
| `Logger()` | logger.go | 请求/响应全量日志;正则脱敏密码/令牌字段、截断 base64 图片 data URL、SSE 响应标记跳过、单条上限 10KB |
|
||||
| `Recovery()` | recovery.go | panic 捕获 + 堆栈记录 + 500 响应 |
|
||||
| `ErrorHandler()` | error_handler.go | 读取 `c.Errors` 末位错误:`*errors.AppError` 按其 `HTTPCode` 返回 `{success:false, error:{code,message,details}}` 统一信封;其余 500 |
|
||||
@@ -338,7 +338,7 @@ type AppError struct {
|
||||
|
||||
## 日志体系(internal/logger) {#_8-日志体系-internal-logger}
|
||||
|
||||
- 基于 **logrus**,私有 `appLogger` 单例 + 自定义 Formatter(彩色终端输出;`WEKNORA_LOG_FORMAT` 可用 `%d` `%level` `%traceId` `%msg` 等占位符自定义模板;`LOG_PATH` 设置后经 lumberjack 轮转写文件并剥离 ANSI 颜色码);
|
||||
- 基于 **logrus**,私有 `appLogger` 单例 + 自定义 Formatter(彩色终端输出;`ACADEMY_LOG_FORMAT` 可用 `%d` `%level` `%traceId` `%msg` 等占位符自定义模板;`LOG_PATH` 设置后经 lumberjack 轮转写文件并剥离 ANSI 颜色码);
|
||||
- **request_id 贯穿**:`middleware.RequestID` 写入 context → `logger.GetLogger(ctx)` 自动提取并注入 `request_id` 字段;常用出口为 `logger.Infof/Warnf/Errorf(ctx, format, ...)` 与 `ErrorWithFields`;
|
||||
- **LLM 调试日志**(`llm_logger.go`):`LLM_DEBUG_LOG=true` 时启用,按 request_id 分文件记录每次 LLM 调用(`LLMCallRecord`:CallType Chat/Embedding/Rerank/VLM、模型、耗时、完整消息与工具调用、错误),7 天自动清理,用于排查提示词和上下文问题。
|
||||
|
||||
|
||||
Reference in new issue
Block a user