Skip to content

Latest commit

 

History

History
43 lines (32 loc) · 1.03 KB

README.md

File metadata and controls

43 lines (32 loc) · 1.03 KB

GIN dumper

codecov Build Status

  • Gin middleware handler for dumping body and headers of request(and response).
  • You can easily use it with your logger
Sample
package main

import (
    "github.com/gin-gonic/gin"
    "github.com/nikonm/gin-dumper"
    "fmt"
)

func main () {
    router := gin.New()

    opt := &gin_dumper.Options{TrimNewLineInRequest: "   "}

    router.Use(gin_dumper.Dumper(func(output *gin_dumper.Output) {
        fmt.Printf("REQUEST: %s %s Headers: %v Body: %s Resp: %d JsonBody: %s\n",
			output.Request.Method,
			output.Request.Url.RequestURI(),
			output.Request.Headers,
			output.Request.Body,
			output.Response.StatusCode,
			output.Response.Body,
		)
    }, opt))

    router.POST("/test", func(c *gin.Context) {
		// Some Action
    })
	
    router.Run(":80")
}