首先,我略高於Go中的初學者,需要一點幫助。 我以爲我已經斷言(據我已經學會了去了),但我不斷收到此錯誤 cannot use readBack["SomePIN"] (type interface {}) as type string in argument to c.String: need type assertion
錯誤:需要類型斷言
這裏是我的代碼(該段是從一個請求處理函數和我使用回聲的Web框架和細節一般的NoSQL數據庫)
// To get query result document, simply
// read it [as stated in the Tiedot readme.md]
for id := range queryResult {
readBack, err := aCollection.Read(id)
if err != nil {
panic(err)
}
if readBack["OtherID"] == otherID {
if _, ok := readBack["SomePIN"].(string); ok {
return c.String(http.StatusOK, readBack["SomePIN"])
}
}
}