govisual

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 4, 2025 License: MIT Imports: 12 Imported by: 2

README

GoVisual

A lightweight, zero-configuration HTTP request visualizer and debugger for Go web applications during local development.

Features

  • Real-time Request Monitoring: Visualize HTTP requests passing through your application
  • Request Inspection: Deep inspection of headers, body, status codes, and timing information
  • Middleware Tracing: Visualize middleware execution flow and identify performance bottlenecks
  • Zero Configuration: Drop-in integration with standard Go HTTP handlers
  • OpenTelemetry Integration: Optional export of telemetry data to OpenTelemetry collectors

Installation

go get github.com/doganarif/govisual

Quick Start

package main

import (
    "net/http"
    "github.com/doganarif/govisual"
)

func main() {
    mux := http.NewServeMux()

    // Add your routes
    mux.HandleFunc("/api/users", userHandler)

    // Wrap with GoVisual
    handler := govisual.Wrap(
        mux,
        govisual.WithRequestBodyLogging(true),
        govisual.WithResponseBodyLogging(true),
    )

    http.ListenAndServe(":8080", handler)
}

Access the dashboard at http://localhost:8080/__viz

Configuration Options

handler := govisual.Wrap(
    mux,
    govisual.WithMaxRequests(100),              // Number of requests to store
    govisual.WithDashboardPath("/__dashboard"), // Custom dashboard path
    govisual.WithRequestBodyLogging(true),      // Log request bodies
    govisual.WithResponseBodyLogging(true),     // Log response bodies
    govisual.WithIgnorePaths("/health"),        // Paths to ignore
    govisual.WithOpenTelemetry(true),           // Enable OpenTelemetry
    govisual.WithServiceName("my-service"),     // Service name for OTel
    govisual.WithServiceVersion("1.0.0"),       // Service version
    govisual.WithOTelEndpoint("localhost:4317"), // OTLP endpoint
)

Examples

Basic Example

Simple example showing core functionalities:

cd cmd/examples/basic
go run main.go
OpenTelemetry Example

Example showing integration with OpenTelemetry:

cd cmd/examples/otel
docker-compose up -d  # Start Jaeger
go run main.go

Visit OpenTelemetry Integration for detailed instructions.

Dashboard Features

GoVisual Dashboard

  • Request Table: View all captured HTTP requests with method, path, status code, and response time
  • Request Details: One-click access to headers, body content, and timing information
  • Middleware Trace: Interactive visualization of middleware execution flow
  • Request Filtering: Filter by HTTP method, status code, path pattern, or duration
  • Real-time Updates: See new requests appear instantly as they happen

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Wrap

func Wrap(handler http.Handler, opts ...Option) http.Handler

Wrap wraps an http.Handler with request visualization middleware

Types

type Config

type Config struct {
	MaxRequests int

	DashboardPath string

	LogRequestBody bool

	LogResponseBody bool

	IgnorePaths []string

	// OpenTelemetry configuration
	EnableOpenTelemetry bool

	ServiceName string

	ServiceVersion string

	OTelEndpoint string
}

func (*Config) ShouldIgnorePath

func (c *Config) ShouldIgnorePath(path string) bool

ShouldIgnorePath checks if a path should be ignored based on the configured patterns ShouldIgnorePath checks if a path should be ignored based on the configured patterns

type Option

type Option func(*Config)

Option is a function that modifies the configuration

func WithDashboardPath

func WithDashboardPath(path string) Option

WithDashboardPath sets the path to access the dashboard

func WithIgnorePaths

func WithIgnorePaths(patterns ...string) Option

WithIgnorePaths sets the path patterns to ignore

func WithMaxRequests

func WithMaxRequests(max int) Option

WithMaxRequests sets the maximum number of requests to store

func WithOTelEndpoint added in v0.1.3

func WithOTelEndpoint(endpoint string) Option

WithOTelEndpoint sets the OTLP endpoint for exporting telemetry data

func WithOpenTelemetry added in v0.1.3

func WithOpenTelemetry(enabled bool) Option

WithOpenTelemetry enables or disables OpenTelemetry instrumentation

func WithRequestBodyLogging

func WithRequestBodyLogging(enabled bool) Option

WithRequestBodyLogging enables or disables request body logging

func WithResponseBodyLogging

func WithResponseBodyLogging(enabled bool) Option

WithResponseBodyLogging enables or disables response body logging

func WithServiceName added in v0.1.3

func WithServiceName(name string) Option

WithServiceName sets the service name for OpenTelemetry

func WithServiceVersion added in v0.1.3

func WithServiceVersion(version string) Option

WithServiceVersion sets the service version for OpenTelemetry

Directories

Path Synopsis
cmd
examples/basic command
examples/otel command
internal

Jump to

Keyboard shortcuts

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