Package stringid
provides string based ID generators, and accompanying
middleware for assigning a request ID to standard HTTP request contexts.
Install in the usual Go fashion:
$ go get -u github.com/kenshaw/stringid
stringid
can be used similarly to the following:
// examples/goji/main.go
package main
import (
"fmt"
"net/http"
goji "goji.io"
"goji.io/pat"
"github.com/kenshaw/stringid"
)
func main() {
mux := goji.NewMux()
mux.Use(stringid.Middleware())
mux.HandleFunc(pat.New("/"), func(res http.ResponseWriter, req *http.Request) {
fmt.Fprintf(res, "request id: %s\n", stringid.FromContext(req.Context()))
})
http.ListenAndServe(":3000", mux)
}
Please see the GoDoc listing for the full API listing.