Skip to content

Instantly share code, notes, and snippets.

@cep21
cep21 / httptrace_example.go
Last active July 28, 2023 15:23
Example of http trace in Go 1.7
package main
import (
"fmt"
"io"
"net/http"
"net/http/httptest"
"net/http/httptrace"
"os"
)
@cep21
cep21 / client_trace.go
Created August 26, 2016 22:40
ClientTrace object
type ClientTrace struct {
// GetConn is called before a connection is created or
// retrieved from an idle pool. The hostPort is the
// "host:port" of the target or proxy. GetConn is called even
// if there's already an idle cached connection available.
GetConn func(hostPort string)
// GotConn is called after a successful connection is
// obtained. There is no hook for failure to obtain a
// connection; instead, use the error from
type ClientTrace struct {
// Called before a connection is established. If it returns a
// non nil object, that object is used instead for the Connection.
GetConn func(hostPort string) *net.Conn
}
type ClientTrace struct {
// Called before a connection is established. The returned context is used
// to finish processing the request.
GetConn func(ctx context.Context, hostPort string) context.Context
}
type Request struct {
Method string
URL *url.URL
// ...
// Trace callbacks are executed if they are set
Trace ClientTrace
}
@cep21
cep21 / client_trace_log.go
Created August 27, 2016 02:18
client trace as logging instead
type ClientTrace struct {
Log(state string)
}
@cep21
cep21 / request.go
Created August 28, 2016 23:13
ClientTrace example
if trace != nil && trace.WroteHeaders != nil {
trace.WroteHeaders()
}
@cep21
cep21 / customer.go
Last active October 26, 2016 17:59
package customer
type User struct {
Name string
}
type Item struct {
Price float64
}
@cep21
cep21 / client.go
Last active November 1, 2016 18:58
package cart
import "customer"
type Client struct {
}
func (c *Client) Purchase(who *customer.User, what *customer.Item) {
}
package customer
type User struct {
Name string
}