2 回答

TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超3個(gè)贊
使用以下代碼攔截 read on a net.Conn:
type wrap {
// Conn is the wrapped net.Conn.
// Because it's an embedded field, the
// net.Conn methods are automatically promoted
// to wrap.
net.Conn
}
// Read calls through to the wrapped read and
// prints the bytes that flow through. Replace
// the print statement with whatever is appropriate
// for your application.
func (w wrap) Read(p []byte) (int, error) {
n, err := w.Conn.Read()
fmt.Printf("%x\n", p[:n]) // example
return n, err
}
像這樣包裹:
tnc, err :=tls.Client(wrap{nc}, &tls.Config{})

TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超6個(gè)贊
以前的答案確實(shí)完成了工作。
不過(guò),我會(huì)推薦 Liz Rice 的演講:GopherCon 2018:Liz Rice - The Go Programmer's Guide to Secure Connections
瀏覽她在Github中的代碼,您可能會(huì)找到一種更優(yōu)雅的方式來(lái)實(shí)現(xiàn)您想要的。
從第 26 行的客戶(hù)端代碼開(kāi)始。
- 2 回答
- 0 關(guān)注
- 195 瀏覽
添加回答
舉報(bào)