middleware

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: Apache-2.0 Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Metrics

type Metrics struct {
	ReqCntURLLabelMappingFn RequestCounterURLLabelMappingFn
}

Metrics contains the metrics gathered by the instance

func NewMetrics

func NewMetrics(expandedParams []string) *Metrics

NewMetrics generates a new set of metrics

func (*Metrics) HandlerFunc

func (m *Metrics) HandlerFunc(metricsPrefix []string, ignoreURLs []string, replaceSlashWithUnderscore bool) gin.HandlerFunc

HandlerFunc is a function which should be used as middleware to count requests stats such as request processing time, request and response size and store it in rcrowley/go-metrics.DefaultRegistry.

type RequestCounterURLLabelMappingFn

type RequestCounterURLLabelMappingFn func(c *gin.Context) string

RequestCounterURLLabelMappingFn is a function which can be supplied to the middleware to control the cardinality of the request counter's "url" label, which might be required in some contexts. For instance, if for a "/customer/:name" route you don't want to generate a time series for every possible customer name, you could use this function:

func(c *gin.Context) string {
	url := c.Request.URL.String()
	for _, p := range c.Params {
		if p.Key == "name" {
			url = strings.Replace(url, p.Value, ":name", 1)
			break
		}
	}
	return url
}

which would map "/customer/alice" and "/customer/bob" to their template "/customer/:name".

Jump to

Keyboard shortcuts

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