Documentation
¶
Overview ¶
Package correlation is a HTTP middleware that adds correlation ids to incoming requests.
package main
import (
"net/http"
"gitlab.com/JanMa/correlation"
)
var myHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hello world"))
})
func main() {
correlationMiddleware := correlation.New(correlation.Options{
CorrelationIDType: correlation.UUID,
})
http.ListenAndServe(":8080", correlationMiddleware.Handler(myHandler))
}
Index ¶
- Constants
- type Correlation
- func (c *Correlation) Handler(h http.Handler) http.Handler
- func (c *Correlation) HandlerForRequestOnly(h http.Handler) http.Handler
- func (c *Correlation) HandlerFuncWithNext(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
- func (c *Correlation) HandlerFuncWithNextForRequestOnly(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
- func (c *Correlation) ModifyResponseHeaders(res *http.Response) error
- func (c *Correlation) Process(w http.ResponseWriter, r *http.Request) error
- type Options
Constants ¶
const ( // UUID generate a random UUID as correlation id. UUID correlationType = iota + 1 // CUID generate a CUID as correlation id. CUID // Random generate a pseudo random Int64 as correlation id. Random // Custom pass a custom string as correlation id. Custom // Time use the elapsed nanoseconds since the Epoch as correlation id. Time )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Correlation ¶
type Correlation struct {
// contains filtered or unexported fields
}
Correlation is a middleware that adds correlation ids to requests. A correlation.Options struct can be provided t override the default configuration values.
func New ¶
func New(opt Options) *Correlation
New returns a new correlation struct with the provides options.
func (*Correlation) Handler ¶
func (c *Correlation) Handler(h http.Handler) http.Handler
Handler for integration with net/http.
func (*Correlation) HandlerForRequestOnly ¶
func (c *Correlation) HandlerForRequestOnly(h http.Handler) http.Handler
HandlerForRequestOnly for integration with net/http.
func (*Correlation) HandlerFuncWithNext ¶
func (c *Correlation) HandlerFuncWithNext(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
HandlerFuncWithNext for integration with github.com/urfave/negroni.
func (*Correlation) HandlerFuncWithNextForRequestOnly ¶
func (c *Correlation) HandlerFuncWithNextForRequestOnly(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
HandlerFuncWithNextForRequestOnly for integration with github.com/urfave/negroni.
func (*Correlation) ModifyResponseHeaders ¶
func (c *Correlation) ModifyResponseHeaders(res *http.Response) error
ModifyResponseHeaders modifies the response for integration with net/http/httputil ReverseProxy.
func (*Correlation) Process ¶
func (c *Correlation) Process(w http.ResponseWriter, r *http.Request) error
Process processes the incoming request.
type Options ¶
type Options struct {
// CorrelationHeaderName the name of the header to be used as correlation id. Defaults to `X-Correlation-ID`.
CorrelationHeaderName string
// CorrelationIDType the type of correlation id to generate. Defaults to `correlation.UUID`.
CorrelationIDType correlationType
// CorrelationCustomString the value to use when using a custom correlation id. Default is empty.
CorrelationCustomString string
}
Options is a struct for specifying configuration options.