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

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

這個(gè)函數(shù)在哪里返回非錯(cuò)誤?

這個(gè)函數(shù)在哪里返回非錯(cuò)誤?

Go
達(dá)令說 2021-11-15 15:48:12
我正在圍繞數(shù)據(jù)存儲(chǔ)GetAll函數(shù)構(gòu)建一個(gè)包裝器,我很難找到該函數(shù)返回非錯(cuò)誤的位置。在我看來,除非有任何其他錯(cuò)誤(即當(dāng)它中斷時(shí)Done),否則它會(huì)返回errFieldMismatch我認(rèn)為不正確的。func (q *Query) GetAll(c context.Context, dst interface{}) ([]*Key, error) {    var (        dv               reflect.Value        mat              multiArgType        elemType         reflect.Type        errFieldMismatch error    )    if !q.keysOnly {        dv = reflect.ValueOf(dst)        if dv.Kind() != reflect.Ptr || dv.IsNil() {            return nil, ErrInvalidEntityType        }        dv = dv.Elem()        mat, elemType = checkMultiArg(dv)        if mat == multiArgTypeInvalid || mat == multiArgTypeInterface {            return nil, ErrInvalidEntityType        }    }    var keys []*Key    for t := q.Run(c); ; {        k, e, err := t.next()        if err == Done {            break        }        if err != nil {            return keys, err        }        if !q.keysOnly {            ev := reflect.New(elemType)            if elemType.Kind() == reflect.Map {                // This is a special case. The zero values of a map type are                // not immediately useful; they have to be make'd.                //                // Funcs and channels are similar, in that a zero value is not useful,                // but even a freshly make'd channel isn't useful: there's no fixed                // channel buffer size that is always going to be large enough, and                // there's no goroutine to drain the other end. Theoretically, these                // types could be supported, for example by sniffing for a constructor                // method or requiring prior registration, but for now it's not a                // frequent enough concern to be worth it. Programmers can work around                // it by explicitly using Iterator.Next instead of the Query.GetAll                // convenience method.                x := reflect.MakeMap(elemType)                ev.Elem().Set(x)            }
查看完整描述

1 回答

?
慕娘9325324

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

默認(rèn)是 return errFieldMismatch,它在函數(shù)頂部聲明,但未初始化。

如果ErrFieldMismatch在迭代過程中的任何時(shí)候都沒有,errFieldMismatch仍然會(huì)nil在最后,因此GetAll會(huì)返回nil錯(cuò)誤。


查看完整回答
反對 回復(fù) 2021-11-15
  • 1 回答
  • 0 關(guān)注
  • 178 瀏覽

添加回答

舉報(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)