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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Golang io/ioutil NopCloser

Golang io/ioutil NopCloser

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

3 回答

?
繁星淼淼

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

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


你可以在gorest 的這個分支中看到一個例子,在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

        }


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

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

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


查看完整回答
反對 回復(fù) 2021-09-13
  • 3 回答
  • 0 關(guān)注
  • 655 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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