2 回答

TA贡献1830条经验 获得超3个赞
使用以下代码拦截 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贡献1803条经验 获得超6个赞
以前的答案确实完成了工作。
不过,我会推荐 Liz Rice 的演讲:GopherCon 2018:Liz Rice - The Go Programmer's Guide to Secure Connections
浏览她在Github中的代码,您可能会找到一种更优雅的方式来实现您想要的。
从第 26 行的客户端代码开始。
- 2 回答
- 0 关注
- 166 浏览
添加回答
举报