feat: bootstrap reusable GoOmni framework

This commit is contained in:
2026-09-20 22:06:24 +08:00
commit 8b19aa79ee
60 changed files with 4923 additions and 0 deletions

31
logx/README.md Normal file
View File

@@ -0,0 +1,31 @@
# logx
`logx` 是 GoOmni 的业务层结构化日志入口。业务代码不需要依赖 Gin:
```go
import "git.yuntuo.hk/k2safe/go-omni/logx"
func (s *UserService) Create(ctx context.Context, input CreateInput) error {
logx.InfoContext(ctx, "user.create.start", "email", input.Email)
// ...
return nil
}
```
应用启动时可以替换默认输出:
```go
closeLog, err := logx.Setup(logx.Config{
Service: "billing-api",
Environment: "production",
Level: "info",
Format: "json",
File: "./var/log/billing-api.log",
})
if err != nil {
return err
}
defer closeLog()
```
HTTP 请求的 `X-Request-ID` 会被放进标准 `context.Context`,之后的 `InfoContext`、`ErrorContext` 会自动带上 `requestId`。后续可以在不改变业务调用方式的前提下增加文件轮转、采样和 OpenTelemetry 导出。