亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

使用 beego 驗證碼:無效的內存地址或 nil 指針取消引用

使用 beego 驗證碼:無效的內存地址或 nil 指針取消引用

Go
偶然的你 2023-05-08 16:05:38
我想在beego下使用captcha生成驗證碼。但是它有錯誤invalid memory address or nil pointer dereference。有誰知道如何解決這個問題?謝謝。Request Method: GETRequest URL:    /accounts/forgotpasswordRemoteAddr: 127.0.0.1StackC:/Go/src/runtime/asm_amd64.s:573C:/Go/src/runtime/panic.go:505C:/Go/src/text/template/exec.go:137C:/Go/src/runtime/asm_amd64.s:573C:/Go/src/runtime/panic.go:505C:/Go/src/runtime/panic.go:63我的代碼: conf\app.conf# Cache ProviderCacheProvider = redisCacheConnection = {"conn":"127.0.0.1:6379"}控制器\main.gopackage controllersimport ("github.com/astaxie/beego""github.com/astaxie/beego/cache"  "github.com/astaxie/beego/utils/captcha")var(    cpt *captcha.Captcha    CacheProvider string = beego.AppConfig.String("CacheProvider")    CacheConnection string = beego.AppConfig.String("CacheConnection"))func init() {  store, _ := cache.NewCache(CacheProvider, CacheConnection)  cpt = captcha.NewWithFilter("/accounts/captca/", store)}視圖\忘記密碼控制器\get.tpl<div class="w3-container w3-center">      <form method="post" id="mainForm"class="w3-container" style="margin-top:90px">        <div class="w3-card " style="    padding-left: 0px;        padding-right: 0px;    margin-top: 30px;">            <div class="w3-container">                <h1>Reset password</h1>            </div><div class="w3-container" style="    padding-bottom: 16px;">            {{create_captcha}}                <input type="text"  class="w3-input   "name="captcha"style="outline: none;">            <p style="text-align: left;margin-top: 0px;color:red">            {{if .Errors.Captcha}}                {{.Errors.Captcha}}{{else}}&zwnj;{{end}}</p>                <input type="submit" value="Request reset password" onclick="login()" class="w3-button w3-indigo w3-block w3-round-large">            </div>        </div>      </form>  </div>
查看完整描述

1 回答

?
拉風的咖菲貓

TA貢獻1995條經驗 獲得超2個贊

剛剛在我的本地測試了你的代碼。錯誤來自緩存創建部分。


store, err := cache.NewCache(CacheProvider, CacheConnection)

if err != nil {

    log.Fatal(err.Error())

    os.Exit(0)

}

要獲取詳細錯誤,請檢查err從 返回的變量cache.NewCache()。此外,最好始終記錄來自錯誤對象的任何可能錯誤,不要忽略它。


這是錯誤日志:


2018/11/14 11:13:24 緩存:未知適配器名稱“redis”(忘記導入?)


發生上述錯誤是因為緩存包找不到redis適配器。那是因為你還沒有導入包。因此,讓我們嘗試導入它,然后您的問題將得到解決。


import (

    "fmt"

    "log"

    "os"

    "github.com/astaxie/beego"

    "github.com/astaxie/beego/cache"

    "github.com/astaxie/beego/utils/captcha"


    _ "github.com/astaxie/beego/cache/redis" // <----- this one

)

由于我們不直接與緩存 redis 包交互,因此使用_.


查看完整回答
反對 回復 2023-05-08
  • 1 回答
  • 0 關注
  • 187 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號