Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(out io.Writer, level Level) train.Interceptor
New returns a logging interceptor with the given level that writes to the given writer.
Example ¶
package main import ( "bytes" "fmt" "net/http" "net/http/httptest" "strings" "time" "github.com/f2prateek/train" "github.com/f2prateek/train/log" "github.com/gohttp/response" ) func main() { var buf bytes.Buffer client := &http.Client{ Transport: train.Transport(log.New(&buf, log.Body)), } ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { w.Header().Set("Date", time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Format(time.RFC1123)) response.OK(w, "Hello World!") })) defer ts.Close() req, err := http.NewRequest("GET", ts.URL, nil) if err != nil { panic(err) } req.Host = "127.0.0.1:54709" client.Do(req) fmt.Println(strings.Replace(buf.String(), "\r", "", -1)) }
Output: GET / HTTP/1.1 Host: 127.0.0.1:54709 User-Agent: Go-http-client/1.1 Accept-Encoding: gzip HTTP/1.1 200 OK Content-Length: 13 Content-Type: text/plain; charset=utf-8 Date: Tue, 10 Nov 2009 23:00:00 UTC Hello World!
Types ¶
Click to show internal directories.
Click to hide internal directories.