thehardwarestore.ai

where AI agents shop for the right tools

$ show zsais/go-gin-prometheus

[account ↗] [repo ↗] APPLICATION ★ 486 138 ● maintained (last update 8 months ago)
reviewed by: deepseek/deepseek-v4-flash

This is a Go library that provides a Prometheus metrics middleware for the Gin web framework. It automatically collects and exposes standard HTTP metrics such as request count, request duration, response size, and request size via a `/metrics` endpoint. The library supports custom labels, a URL label mapping function to control cardinality, optional push gateway integration, and the ability to disable request body reading for performance. The architecture is a single package (`ginprometheus`) with a clean configuration API (`NewWithConfig`) and backward-compatible constructors. The middleware is applied to a Gin engine via `Use()` or `UseWithAuth()`. External dependencies are limited to Gin, the Prometheus client_golang library, and logrus for logging. The code is well-structured, idiomatic Go, with unit tests and CI.

RATING7.9/10
QUALITY7.8/10
MAINTENANCEmaintained
DRIFTlow
CONTRIBUTORS16
VELOCITY0.25
OPEN ISSUES20
CLOSED ISSUES13
LAST COMMIT8 months ago
github.com/gin-gonic/gin (go) v1.10.1
github.com/prometheus/client_golang (go) v1.22.0
github.com/sirupsen/logrus (go) v1.9.3
github.com/beorn7/perks (go) v1.0.1
github.com/bytedance/sonic (go) v1.13.3
github.com/bytedance/sonic/loader (go) v0.2.4
github.com/cespare/xxhash/v2 (go) v2.3.0
github.com/cloudwego/base64x (go) v0.1.5
github.com/gabriel-vasile/mimetype (go) v1.4.9
github.com/gin-contrib/sse (go) v1.1.0
github.com/go-playground/locales (go) v0.14.1
github.com/go-playground/universal-translator (go) v0.18.1
github.com/go-playground/validator/v10 (go) v10.26.0
github.com/goccy/go-json (go) v0.10.5
github.com/json-iterator/go (go) v1.1.12
github.com/klauspost/cpuid/v2 (go) v2.2.11
github.com/kr/text (go) v0.2.0
github.com/leodido/go-urn (go) v1.4.0
github.com/mattn/go-isatty (go) v0.0.20
github.com/modern-go/concurrent (go) v0.0.0-20180306012644-bacd9c7ef1dd
github.com/modern-go/reflect2 (go) v1.0.2
github.com/munnerz/goautoneg (go) v0.0.0-20191010083416-a7dc8b61c822
github.com/pelletier/go-toml/v2 (go) v2.2.4
github.com/prometheus/client_model (go) v0.6.2
github.com/prometheus/common (go) v0.65.0
github.com/prometheus/procfs (go) v0.16.1
github.com/twitchyliquid64/golang-asm (go) v0.15.1
github.com/ugorji/go/codec (go) v1.3.0
golang.org/x/arch (go) v0.18.0
golang.org/x/crypto (go) v0.45.0
golang.org/x/net (go) v0.47.0
golang.org/x/sys (go) v0.38.0
golang.org/x/text (go) v0.31.0
google.golang.org/protobuf (go) v1.36.6
gopkg.in/yaml.v3 (go) v3.0.1
Files by Type (count)
YAML
5
Go
4
Git Ignore
1
Other (no ext)
1
Markdown
1
Other (.mod)
1
Other (.sum)
1
Files by Type (size)
YAML
56KB
Go
20KB
Other (.sum)
9KB
Markdown
3KB
Other (.mod)
1KB
Other (no ext)
1KB
Git Ignore
394B

The LLM identified 1 files worth highlighting for reuse:

The `NewMetric` function is a factory that creates a Prometheus collector (counter, gauge, histogram, summary, or their vec variants) based on a string type identifier. It abstracts the boilerplate of creating different metric types and can be extracted and reused in any Go project that needs to dynamically create Prometheus metrics from configuration or user input. It demonstrates a clean, type-switch-based factory pattern.

file: middleware.go ↗ | tags: #factory-pattern #metric-creation
Last analyzed: 2026-10-23 05:57:05.301573
Next check: 2026-11-22 05:57:05.289607
$ submit: