Documentation ¶
Overview ¶
package httpstat traces HTTP latency infomation (DNSLookup, TCP Connection and so on) on any golang HTTP request. It uses `httptrace` package. Just create `go-httpstat` powered `context.Context` and give it your `http.Request` (no big code modification is required).
Example ¶
req, err := http.NewRequest("GET", "http://deeeet.com", nil) if err != nil { log.Fatal(err) } // Create go-httpstat powered context and pass it to http.Request var result httpstat.Result ctx := httpstat.WithHTTPStat(req.Context(), &result) req = req.WithContext(ctx) client := http.DefaultClient res, err := client.Do(req) if err != nil { log.Fatal(err) } if _, err := io.Copy(ioutil.Discard, res.Body); err != nil { log.Fatal(err) } res.Body.Close() end := time.Now() // Show results log.Printf("Name Lookup: %d ms", int(result.NameLookup/time.Millisecond)) log.Printf("Connect: %d ms", int(result.Connect/time.Millisecond)) log.Printf("Start Transfer: %d ms", int(result.StartTransfer/time.Millisecond)) log.Printf("Total: %d ms", int(result.Total(end)/time.Millisecond))
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Result ¶
type Result struct { // The following are duration for each phase DNSLookup time.Duration TCPConnection time.Duration TLSHandshake time.Duration ServerProcessing time.Duration // The followings are timeline of reuqest NameLookup time.Duration Connect time.Duration Pretransfer time.Duration StartTransfer time.Duration // contains filtered or unexported fields }
Result stores httpstat info.
func (*Result) ContentTransfer ¶
ContentTransfer returns the duration of content transfer time. It is from first response byte to the given time. The time must be time after read body (go-httpstat can not detect that time).
Click to show internal directories.
Click to hide internal directories.