3

を使用してタイムアウトを設定してセッション変数を処理しています

globalSessions, _ = session.NewManager("memory", `{"cookieName":"gosessionid", "enableSetCookie,omitempty": true, "gclifetime":5, "maxLifetime": 5, "secure": false, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "cookieLifeTime": 3600, "providerConfig": ""}`)

go globalSessions.GC()

sess, _ := globalSessions.SessionStart(c.Ctx.ResponseWriter, c.Ctx.Request)

defer sess.SessionRelease(c.Ctx.ResponseWriter)

errU := sess.Set("user1", c.Input().Get("userName"))

if errU != nil {
    fmt.Println("error in settng value")
}

現在のページから時間切れになったときに特定のページにリダイレクトする方法。私はこのアプリケーションをビーゴに持っています

4

1 に答える 1

1

beegoPrepare()にはこれを行う方法があります。ドキュメントを参照してください

準備()

この関数は拡張に使用でき、以下のメソッドの前に実行されます。これを上書きして、ユーザー検証などの機能を実装できます。

コード

type MainController struct {
    beego.Controller
}

func (c *MainController) Prepare() { 
    if timeOut {
        c.Redirect("login.html", 302)
    }
}

func (c *MainController) Index() {
    c.TplNames = "index.tpl"
}
于 2015-08-01T08:19:42.877 に答える