An open API service indexing awesome lists of open source software.

https://github.com/artarts36/go-http-metrics

Go HTTP Metrics
https://github.com/artarts36/go-http-metrics

go http metrics prometheus

Last synced: 7 months ago
JSON representation

Go HTTP Metrics

Awesome Lists containing this project

README

          

# go-http-metrics

```
go get github.com/artarts36/go-http-metrics
```

## Usage example

```go
package main

import (
"net/http"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"

metrics "github.com/artarts36/go-http-metrics"
)

func main() {
mm := metrics.NewMetrics()
prometheus.MustRegister(mm)

http.Handle("/metrics", promhttp.Handler())

http.Handle("GET /users/{user_id}", mm.Middleware(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.Write([]byte("hello world"))
})))

http.ListenAndServe(":8080", nil)
}
```