3 ZH_Debug
Lunny Xiao edited this page 2019-11-27 09:08:08 +08:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Debug中间件为你调试请求和返回提供方便它是一个 Tango 的中间件。

安装

go get gitea.com/tango/debug

示例

type DebugAction struct {
    tango.Ctx
}

func (c *DebugAction) Get() {
    c.Write([]byte("get"))
}

func main() {
    t := tango.Classic()
    t.Use(debug.Debug())
    t.Get("/", new(DebugAction))
    t.Run()
}

当你运行时你将会在控制台或log文件中发现请求和响应的头和具体信息。

[tango] 2015/03/04 06:44:06 [Debug] debug.go:53 [debug] request: GET http://localhost:3000/
[tango] 2015/03/04 06:44:06 [Debug] debug.go:55 [debug] head: map[]
[tango] 2015/03/04 06:44:06 [Debug] debug.go:66 [debug] ----------------------- end request
[tango] 2015/03/04 06:44:06 [Debug] debug.go:78 [debug] response ------------------ 200
[tango] 2015/03/04 06:44:06 [Debug] debug.go:80 [debug] head: map[]
[tango] 2015/03/04 06:44:06 [Debug] debug.go:83 [debug] body: debug
[tango] 2015/03/04 06:44:06 [Debug] debug.go:85 [debug] ----------------------- end response