# README
requestid
RequestID middleware for Go forked from ascarter/requestid
with custom extensions to pass the request ID with Twirp
RequestID adds a UUID as X-Request-ID
header if not already set. It also adds
it to the http.Request Context. Use requestid.FromContext
to get the generated
request id.
Example
package main
import (
"fmt"
"html"
"log"
"net/http"
"github.com/elblox/requestid"
)
func handler(w http.ResponseWriter, r *http.Request) {
rid, _ := requestid.FromContext(r.Context())
log.Println("Running hello handler:", rid)
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
}
func main() {
h := http.HandlerFunc(handler)
http.Handle("/", requestid.RequestIDHandler(h))
log.Fatal(http.ListenAndServe(":8080", nil))
}
# Functions
FromContext returns the request id from context.
NewContext creates a context with request id set as context value as well as twirp request header.
RequestIDHandler sets unique request id.
# Constants
No description provided by the author