Documentation ¶
Index ¶
- func Error(w http.ResponseWriter, text string, code int)
- func ErrorCountHandler(errorCount *expvar.Int, next http.Handler) http.Handler
- func ErrorLogHandler(out io.Writer, next http.Handler) http.Handler
- func GzipHandler(next http.Handler) http.Handler
- func LogHandler(out io.Writer, next http.Handler) http.Handler
- func PanicHandler(next http.Handler) http.Handler
- func Status1xxCounterHandler(counter *expvar.Int, next http.Handler) http.Handler
- func Status2xxCounterHandler(counter *expvar.Int, next http.Handler) http.Handler
- func Status3xxCounterHandler(counter *expvar.Int, next http.Handler) http.Handler
- func Status4xxCounterHandler(counter *expvar.Int, next http.Handler) http.Handler
- func Status5xxCounterHandler(counter *expvar.Int, next http.Handler) http.Handler
- func TimeoutHandler(timeout time.Duration, next http.Handler) http.Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Error ¶
func Error(w http.ResponseWriter, text string, code int)
Error formats and emits the specified error message text and status code information to the http.ResponseWriter, to be consumed by the client of the service. This particular helper function has nothing to do with emitting log messages on the server side, and only creates a response for the client. Typically handlers will call this method prior to invoking return to exit to whichever handler invoked it.
// example function which guards downstream handlers to ensure only HTTP GET method used // to access resource. func onlyGet(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Method != "GET" { gohm.Error(w, r.Method, http.StatusMethodNotAllowed) return } next.ServeHTTP(w, r) }) }
func ErrorCountHandler ¶
ErrorCountHandler returns a new http.Handler that composes the specified next http.Handler, and increments the specified counter when the response status code is not http.StatusOK.
var errorCount = expvar.NewInt("/example/path/errorCount") mux := http.NewServeMux() mux.Handle("/example/path", gohm.ErrorCount(errorCount, decodeURI(expand(querier))))
func ErrorLogHandler ¶
ErrorLogHandler returns a new http.Handler that logs HTTP requests that result in response errors. The handler will output lines in common log format to the specified io.Writer.
func GzipHandler ¶
GzipHandler returns a new http.Handler that optionally compresses the response text using the gzip compression algorithm when the HTTP request's Accept-Encoding header includes the string "gzip".
var errorCount = expvar.NewInt("/example/path/errorCount") mux := http.NewServeMux() mux.Handle("/example/path", gohm.GzipHandler(decodeURI(expand(querier))))
func LogHandler ¶
LogHandler returns a new http.Handler that logs HTTP requests and responses in common log format to the specified io.Writer.
func PanicHandler ¶
PanicHandler returns a new http.Handler that catches a panic caused by the specified http.Handler, and responds with an appropriate http status code and message.
func Status1xxCounterHandler ¶ added in v0.1.0
Status1xxCounterHandler returns a new http.Handler that composes the specified next http.Handler, and increments the specified counter when the response status code is not 1xx.
var counter1xx = expvar.NewInt("counter1xx") mux := http.NewServeMux() mux.Handle("/example/path", gohm.Status1xxConterHandler(counter1xx, decodeURI(expand(querier))))
func Status2xxCounterHandler ¶ added in v0.1.0
Status2xxCounterHandler returns a new http.Handler that composes the specified next http.Handler, and increments the specified counter when the response status code is not 2xx.
var counter2xx = expvar.NewInt("counter2xx") mux := http.NewServeMux() mux.Handle("/example/path", gohm.Status2xxConterHandler(counter2xx, decodeURI(expand(querier))))
func Status3xxCounterHandler ¶ added in v0.1.0
Status3xxCounterHandler returns a new http.Handler that composes the specified next http.Handler, and increments the specified counter when the response status code is not 3xx.
var counter3xx = expvar.NewInt("counter3xx") mux := http.NewServeMux() mux.Handle("/example/path", gohm.Status3xxConterHandler(counter3xx, decodeURI(expand(querier))))
func Status4xxCounterHandler ¶ added in v0.1.0
Status4xxCounterHandler returns a new http.Handler that composes the specified next http.Handler, and increments the specified counter when the response status code is not 4xx.
var counter4xx = expvar.NewInt("counter4xx") mux := http.NewServeMux() mux.Handle("/example/path", gohm.Status4xxConterHandler(counter4xx, decodeURI(expand(querier))))
func Status5xxCounterHandler ¶ added in v0.1.0
Status5xxCounterHandler returns a new http.Handler that composes the specified next http.Handler, and increments the specified counter when the response status code is not 5xx.
var counter5xx = expvar.NewInt("counter5xx") mux := http.NewServeMux() mux.Handle("/example/path", gohm.Status5xxConterHandler(counter5xx, decodeURI(expand(querier))))
Types ¶
This section is empty.