reqlog

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

README

  1. 从 github 下载源码

https://github.com/FirasLatrech/reqlog

前端地址

进入 /packages/dashboard/,npm build 后,将 /packages/core/dist/dashboard/ 的内容复制到 /packages/go/dashboard_dist/中,因为在 dashboard.go 中,有个 embed 语句,嵌入了这个目录的内容。

Documentation

Overview

Package reqlog provides a live HTTP request dashboard for Go web applications. It captures every request hitting your server and displays them in a real-time browser dashboard with full request/response inspection, latency tracking, and replay.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	Port          int  // Dashboard port (default: 9000)
	MaxRequests   int  // Max entries in ring buffer (default: 200)
	SlowThreshold int  // Latency threshold in ms to flag slow requests (default: 200)
	AutoOpen      bool // Auto-open browser on start (default: true)
	AllowInProd   bool // Allow running in production (default: false)
	AllowNetwork  bool // Allow network access to the dashboard (default: false, only localhost)
}

Options configures the reqlog instance.

type Reqlog

type Reqlog struct {
	// contains filtered or unexported fields
}

Reqlog is the main reqlog instance that runs the dashboard server and provides middleware.

func New

func New(opts Options) *Reqlog

New creates a new Reqlog instance with the given options.

func (*Reqlog) ChiMiddleware

func (r *Reqlog) ChiMiddleware() func(http.Handler) http.Handler

ChiMiddleware returns a Chi-compatible middleware. Chi uses the standard net/http middleware signature, so this is an alias for Middleware().

func (*Reqlog) GinMiddleware

func (r *Reqlog) GinMiddleware() gin.HandlerFunc

GinMiddleware returns a Gin middleware that captures requests and responses.

func (*Reqlog) IsBlocked

func (r *Reqlog) IsBlocked() bool

IsBlocked returns true if reqlog is blocked (e.g. production mode without AllowInProd).

func (*Reqlog) Middleware

func (r *Reqlog) Middleware() func(http.Handler) http.Handler

Middleware returns a standard net/http middleware that captures requests and responses.

func (*Reqlog) Port

func (r *Reqlog) Port() int

Port returns the actual port the dashboard is listening on, or 0 if not started.

func (*Reqlog) Start

func (r *Reqlog) Start() error

Start starts the dashboard HTTP server. It blocks until the server is ready. In production (GO_ENV=production or APP_ENV=production), it will no-op unless AllowInProd is set.

func (*Reqlog) Stop

func (r *Reqlog) Stop() error

Stop gracefully shuts down the dashboard server.

type ReqlogEntry

type ReqlogEntry struct {
	ID              string            `json:"id"`
	Timestamp       int64             `json:"timestamp"`
	Method          string            `json:"method"`
	URL             string            `json:"url"`
	StatusCode      int               `json:"statusCode"`
	Latency         int64             `json:"latency"`
	Slow            bool              `json:"slow"`
	RequestHeaders  map[string]string `json:"requestHeaders"`
	ResponseHeaders map[string]string `json:"responseHeaders"`
	RequestBody     any               `json:"requestBody"`
	ResponseBody    any               `json:"responseBody"`
	AppHost         string            `json:"appHost"`
}

ReqlogEntry represents a captured HTTP request/response pair.

func (ReqlogEntry) GetID

func (e ReqlogEntry) GetID() string

GetID implements the ID interface for ReqlogEntry.

type RingBuffer

type RingBuffer[T interface{ GetID() string }] struct {
	// contains filtered or unexported fields
}

RingBuffer is a thread-safe circular buffer that overwrites the oldest entries when full.

func NewRingBuffer

func NewRingBuffer[T interface{ GetID() string }](capacity int) *RingBuffer[T]

NewRingBuffer creates a new ring buffer with the given capacity.

func (*RingBuffer[T]) FindByID

func (rb *RingBuffer[T]) FindByID(id string) (T, bool)

FindByID finds an item by its ID. Returns the item and true if found.

func (*RingBuffer[T]) Push

func (rb *RingBuffer[T]) Push(item T)

Push adds an item to the buffer, overwriting the oldest if full.

func (*RingBuffer[T]) ToSlice

func (rb *RingBuffer[T]) ToSlice() []T

ToSlice returns all items in order from oldest to newest.

Jump to

Keyboard shortcuts

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