go-resty/resty中Trace Info说明

版权声明 本站原创文章 由 萌叔 发表 转载请注明 萌叔 | http://vearne.cc 1.引言 今天萌叔翻看Golang的request库go-resty/resty,看了请求trace Info的相关的细节。 程序如下: package main import ( "fmt" "github.com/go-resty/resty/v2" ) func main() { target := "https://vearne.cc/" client := resty.New() resp, err := client.R(). EnableTrace(). Get(target) if err != nil { fmt.Println("error:", err) return } fmt.Println(len(resp.String()), resp.StatusCode()) // Explore trace info fmt.Println("Request Trace Info:") ti := resp.Request.TraceInfo() fmt.Println(" DNSLookup :", ti.DNSLookup) fmt.Println(" ConnTime :", ti.ConnTime) fmt.Println(" TCPConnTime :", ti.TCPConnTime) fmt.Println(" TLSHandshake :", ti.TLSHandshake) fmt.Println(" ServerTime :", ti.ServerTime) fmt.Println(" ResponseTime :", ti.ResponseTime) fmt.Println(" TotalTime :", ti.TotalTime) fmt.Println(" IsConnReused :", ti.IsConnReused) fmt.Println(" IsConnWasIdle :", ti.IsConnWasIdle) fmt.Println(" ConnIdleTime :", ti.ConnIdleTime) fmt.Println(" RequestAttempt:", ti.RequestAttempt) fmt.Println(" RemoteAddr :", ti.RemoteAddr.String()) } 输出: ...

July 22, 2022 · 1 min