httplogger

package module
v0.0.0-...-6d1b89f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2014 License: MIT Imports: 4 Imported by: 0

README

go-httplogger

Go HTTP client logger.

GoDoc

Install

go get github.com/koofr/go-httplogger

Testing

go test

Documentation

Overview

Package httplogger provides http.RoundTripper wrapper for debugging HTTP client.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TransportLogger

type TransportLogger struct {
	Transport http.RoundTripper
	Writer    io.Writer
}

TransportLogger is an implementation of RoundTripper that takes another RoundTripper and loggs all traffic to the Writer.

Example
go http.ListenAndServe(":8083", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Date", "Wed, 28 May 2014 12:00:27 GMT")
	fmt.Fprintln(w, "Hello, client")
}))

client := &http.Client{
	Transport: httplogger.New(http.DefaultTransport),
}

res, err := client.Post("http://localhost:8083", "text/plain", bytes.NewReader([]byte("123")))

if err != nil {
	log.Fatal(err)
}

greeting, err := ioutil.ReadAll(res.Body)

res.Body.Close()

if err != nil {
	log.Fatal(err)
}

fmt.Printf("%s", greeting)
Output:

func New

func New(transport http.RoundTripper) *TransportLogger

New creates new TransportLogger for given transport.

func NewDefault

func NewDefault() *TransportLogger

NewDefault creates new TransportLogger for http.DefaultTransport

func (*TransportLogger) RoundTrip

func (t *TransportLogger) RoundTrip(req *http.Request) (res *http.Response, err error)

RoundTrip implements the RoundTripper interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL