# README
About
Package stringid
provides string based ID generators, and accompanying
middleware for assigning a request ID to standard HTTP request contexts.
Installing
Install in the usual Go fashion:
$ go get -u github.com/kenshaw/stringid
Using
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.
# Packages
Package grpcid provides a gRPC middleware interceptor that adds a string ID to the request context.
# Functions
FromContext returns the ID previously set on the context.
FromRequest returns the ID previously set on the request's context.
Generate generates a ID using the DefaultGenerator.
HeaderMiddleware creates a standard HTTP middleware handler that sets the request ID as read from one of the supplied headers.
Middleware creates a standard HTTP middleware handler that sets a request ID on the HTTP context.
NewPushGenerator creates a new push ID generator.
NewUUIDGenerator creates a ID generator that generates UUIDv4 style IDs.
WithGenerator is a middleware option to set the generator used.
WithID creates a new context with the supplied ID.
WithPrefix is a middleware option to set a prefix on generated IDs.
WithRequest returns the supplied HTTP request with a new context containing the supplied ID.
# Variables
DefaultGenerator is the default ID generator.
# Structs
GeneratorMiddleware provides standard HTTP middleware that sets a HTTP request ID based on the Prefix and a Generator's generated ID.
PushGenerator is a push-style ID generator that satisifies the Generator interface.
# Interfaces
Generator is the common interface for ID generators.
# Type aliases
GeneratorFunc wraps a standard func as a ID generator.
MiddlewareOption is a middleware option.