第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在 Golang 中包裝 net.Conn.Read()

如何在 Golang 中包裝 net.Conn.Read()

Go
MMMHUHU 2023-02-06 19:35:44
我想包裝Read函數(shù) net.Conn.Read()。這樣做的目的是讀取 SSL 握手消息。https://pkg.go.dev/net#TCPConn.Readnc, err := net.Dial("tcp", "google.com:443")if err != nil {    fmt.Println(err)}tls.Client(nc, &tls.Config{})有什么辦法嗎?
查看完整描述

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{})


查看完整回答
反對(duì) 回復(fù) 2023-02-06
?
慕碼人8056858

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)始。


查看完整回答
反對(duì) 回復(fù) 2023-02-06
  • 2 回答
  • 0 關(guān)注
  • 195 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)