Code Monkey home page Code Monkey logo

gin-dump's Introduction

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": "[email protected]",
        "name": "jfise"
    },
    "ok": true
}

gin-dump's People

Contributors

gladyskellogg avatar samber avatar tpkeeper avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gin-dump's Issues

Expose bodyHiddenFields on the middleware

Current behavior:

  • Middleware handler does not accept hidden fields from user, which makes the handler to print sensitive fields

Expected behavior

  • Accept bodyHiddenFields slice of string on the handler which can be used to remove sensitive fields
DumpWithOptions(hideFields []string,showReq bool, showResp bool, showBody bool, showHeaders bool, showCookies bool, cb func(dumpStr string)) gin.HandlerFunc

Maybe add example of how to use directly on route?

Hi! Nice work!

Would be nice if the Dump() method did not require "nil" to perform standard (stdout) and if you could add examples to the README showing how to use the middleware in both groups and endpoints aswell:

Group

router := gin.New()
dumpAll := router.Group("/group")
dumpAll.Use(gindump.Dump(nil))
dumpAll.POST("/", MyEndpointHandler)
dumpAll.PUT("/", MyOtherEndpointHandler)

Endpoint

router := gin.New()
dumpOne := router.Group("/group")
dumpOne.POST("/", gindump.Dump(nil), MyEndpointHandler)

go get result in error

Tried to go get your middleware but it resulted in the following,

go get -u github.com/tpkeeper/gin-dump
go: finding golang.org/x/sys latest
go: finding github.com/gin-contrib/sse latest
go: finding gopkg.in/check.v1 latest
go: extracting github.com/ugorji/go v1.1.4
go: extracting github.com/ugorji/go/codec v0.0.0-20181022190402-e5e69e061d4f
go build github.com/ugorji/go/codec: no Go files in

I do not understand why it is trying to get two version of ugorji/go?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.