package
1.8.0
Repository: https://github.com/synapsecns/sanguine.git
Documentation: pkg.go.dev

# README

Gin Helper

Note: gindump utilities are courtesy of this repo and have only been updated/modified here because of dependency issues.

  • 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
}

# Functions

BeautifyJSONBytes beautifies json bytes.
Dump dumps the request and response.
DumpWithOptions dumps the request and response with options.
FormatToBeautifulJSON dumps v to beautified json bytes.
New creates a new gin server with some sensible defaults.
NewWithExperimentalLogger creates a new gin server with some sensible defaults.
TraceMiddleware is a middleware that traces the request/response.
WaitForStart waits for the connection to be ready on a ginhelper like server times out after serverStartTimeout.

# Constants

HealthCheck is the health check endpoint.
MetricsEndpoint is used for prometheus metrics.
RequestIDHeader is used for tracking request ids.
RobotsTxt is used for apis to disallow crawls.

# Variables

CorsEnabled is used to enable cors on the server.
Indent is the number of spaces to indent.
Newline is the string to use for newlines.
StringMaxLength is the maximum length of a string to display.