This commit is contained in:
Manfred Touron
2017-05-18 18:54:23 +02:00
parent dc386661ca
commit 5448f25fd6
645 changed files with 55908 additions and 33297 deletions

View File

@@ -1,8 +1,6 @@
gorilla/handlers
================
[![GoDoc](https://godoc.org/github.com/gorilla/handlers?status.svg)](https://godoc.org/github.com/gorilla/handlers) [![Build Status](https://travis-ci.org/gorilla/handlers.svg?branch=master)](https://travis-ci.org/gorilla/handlers)
[![Sourcegraph](https://sourcegraph.com/github.com/gorilla/handlers/-/badge.svg)](https://sourcegraph.com/github.com/gorilla/handlers?badge)
Package handlers is a collection of handlers (aka "HTTP middleware") for use
with Go's `net/http` package (or any framework supporting `http.Handler`), including:

View File

@@ -94,7 +94,7 @@ func makeLogger(w http.ResponseWriter) loggingResponseWriter {
return logger
}
type commonLoggingResponseWriter interface {
type loggingResponseWriter interface {
http.ResponseWriter
http.Flusher
Status() int

View File

@@ -1,21 +0,0 @@
// +build go1.8
package handlers
import (
"fmt"
"net/http"
)
type loggingResponseWriter interface {
commonLoggingResponseWriter
http.Pusher
}
func (l *responseLogger) Push(target string, opts *http.PushOptions) error {
p, ok := l.w.(http.Pusher)
if !ok {
return fmt.Errorf("responseLogger does not implement http.Pusher")
}
return p.Push(target, opts)
}

View File

@@ -1,34 +0,0 @@
// +build go1.8
package handlers
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
)
func TestLoggingHandlerWithPush(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if _, ok := w.(http.Pusher); !ok {
t.Fatalf("%T from LoggingHandler does not satisfy http.Pusher interface when built with Go >=1.8", w)
}
w.WriteHeader(200)
})
logger := LoggingHandler(ioutil.Discard, handler)
logger.ServeHTTP(httptest.NewRecorder(), newRequest("GET", "/"))
}
func TestCombinedLoggingHandlerWithPush(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if _, ok := w.(http.Pusher); !ok {
t.Fatalf("%T from CombinedLoggingHandler does not satisfy http.Pusher interface when built with Go >=1.8", w)
}
w.WriteHeader(200)
})
logger := CombinedLoggingHandler(ioutil.Discard, handler)
logger.ServeHTTP(httptest.NewRecorder(), newRequest("GET", "/"))
}

View File

@@ -1,7 +0,0 @@
// +build !go1.8
package handlers
type loggingResponseWriter interface {
commonLoggingResponseWriter
}

View File

@@ -6,14 +6,9 @@ import (
"runtime/debug"
)
// RecoveryHandlerLogger is an interface used by the recovering handler to print logs.
type RecoveryHandlerLogger interface {
Println(...interface{})
}
type recoveryHandler struct {
handler http.Handler
logger RecoveryHandlerLogger
logger *log.Logger
printStack bool
}
@@ -51,7 +46,7 @@ func RecoveryHandler(opts ...RecoveryOption) func(h http.Handler) http.Handler {
// RecoveryLogger is a functional option to override
// the default logger
func RecoveryLogger(logger RecoveryHandlerLogger) RecoveryOption {
func RecoveryLogger(logger *log.Logger) RecoveryOption {
return func(h http.Handler) {
r := h.(*recoveryHandler)
r.logger = logger
@@ -78,11 +73,11 @@ func (h recoveryHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
h.handler.ServeHTTP(w, req)
}
func (h recoveryHandler) log(v ...interface{}) {
func (h recoveryHandler) log(message interface{}) {
if h.logger != nil {
h.logger.Println(v...)
h.logger.Println(message)
} else {
log.Println(v...)
log.Println(message)
}
if h.printStack {