inspector

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2024 License: MIT Imports: 8 Imported by: 0

README

Gin Inspector

Gin Inspector HTML Preview

Gin Inspector HTML Preview 2

Gin middleware for investigating http request.

Usage

$ go get github.com/krobus00/gin-inspector@v1.1.0
Html Template
package main

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

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

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

	r.SetFuncMap(template.FuncMap{
		"inspectorFormatDate": func(t time.Time) string {
			return t.Format(time.RFC822)
		},
	})

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

	if debug {
		r.Use(inspector.InspectorStats(/_inspector, 10000))

		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")
}


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InspectorStats

func InspectorStats(inspectorEndpoint string, multipartFormMaxMemory int64, sensitiveKeys []string) gin.HandlerFunc

Types

type AllRequests

type AllRequests struct {
	Request []RequestStat `json:"requests"`
}

type Pagination

type Pagination struct {
	Total       int           `json:"total"`
	TotalPage   int           `json:"total_page"`
	CurrentPage int           `json:"current_page"`
	PerPage     int           `json:"per_page"`
	HasNext     bool          `json:"has_next"`
	HasPrev     bool          `json:"has_prev"`
	NextPageUrl string        `json:"next_page_url"`
	PrevPageUrl string        `json:"prev_page_url"`
	Data        []RequestStat `json:"data"`
}

func GetPaginator

func GetPaginator() Pagination

type RequestStat

type RequestStat struct {
	RequestedAt   time.Time `json:"requested_at"`
	RequestUrl    string    `json:"request_url"`
	HttpMethod    string    `json:"http_method"`
	HttpStatus    int       `json:"http_status"`
	ContentType   string    `json:"content_type"`
	GetParams     any       `json:"get_params"`
	PostParams    any       `json:"post_params"`
	PostMultipart any       `json:"post_multipart"`
	Body          any       `json:"body"`
	ClientIP      string    `json:"client_ip"`
	Cookies       any       `json:"cookies"`
	Headers       any       `json:"headers"`
}

Jump to

Keyboard shortcuts

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