排查负载均衡服务器中某个IP指定的服务出现故障

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package main

import (
"log"
"net/http"
"net/http/httptrace"
)

func main() {
req, err := http.NewRequest("GET", "https://example.com/", nil)
if err != nil {
log.Fatal(err)
}

trace := &httptrace.ClientTrace{
GotConn: func(connInfo httptrace.GotConnInfo) {
log.Printf("resolved to: %s", connInfo.Conn.RemoteAddr())
},
}

req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace))

client := &http.Client{}
_, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
}