```go
var once sync.Once
var f *os.File
var err error
func DebugLogger(c iris.Context) {
once.Do(func() {
f, err = os.Create("debug.log")
if err != nil {
log.App().Error("DebugLogger error:", zap.Error(err))
}
})
if f == nil {
log.App().Error("debug.log not exists")
c.Next()
return
}
requestDump, err := httputil.DumpRequest(c.Request(), true)
if err != nil {
log.App().Error("logger error:", zap.Error(err))
}
c.Next()
fmt.Fprintln(f, string(requestDump))
fmt.Println(c.Request().Response)
responseDump, err := httputil.DumpResponse(c.Request().Response, true)
if err != nil {
fmt.Println(err)
}
fmt.Fprintln(f, string(responseDump))
}
```
发现 (c.Request().Response 为 nil,如何才能获取到 reposne
有疑问加站长微信联系(非本文作者)