This is a package of sessions middleware for Echo.
A thin gorilla/sessions wrapper.
$ go get -u github.com/utahta/echo-sessions
import (
"github.com/boj/redistore"
"github.com/utahta/echo-sessions"
"github.com/labstack/echo"
)
store, _ := redistore.NewRediStore(10, "tcp", ":6379", "", []byte("secret-key"))
e := echo.New()
e.Use(sessions.Sessions("SESSID", store))
import "github.com/utahta/echo-sessions"
func example(c echo.Context) {
sessions.Set(c, "key", "value")
dst := sessions.GetRaw(c, "key")
var dst string
ok, err := sessions.Get(c, "key", &dst)
var dst string
ok := sessions.MustGet(c, "key", &dst)
sessions.Delete(c, "key")
ok := sessions.Exists(c, "key")
sessions.Clear(c)
sessions.Flashes(c vars...)
sessions.AddFlash(c, value, vars...)
err := sessions.Save(c)
}
s := sessions.MustStart()
s.Set("key", "value")
var v string
ok, err := s.Get("key", &v)
or
var v string
ok := s.MustGet("key", &v)
v := s.GetRaw("key") // returns (interface{})
if !s.Exists("key") {
s.Set("key", "new value")
}
or
var v string
if ok, err := s.Get("example1", &v); !ok && err == nil {
s.Set("example1", "new value")
}
if ok := s.MustGet("example2", &v); !ok {
s.Set("example2", "new value")
}
s.Delete("key")
err := s.Save()
- Fork it ( https://github.com/utahta/echo-sessions/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request