gindump

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2025 License: MIT Imports: 11 Imported by: 0

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

Start using it

Download and install it:

$ go get github.com/itmisx/gin-dump

Import it in your code:

import "github.com/itmisx/gin-dump"
Canonical example:
package main

import (
	"fmt"
	"time"
	"github.com/gin-gonic/gin"
	"github.com/itmisx/gin-dump"
)

func main() {
    router := gin.Default()
  
    showReq := true
    showResp := true
    showBody := true
    showHeaders := false
    showCookies := false
  
    router.Use(gindump.Dump(nil))   // prints on stdout
    // or
	router.Use(gindump.Dump(func(dumpStr string) {
	    fmt.Println(dumpStr)
    }))
    // or
    router.Use(gindump.DumpWithOptions(showReq, showResp, showBody, showHeaders, showCookies, nil)   // prints on stdout
    // or
	router.Use(gindump.DumpWithOptions(showReq, showResp, showBody, showHeaders, showCookies, func(dumpStr string) {
	    fmt.Println(dumpStr)
    }))

	//...
	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
}

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 Dump

func Dump() gin.HandlerFunc

func DumpWithOptions

func DumpWithOptions(showReq bool, showResp bool, showBody bool, showHeaders bool, showCookies bool) gin.HandlerFunc

func FormatJsonBytes

func FormatJsonBytes(data []byte, hiddenFields []string) (interface{}, error)

func FormatToJson

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

support

Types

This section is empty.

Jump to

Keyboard shortcuts

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