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

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

Golang io/ioutil NopCloser

Golang io/ioutil NopCloser

Go
桃花長相依 2021-09-13 10:53:24
有沒有人對(duì) Golang 的NopCloser功能有很好的解釋?我環(huán)顧四周,但除了 Golang 的主要文檔對(duì)以下內(nèi)容的解釋外,沒有找到任何內(nèi)容:NopCloser 返回一個(gè) ReadCloser,其中包含一個(gè)封裝了提供的 Reader r 的無操作 Close 方法。任何指針或解釋將不勝感激。謝謝。
查看完整描述

3 回答

?
繁星淼淼

TA貢獻(xiàn)1775條經(jīng)驗(yàn) 獲得超11個(gè)贊

每當(dāng)您需要返回 an 時(shí)io.ReadCloser,同時(shí)確保 aClose()可用,您可以使用 aNopCloser來構(gòu)建這樣的 ReaderCloser。


你可以在gorest 的這個(gè)分支中看到一個(gè)例子,在util.go


//Marshals the data in interface i into a byte slice, using the Marhaller/Unmarshaller specified in mime.

//The Marhaller/Unmarshaller must have been registered before using gorest.RegisterMarshaller

func InterfaceToBytes(i interface{}, mime string) (io.ReadCloser, error) {

    v := reflect.ValueOf(i)

    if v.Kind() == reflect.Ptr {

        v = v.Elem()

    }

    switch v.Kind() {

    case reflect.Bool:

        x := v.Bool()

        if x {

            return ioutil.NopCloser(bytes.NewBuffer([]byte("true"))), nil

        }


查看完整回答
反對(duì) 回復(fù) 2021-09-13
?
千巷貓影

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊

它用于需要io.ReadCloser但當(dāng)前對(duì)象(例如 a bytes.Buffer)不提供 Close 函數(shù)的函數(shù)。


查看完整回答
反對(duì) 回復(fù) 2021-09-13
  • 3 回答
  • 0 關(guān)注
  • 634 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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