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

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

QOR示例恐慌

QOR示例恐慌

Go
ABOUTYOU 2022-09-12 20:26:19
我正在嘗試運(yùn)行該程序此鏈接。然而,我運(yùn)行它,它導(dǎo)致側(cè)面的恐慌。由于我是語(yǔ)言新手,我不知道如何調(diào)試它。gormgo該程序的迷你版本(沒(méi)有fb,推特和其他登錄界面)package mainimport (    "net/http"    "github.com/qor/auth"    "github.com/qor/auth/auth_identity"    "github.com/qor/auth/providers/password"    "github.com/qor/session/manager"    "github.com/jinzhu/gorm")var (    gormDB, _ = gorm.Open("sqlite3", "sample.db")    Auth = auth.New(&auth.Config{        DB: gormDB,    }))func init() {    // Migrate AuthIdentity model, AuthIdentity will be used to save auth info, like username/password, oauth token, you could change that.    gormDB.AutoMigrate(&auth_identity.AuthIdentity{})    // Register Auth providers    // Allow use username/password    Auth.RegisterProvider(password.New(&password.Config{}))}func main() {    mux := http.NewServeMux()    // Mount Auth to Router    mux.Handle("/auth/", Auth.NewServeMux())    http.ListenAndServe(":9000", manager.SessionManager.Middleware(mux))}我將我命名的文件放在一個(gè)文件夾中(是文件夾中唯一的文件),然后我運(yùn)行以初始化項(xiàng)目并安裝所需的包。然后我這樣做,我得到以下內(nèi)容:main.gomain.gogo mod init project_name && go mod tidygo run .panic: runtime error: invalid memory address or nil pointer dereference[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x6d0441]我真的很迷茫,因?yàn)槲也恢廊绾握{(diào)試它。似乎是結(jié)構(gòu)中的指針(我不知道如何更改)。順便說(shuō)一句,我正在使用.auth_identity.AuthIdentitygo version go1.16.5 linux/amd64
查看完整描述

3 回答

?
慕尼黑的夜晚無(wú)繁華

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

這似乎不是在戈?duì)柲分姓_打開(kāi) SQLite 數(shù)據(jù)庫(kù)的方法。


您缺少 SQLite 驅(qū)動(dòng)程序的導(dǎo)入,而不是傳遞字符串“sqlite3”,而應(yīng)該傳遞和指向 .sqlite.Open("sample.db")gorm.Config


請(qǐng)參閱 https://gorm.io/docs/connecting_to_the_database.html#SQLite


import (

  "gorm.io/driver/sqlite"

  "gorm.io/gorm"

)


// github.com/mattn/go-sqlite3

db, err := gorm.Open(sqlite.Open("gorm.db"), &gorm.Config{})


查看完整回答
反對(duì) 回復(fù) 2022-09-12
?
汪汪一只貓

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

func init在建立數(shù)據(jù)庫(kù)連接之前執(zhí)行,gorm 無(wú)法遷移,并且在此處引發(fā)恐慌。


試試這個(gè)代碼




func main(){

    gormDB, err = gorm.Open("sqlite3", "sample.db")

    if err != nil {

      log.Falal(err) // thrown, if database cannot be opened

    }

    // database connection is established, ready to perform migrations:



    Auth = auth.New(&auth.Config{

        DB: gormDB,

    })


    // Migrate AuthIdentity model, AuthIdentity will be used to save auth info, like username/password, oauth token, you could change that.

    err = gormDB.AutoMigrate(&auth_identity.AuthIdentity{})

    if err != nil {  

        log.Fatal(err) // do not forget to throw exception, if migration fails

    }


    // Register Auth providers

    // Allow use username/password

    Auth.RegisterProvider(password.New(&password.Config{}))



    err = gormDB.AutoMigrate(&auth_identity.AuthIdentity{})

    if err != nil {  

       log.Fatal(err) // do not forget to throw exception, if migration fails

    }

    // Register Auth providers

    // Allow use username/password

    Auth.RegisterProvider(password.New(&password.Config{}))


    mux := http.NewServeMux()


    // Mount Auth to Router

    mux.Handle("/auth/", Auth.NewServeMux())

    http.ListenAndServe(":9000", manager.SessionManager.Middleware(mux))


}


查看完整回答
反對(duì) 回復(fù) 2022-09-12
?
瀟湘沐

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

問(wèn)題是沒(méi)有開(kāi)箱即用的支持。在教程中,他們忘記在導(dǎo)入中添加以下行:sqlite

_ "github.com/jinzhu/gorm/dialects/sqlite"


查看完整回答
反對(duì) 回復(fù) 2022-09-12
  • 3 回答
  • 0 關(guān)注
  • 121 瀏覽
慕課專(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)