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

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

為什么 defer stmnt.Close() 似乎阻止了我的 http.Redirect?

為什么 defer stmnt.Close() 似乎阻止了我的 http.Redirect?

Go
達(dá)令說(shuō) 2021-11-08 09:59:21
為什么我defer stmnt.Close()似乎阻止我http.Redirect重定向它只是掛在網(wǎng)站上無(wú)限嘗試加載。但是如果我刪除defer stmnt.Close()它重定向就好了?    err = db.QueryRow("SELECT steamid FROM accounts WHERE steamid = ?", ids).Scan(&steamid)    if err != nil {        common.WriteLog(err.Error(), r)        http.Error(w, "Failed to connect to database. Try again in a bit.", 500)    }    switch {    case len(profile.Response.Players) == 0:        common.WriteLog("Failed to look you up in the steam database. Try again in a bit.", r)        http.Error(w, "Failed to look you up in the steam database. Try again in a bit.", 500)    case err == sql.ErrNoRows:        stmnt, err := db.Query("INSERT INTO accounts SET steamid=?", ids)        if err != nil {            common.WriteLog(err.Error(), r)            http.Error(w, "Failed to insert your account to the database. Try again in a bit.", 500)        }        defer stmnt.Close() // <<<<< The suspect        // Insert Account        http.Redirect(w, r, "/", 303)    case err != nil:        common.WriteLog(err.Error(), r)        http.Error(w, "Failed to insert your account to the database. Try again in a bit.", 500)    default:        // Login User        http.Redirect(w, r, "/", 303)    }
查看完整描述

1 回答

?
海綿寶寶撒

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

使用db.Exec代替db.Query。


Exec 執(zhí)行查詢(xún)而不返回任何行。


對(duì)比


Query 執(zhí)行返回行的查詢(xún)


至于為什么,我猜mysqlRows.Close正在等待連接上的數(shù)據(jù):


func (rows *mysqlRows) Close() error {

    mc := rows.mc

    if mc == nil {

        return nil

    }

    if mc.netConn == nil {

        return ErrInvalidConn

    }


    // Remove unread packets from stream

    err := mc.readUntilEOF()

    rows.mc = nil

    return err

}

這是永遠(yuǎn)不會(huì)發(fā)生的。


請(qǐng)參閱示例。


查看完整回答
反對(duì) 回復(fù) 2021-11-08
  • 1 回答
  • 0 關(guān)注
  • 193 瀏覽
慕課專(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)