Files
pig-farm-controller/design/provide-logger-with-mothed/task-api.md
2025-11-03 23:17:06 +08:00

10 lines
724 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

- **`internal/app/api/api.go` (`API`)**:
- [ ] 修改 `NewAPI` 函数,移除 `logger` 参数,改为接收 `ctx context.Context`
- [ ] 移除 `API` 结构体中的 `logger` 成员,改为保存 `selfCtx context.Context`
- [ ] 为 `API` 组件本身创建 `selfCtx``selfCtx := logs.AddCompName(ctx, 'API')`,并传递给所有 `Controller`
的构造函数。
- [ ] 改造 `Start` 方法,从 `a.selfCtx` 获取 `logger` 实例进行日志记录。
- [ ] 改造 `Stop` 方法,从 `a.selfCtx` 获取 `logger` 实例进行日志记录。
- **`internal/app/api/router.go`
- [ ] 改造 `setupRoutes` 方法,从 `a.selfCtx` 获取 `logger` 实例进行日志记录。