modulepackage
3.0.1+incompatible
Repository: https://github.com/go-session/beego-session.git
Documentation: pkg.go.dev
# README
Session middleware for Beego
Quick Start
Download and install
$ go get -u -v github.com/go-session/beego-session
Create file server.go
package main
import (
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/context"
"github.com/go-session/beego-session"
"github.com/go-session/session"
)
func main() {
app := beego.NewApp()
app.Handlers.InsertFilter("*", beego.BeforeRouter, beegosession.New())
app.Handlers.Get("/", func(ctx *context.Context) {
store := beegosession.FromContext(ctx)
store.Set("foo", "bar")
err := store.Save()
if err != nil {
ctx.Abort(500, err.Error())
return
}
ctx.Redirect(302, "/foo")
})
app.Handlers.Get("/foo", func(ctx *context.Context) {
store := beegosession.FromContext(ctx)
foo, ok := store.Get("foo")
if !ok {
ctx.Abort(404, "not found")
return
}
ctx.WriteString(fmt.Sprintf("foo:%s", foo))
})
beego.BConfig.Listen.HTTPPort = 8080
app.Run()
}
Build and run
$ go build server.go
$ ./server
Open in your web browser
foo:bar
MIT License
Copyright (c) 2018 Lyric
# Functions
Destroy a session.
FromContext Get session storage from context.
New create a session middleware.
NewWithConfig create a session middleware.
Refresh a session and return to session storage.
# Variables
DefaultConfig is the default Recover middleware config.
# Type aliases
No description provided by the author