gindump

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2023 License: MIT Imports: 12 Imported by: 2

README

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
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Indent = 4
View Source
var Newline = "\n"
View Source
var StringMaxLength = 0

Functions

func BeautifyJsonBytes

func BeautifyJsonBytes(data []byte, hiddenFields []string) ([]byte, error)

func Dump

func Dump() gin.HandlerFunc

func DumpRequest added in v0.2.0

func DumpRequest(req *http.Request, showHeaders bool, showBody bool) string

func DumpResponse added in v0.2.0

func DumpResponse(res *http.Response, showHeaders bool, showBody bool) string

func DumpResponseWriter added in v0.2.0

func DumpResponseWriter(res gin.ResponseWriter, showHeaders bool, showBody bool) string

func DumpWithOptions

func DumpWithOptions(showReq bool, showResp bool, showBody bool, showHeaders bool, cb func(dumpStr string)) gin.HandlerFunc

func FormatToBeautifulJson

func FormatToBeautifulJson(v interface{}, hiddenFields []string) ([]byte, error)

transfer v to beautified json bytes

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL