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

View File

@@ -0,0 +1,31 @@
package handler
import (
"time"
"git.yuntuo.hk/k2safe/go-omni"
"git.yuntuo.hk/k2safe/go-omni/logx"
)
// RequestLog demonstrates business middleware using only the GoOmni API.
func RequestLog(logger *logx.Logger) omni.Middleware {
return func(next omni.Handler) omni.Handler {
return func(ctx *omni.Context) error {
started := time.Now()
err := next(ctx)
attributes := []any{
"requestId", ctx.RequestID(),
"method", ctx.Request().Method,
"path", ctx.Request().URL.Path,
"duration", time.Since(started),
}
if err != nil {
attributes = append(attributes, "error", err)
logger.ErrorContext(ctx.Request().Context(), "request failed", attributes...)
} else {
logger.InfoContext(ctx.Request().Context(), "request completed", attributes...)
}
return err
}
}
}