$ show zsais/go-gin-prometheus
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.
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.