Golang 上下文配置
- 作者仓库星标 0
- 作者仓库 skills-registry
golang-echo-zap
Use this skill when adding or configuring github.com/adlandh/echo-zap-middleware/v2 in a Go Echo service.
Use When
- The user wants Zap request logging in an Echo app.
- Code imports
github.com/adlandh/echo-zap-middleware/v2or needs this middleware configured. - The task mentions
ZapConfig,Middleware,MiddlewareWithContextLogger,BodySkipper, request/response body logging, or Echo request IDs.
Key Facts
- This middleware targets
github.com/labstack/echo/v5; do not mix it with Echo v4 imports. - Echo v5 handlers and skippers use
*echo.Context, notecho.Context. - Import path is
github.com/adlandh/echo-zap-middleware/v2; package name isechozapmiddlewareunless aliased. Middleware(logger, config...)is the normal entrypoint for a*zap.Logger.MiddlewareWithContextLogger(ctxLogger, config...)is forgithub.com/adlandh/context-loggerextractors.ZapConfigfills defaults only for nilSkipperand nilBodySkipper; bool and int zero values are meaningful.LimitHTTPBody: truewithLimitSize <= 0disables body limiting.BodySkipperdoes not prevent body capture; it replaces non-empty logged bodies with[excluded].- Request IDs are logged from request
X-Request-Idfirst, then from Echo's response header.
Minimal Setup
import (
echozapmiddleware "github.com/adlandh/echo-zap-middleware/v2"
"github.com/labstack/echo/v5"
"github.com/labstack/echo/v5/middleware"
"go.uber.org/zap"
)
logger, err := zap.NewProduction()
if err != nil {
return err
}
e := echo.New()
e.Use(middleware.RequestID())
e.Use(echozapmiddleware.Middleware(logger))
Body And Header Logging
e.Use(echozapmiddleware.Middleware(logger, echozapmiddleware.ZapConfig{
AreHeadersDump: true,
IsBodyDump: true,
LimitHTTPBody: true,
LimitSize: 500,
Skipper: func(c *echo.Context) bool {
return c.Path() == "/health"
},
BodySkipper: func(c *echo.Context) (skipReqBody, skipRespBody bool) {
if c.Path() == "/upload" {
return true, false
}
if c.Request().Header.Get("Content-Encoding") == "gzip" {
return true, true
}
return false, false
},
}))
Context Logger Setup
import contextlogger "github.com/adlandh/context-logger"
ctxLogger := contextlogger.WithContext(logger)
e.Use(echozapmiddleware.MiddlewareWithContextLogger(ctxLogger))
Implementation Guidance
- Add
middleware.RequestID()before this middleware when generated request IDs should appear in logs. - Keep body dumping off by default for hot paths; enable
IsBodyDumponly when the service can afford body capture. - Use
BodySkipperfor sensitive or binary payloads, but still setLimitHTTPBodyandLimitSizefor large bodies. - If changing middleware behavior in this repo, preserve downstream request body replay after capture and update README configuration docs.
Verify
- In this repo, run
go test ./...for a fast check. - For body limit changes, run
go test -run TestLimitBody ./...andgo test -run 'TestMiddleware/TestBodyLimitApplied' ./.... - CI uses
go test -race -coverprofile=coverage.txt -covermode=atomic ./....
<!-- tomevault:4.0:skill_md:2026-05-23 -->Source: adlandh/echo-zap-middleware — distributed by TomeVault.
- 流狐分类
- 工程开发
- 作者声明 Agent
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 88 / 100 · 启发式扫描,不代表运行安全
- 作者 / 版本 / 许可
- @tomevault-io · 未声明 license
- 流狐 Token 估算
- 低消耗
- 流狐接入估算
- 即装即用
- 是否需要外部 API Key
- 未发现要求
- 检测到的系统要求
- 未声明
- 底层运行要求
- 未声明
- 检测到的文件与系统行为
-
- 只读
- 允许写入 / 修改
- 检测到的网络行为
- 仅限本地
- 安装命令数
- 无(仅作为资料)
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
作者没有在当前 SKILL.md 中定义固定输出样例。 The user wants Zap request logging in an Echo app. Code imports github.com/adlandh/echo-zap-middleware/v2 or needs this middleware configured. The task mentions ZapConfig, Middleware, MiddlewareWithContextLogger, BodySkipper, request/response body logging, or…
This middleware targets github.com/labstack/echo/v5; do not mix it with Echo v4 imports. Echo v5 handlers and skippers use echo.Context, not echo.Context. Import path is github.com/adlandh/echo-zap-middleware/v2; package name is echozapmiddleware unless…
Minimal Setup
Body And Header Logging
Context Logger Setup
Add middleware.RequestID() before this middleware when generated request IDs should appear in logs. Keep body dumping off by default for hot paths; enable IsBodyDump only when the service can afford body capture. Use BodySkipper for sensitive or binary…
# golang-echo-zap
Use this skill when adding or configuring `github.com/adlandh/echo-zap-middleware/v2` in a Go Echo service.
## Use When
- The user wants Zap request logging in an Echo app.
- Code imports `github.com/adlandh/echo-zap-middleware/v2` or needs this middleware configured.
- The task mentions `ZapConfig`, `Middleware`, `MiddlewareWithContextLogger`, `BodySkipper`, request/response body logging, or Echo request IDs.
## Key Facts
- This middleware targets `github.com/labstack/echo/v5`; do not mix it with Echo v4 imports.
- Echo v5 handlers and skippers use `*echo.Context`, not `echo.Context`.
- Import path is `github.com/adlandh/echo-zap-middleware/v2`; package name is `echozapmiddleware` unless aliased.
- `Middleware(logger, config...)` is the normal entrypoint for a `*zap.Logger`.
- `MiddlewareWithContextLogger(ctxLogger, config...)` is for `github.com/adlandh/context-logger` extractors.
- `ZapConfig` fills defaults only for nil `Skipper` and nil `BodySkipper`; bool and int zero values are meaningful.
- `LimitHTTPBody: true` with `LimitSize <= 0` disables body limiting.
- `BodySkipper` does not prevent body capture; it replaces non-empty logged bodies with `[excluded]`.
- Request IDs are logged from request `X-Request-Id` first, then from Echo's response header.
## Minimal Setup
```go
import (
echozapmiddleware "github.com/adlandh/echo-zap-middleware/v2"
"github.com/labstack/echo/v5"
"github.com/labstack/echo/v5/middleware"
"go.uber.org/zap"
)
logger, err := zap.NewProduction()
if err != nil {
return err
}
e := echo.New()
e.Use(middleware.RequestID())
e.Use(echozapmiddleware.Middleware(logger))
```
## Body And Header Logging
```go
e.Use(echozapmiddleware.Middleware(logger, echozapmiddleware.ZapConfig{
AreHeadersDump: true,
… 作者原文负责流程事实;流狐只索引当前章节、要点、文件与命令。
章节 -> Use When → Key Facts → Minimal Setup → Body And Header Logging → Context Logger Setup → Implementation Guidance
要点 -> Use this skill when adding or configuring github.com/adlandh/echo-zap-middleware/v2 in a Go Echo service.
文件/命令 -> github.com/adlandh/echo-zap-middleware/v2 · ZapConfig · Middleware · MiddlewareWithContextLogger · BodySkipper · github.com/labstack/echo/v5 · echo.Context · echozapmiddleware
内容 SHA-256 -> 8cf4ee3b3821
原文结构
适用与边界
原文中的明确线索
github.com/adlandh/echo-zap-middleware/v2、ZapConfig、Middleware、MiddlewareWithContextLogger、BodySkipper、github.com/labstack/echo/v5、echo.Context、echozapmiddleware