Skip to content

tpkeeper/gin-dump

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gin-dump

  • Gin middleware/handler to dump header/body of request and response .

  • Very helpful for debugging your applications.

  • More beautiful output than httputil.DumpXXX()

Content-type support / todo

  • application/json
  • application/x-www-form-urlencoded
  • text/xml
  • application/xml
  • text/plain

Usage

All:

func main() {
    router := gin.Default()
    
    //use Dump() default will print on stdout
    router.Use(gindump.Dump())
    
    //or use DumpWithOptions() with more options    
    router.Use(gindump.DumpWithOptions(true, true, false, true, false, func(dumpStr string) {
	    fmt.Println(dumpStr)
    }))
    
    router.Post("/",myHandler)
    
    ...
    
    router.Run()
}

Group:

func main() {
    router := gin.Default()
    
    dumpGroup := router.Group("/group")
    
    //use Dump() default will print on stdout
    dumpGroup.Use(gindump.Dump())
    
    //or use DumpWithOptions() with more options    
    dumpGroup.Use(gindump.DumpWithOptions(true, true, false, true, false, func(dumpStr string) {
	    fmt.Println(dumpStr)
    }))
    
    dumpGroup.Post("/",myHandler)
    
    ...
    
    router.Run()
}

EndPoint:

func main() {
    router := gin.Default()
    
    //use Dump() default will print on stdout
    router.Post("/",gindump.Dump(),myHandler)
    
    //or use DumpWithOptions() with more options    
    router.Post("/",gindump.DumpWithOptions(true, true, false, true, false, func(dumpStr string) {
	    fmt.Println(dumpStr)
    }),myHandler)
    
    ...
    
    router.Run()
}

Output is as follows

[GIN-dump]:
Request-Header:
{
    "Content-Type": [
        "application/x-www-form-urlencoded"
    ]
}
Request-Body:
{
    "bar": [
        "baz"
    ],
    "foo": [
        "bar",
        "bar2"
    ]
}
Response-Header:
{
    "Content-Type": [
        "application/json; charset=utf-8"
    ]
}
Response-Body:
{
    "data": {
        "addr": "tpkeeper@qq.com",
        "name": "jfise"
    },
    "ok": true
}

About

Gin middleware to dump header/body of request and response.Very helpful for debugging your applications.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages