Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/fatihkahveci/gin-inspector

Gin middleware for investigating http request.
https://github.com/fatihkahveci/gin-inspector

Last synced: 2 months ago
JSON representation

Gin middleware for investigating http request.

Awesome Lists containing this project

README

        

# Gin Inspector

![Gin Inspector HTML Preview](https://raw.githubusercontent.com/fatihkahveci/gin-inspector/master/preview-html.png)

![Gin Inspector HTML Preview 2](https://raw.githubusercontent.com/fatihkahveci/gin-inspector/master/preview-html-2.jpg)

Gin middleware for investigating http request.

## Usage

```sh
$ go get github.com/fatihkahveci/gin-inspector
```

### JSON Response

```
package main

import (
"github.com/fatihkahveci/gin-inspector"
"github.com/gin-gonic/gin"
)

func main() {
r := gin.Default()
debug := true

if debug {
r.Use(inspector.InspectorStats())
r.GET("/_inspector", func(c *gin.Context) {
c.JSON(200, inspector.GetPaginator())
})
}

r.Run()
}
```

### Html Template

```
package main

import (
"html/template"
"net/http"
"time"

"github.com/fatihkahveci/gin-inspector"
"github.com/gin-gonic/gin"
)

func formatDate(t time.Time) string {
return t.Format(time.RFC822)
}

func main() {
r := gin.Default()
r.Delims("{{", "}}")

r.SetFuncMap(template.FuncMap{
"formatDate": formatDate,
})

r.LoadHTMLFiles("inspector.html")
debug := true

if debug {
r.Use(inspector.InspectorStats())

r.GET("/_inspector", func(c *gin.Context) {
c.HTML(http.StatusOK, "inspector.html", map[string]interface{}{
"title": "Gin Inspector",
"pagination": inspector.GetPaginator(),
})

})
}

r.Run(":8080")
}

```