hyhilman / stringid

provides string based ID generators, and accompanying middleware

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

provides string based ID generators, and accompanying middleware

License:MIT License


Languages

Language:Go 100.0%