You can implement your own http.Transport.DialContext.

// from https://github.com/codesenberg/bombardier

type Conn struct {
    net.Conn
    read, written *int64
}

func (c *Conn) Read(b []byte) (int, error) {
    n, err := c.Conn.Read(b)
    if err == nil {
        atomic.AddInt64(c.read, int64(n))
    }
    return n, err
}

func (c *Conn) Write(b []byte) (int, error) {
    n, err := c.Conn.Write(b)
    if err == nil {
        atomic.AddInt64(c.written, int64(n))
    }
    return n, err
}

var read, written int64
var dialer net.Dialer

client := http.Client{
    Transport: &http.Transport{
        DialContext: func(ctx context.Context, network, addr string) (net.
Conn, error) {
            conn, err := dialer.DialContext(ctx, network, addr)
            if err != nil {
                return nil, err
            }
            return &Conn{conn, &read, &written}, nil
        },
    },
}


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to