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

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

恐慌 - 未收到數(shù)據(jù) - ERR_EMPTY_RESPONSE

恐慌 - 未收到數(shù)據(jù) - ERR_EMPTY_RESPONSE

Go
qq_遁去的一_1 2021-12-27 10:38:03
我正在使用gorethink驅(qū)動程序,我在模型中編寫了這樣的查詢函數(shù)func GetQuotesByUser(idUser string) []Quote{    ids:=GetQuoteIdsByUser(idUser)    if (len(ids)>0){        result,err:=r.Table("quote").GetAll(ids...).Run(config.Connection())        defer result.Close()        if err!=nil{            fmt.Println(err)            return []Quote{}        }        var quotes []Quote        err=result.All(&quotes)        if err!=nil{            fmt.Println(err)            return []Quote{}        }        fmt.Println(quotes)        return quotes    } else{        return []Quote{}    }}我編寫了一個調(diào)用上述函數(shù)的路由處理程序import (    "corate/util"    "corate/model"    "github.com/fatih/structs"    "net/http")func DashboardHandler(w http.ResponseWriter,r *http.Request){    files:=[]string{"base","dashboard"}    session,_:=util.GlobalSessions.SessionStart(w,r)    defer session.SessionRelease(w)    quotes:=model.GetQuotesByUser("ca8a2e14-f65b-43b1-b655-97d7c29190ec")    q:=structs.Map(quotes)    util.RenderTemplate(w,q,files...)}這是main功能func main(){    // Setup database    config.Setupdb()    // Initialize session manager    util.InitSessionManager()    // Serve static folder    http.Handle("/public/",http.StripPrefix("/public/",http.FileServer(http.Dir("public"))))    // Setup routers and middlewares    http.HandleFunc("/",route.IndexHandler)    http.HandleFunc("/login",route.GoogleLoginHandler)    http.HandleFunc("/auth/google",route.GoogleCallbackHandler)    http.Handle("/dashboard",negroni.New(        negroni.HandlerFunc(route.IsAuthenticated),        negroni.Wrap(http.HandlerFunc(route.DashboardHandler)),    ))    // Start listening    http.ListenAndServe(":3000",nil)}我使用astaxie/beego/session庫來管理此服務(wù)器的會話import (    "github.com/astaxie/beego/session")var (    GlobalSessions *session.Manager)當(dāng)我啟動服務(wù)器,登錄并請求dashboard路徑,DashboardHandler被處理,GetQuotesByUser被調(diào)用,它工作,它工作,它確實打印出查詢的真實結(jié)果。但是在瀏覽器中,瀏覽器拋出錯誤:沒有接收到數(shù)據(jù)ERR_EMPTY_RESPONSE為什么會發(fā)生?然后我注意到,如果我不使用fatih/structs庫,就不會出錯。但是我想使用那個庫,它對我有很大幫助。我想知道這種奇怪行為的原因以及如何在仍在使用fatih/structs庫的同時修復(fù)它
查看完整描述

1 回答

?
哈士奇WWW

TA貢獻1799條經(jīng)驗 獲得超6個贊

GetQuotesByUser返回一個切片,而不是一個結(jié)構(gòu)。所以你不能直接將它傳遞給structs.Map. 您必須迭代切片并將每個元素單獨轉(zhuǎn)換為地圖。


quotes := model.GetQuotesByUser("ca8a2e14-f65b-43b1-b655-97d7c29190ec")


qs := []map[string]interface{}{}

for _, q := range quotes {

    qs = append(qs, structs.Map(q))

}


util.RenderTemplate(w,qs,files...)

應(yīng)該讓你接近你所追求的。


查看完整回答
反對 回復(fù) 2021-12-27
  • 1 回答
  • 0 關(guān)注
  • 272 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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