Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nasa9084/go-logtransport

http.RoundTripper which logs request/response
https://github.com/nasa9084/go-logtransport

Last synced: 11 days ago
JSON representation

http.RoundTripper which logs request/response

Awesome Lists containing this project

README

        

logtransport
===

[![GoDoc](https://godoc.org/github.com/nasa9084/go-logtransport?status.svg)](https://godoc.org/github.com/nasa9084/go-logtransport)

logtransport is a thin wrapper of http.RoundTripper interface, which logs request and response using given logger.

## SYNOPSIS

``` go
func Example() {
handler := func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("Hello, world!"))
}
srv := httptest.NewServer(http.HandlerFunc(handler))
defer srv.Close()

c := &http.Client{
Transport: &logtransport.Transport{
// you can use other logger like sirupsen/logrus
Logger: log.New(os.Stdout, "", log.LstdFlags),
},
}
c.Get(srv.URL)
}

```

or if you do not need to customize HTTP transport, just import `overwrite` subpackage with blank identifier:

``` go
import _ "github.com/nasa9084/go-logtransport/overwrite"
```