修改程序入口

This commit is contained in:
2025-11-05 16:00:43 +08:00
parent bee5104661
commit aaa2f1b22f
5 changed files with 129 additions and 106 deletions

View File

@@ -6,19 +6,19 @@
- **`internal/infra/logs/logs.go` (`logs.Logger` - 内部实现,非注入)**
- **核心包级函数实现 (根据 `implementation.md` 描述)**:
- [ ] 实现 `AddCompName(ctx context.Context, compName string) context.Context`
- [ ] 实现
- [x] 实现 `AddCompName(ctx context.Context, compName string) context.Context`
- [x] 实现
`AddFuncName(upstreamCtx context.Context, selfCtx context.Context, funcName string) context.Context`
- [ ] 实现 `GetLogger(ctx context.Context) *Logger`
- [ ] 实现
- [x] 实现 `GetLogger(ctx context.Context) *Logger`
- [x] 实现
`Trace(upstreamCtx context.Context, selfCtx context.Context, funcName string) (context.Context, *Logger)`
- **`Logger` 结构体改造**:
- [ ] 无
- [x] 无
- **`GormLogger` 改造**:
- [ ] 修改 `GormLogger.Info` 方法,从传入的 `ctx` 中获取 `logger` 实例,并使用该实例进行日志记录。
- [ ] 修改 `GormLogger.Warn` 方法,从传入的 `ctx` 中获取 `logger` 实例,并使用该实例进行日志记录。
- [ ] 修改 `GormLogger.Error` 方法,从传入的 `ctx` 中获取 `logger` 实例,并使用该实例进行日志记录。
- [ ] 修改 `GormLogger.Trace` 方法,从传入的 `ctx` 中获取 `logger` 实例,并使用该实例进行日志记录。特别是
- [x] 修改 `GormLogger.Info` 方法,从传入的 `ctx` 中获取 `logger` 实例,并使用该实例进行日志记录。
- [x] 修改 `GormLogger.Warn` 方法,从传入的 `ctx` 中获取 `logger` 实例,并使用该实例进行日志记录。
- [x] 修改 `GormLogger.Error` 方法,从传入的 `ctx` 中获取 `logger` 实例,并使用该实例进行日志记录。
- [x] 修改 `GormLogger.Trace` 方法,从传入的 `ctx` 中获取 `logger` 实例,并使用该实例进行日志记录。特别是
`With(fields...)` 的调用需要调整。
---
@@ -26,16 +26,16 @@
#### 2. 依赖注入与结构体改造
- **`internal/core/application.go`**:
- [ ] 移除 `Application` 结构体中的 `Logger *logs.Logger` 成员。
- [ ] 修改 `NewApplication` 函数,使其不再创建 `logger`,而是创建根 `context.Background()`
- [ ] 调整 `NewApplication`,将根 `context` 传递给 `initInfrastructure`, `initDomainServices`, `initAppServices`
- [x] 移除 `Application` 结构体中的 `Logger *logs.Logger` 成员。
- [x] 修改 `NewApplication` 函数,使其不再创建 `logger`,而是创建根 `context.Background()`
- [x] 调整 `NewApplication`,将根 `context` 传递给 `initInfrastructure`, `initDomainServices`, `initAppServices`
`api.NewAPI`
- [ ] 移除 `Application` 结构体中所有对 `app.Logger` 的直接调用,改为通过 `context` 获取 `Logger`
- [x] 移除 `Application` 结构体中所有对 `app.Logger` 的直接调用,改为通过 `context` 获取 `Logger`
- **`internal/core/component_initializers.go`**:
- [ ] **修改所有组件结构体定义**: 遍历所有相关组件Controllers, Services, Repositories 等),将其结构体中的
- [x] **修改所有组件结构体定义**: 遍历所有相关组件Controllers, Services, Repositories 等),将其结构体中的
`logger *logs.Logger` 成员变量替换为 `selfCtx context.Context`
- [ ] **重构所有 `init...` 函数**:
- [x] **重构所有 `init...` 函数**:
- 移除所有 `logger *logs.Logger` 参数,改为接收 `ctx context.Context`
- 在每个 `init...` 函数内部,为即将创建的组件生成其专属的 `selfCtx`。例如:
`selfCtx := logs.AddCompName(ctx, 'ComponentName')`