diff --git a/Makefile b/Makefile index b2bedc5..2930eda 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,6 @@ deps: mocks: $(MOCKS_CMD) -.PHONY: godoc -godoc: +.PHONY: docs +docs: godoc -http=":6060" diff --git a/Readme.md b/Readme.md index 6a575f7..169226f 100644 --- a/Readme.md +++ b/Readme.md @@ -1,8 +1,8 @@ # go-http-metrics [![Build Status][github-actions-image]][github-actions-url] [![Go Report Card][goreport-image]][goreport-url] [![GoDoc][godoc-image]][godoc-url] -go-http-metrics knows how to measure http metrics in different metric formats, it comes with a middleware that will measure metrics of a Go net/http handler. The metrics measured are based on [RED] and/or [Four golden signals], follow standards and try to be measured in a efficient way. +go-http-metrics knows how to measure http metrics in different metric formats. The metrics measured are based on [RED] and/or [Four golden signals], follow standards and try to be measured in a efficient way. -If you are using a framework that isn't directly compatible with go's `http.Handler` interface from the std library, do not worry, there are multiple helpers available to get middlewares fo the most used http Go frameworks. If there isn't you can open an issue or a PR. +It measures based on a middleware that is compatible with Go core net/http handler, if you are using a framework that isn't directly compatible with go's `http.Handler` interface, do not worry, there are multiple helpers available to get middlewares for the most used http Go frameworks. If there isn't you can open an issue or a PR. ## Table of contents diff --git a/doc.go b/doc.go index 792f967..ae6b668 100644 --- a/doc.go +++ b/doc.go @@ -1,3 +1,42 @@ +/* +Package gohttpmetrics knows how to measure http metrics in different metric formats, +it comes with a middleware that can be used for different frameworks and also the +the main Go net/http handler: + package main + + import ( + "log" + "net/http" + + "github.com/prometheus/client_golang/prometheus/promhttp" + httpmetrics "github.com/slok/go-http-metrics/metrics/prometheus" + httpmiddleware "github.com/slok/go-http-metrics/middleware" + ) + + func main() { + // Create our middleware. + mdlw := httpmiddleware.New(httpmiddleware.Config{ + Recorder: httpmetrics.NewRecorder(httpmetrics.Config{}), + }) + + // Our handler. + myHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + w.Write([]byte("hello world!")) + }) + h := mdlw.Handler("", myHandler) + + // Serve metrics. + log.Printf("serving metrics at: %s", ":9090") + go http.ListenAndServe(":9090", promhttp.Handler()) + + // Serve our handler. + log.Printf("listening at: %s", ":8080") + if err := http.ListenAndServe(":8080", h); err != nil { + log.Panicf("error while serving: %s", err) + } + } +*/ package gohttpmetrics // blank imports help docs.