Feutures:
Built-in backends to store sessions locally:
Simple Sample code the uses the default storeMap backend:
package main
import(
"bitbucket.org/gotamer/net/session"
"fmt"
)
func main(){
id := save()
load(id)
}
func save() string {
sess := session.New()
sess.Set("Alias","GoTamer")
err := sess.Save()
Check(err)
fmt.Println("Session Saved", sess)
sid, err := sess.Id()
Check(err)
return sid
}
func load(sid string){
sess, err := session.Load(sid)
Check(err)
fmt.Println("Session Load: ", sess)
}
Sample code the uses the leveldb backend:
package main
import(
"bitbucket.org/gotamer/net/session"
"fmt"
)
var path = "/tmp/sessions"
func init(){
session.StoreLeveldb(path)
}
func main(){
id := save()
load(id)
}
func save() string {
sess := session.New()
sess.Set("Alias","GoTamer")
err := sess.Save()
Check(err)
fmt.Println("Session Saved", sess)
sid, err := sess.Id()
Check(err)
return sid
}
func load(sid string){
sess, err := session.Load(sid)
Check(err)
fmt.Println("Session Load: ", sess)
}
Additional backends can be created by simply implementing following interfaces:
type Store interface {
Save(session *sessionObject) (err error)
Load(sid string) (session *sessionObject, err error)
Delete(sid string) (err error)
}
Some code has been borrowed from http://www.stathat.com/src/bingo witch is licensed also under MIT.
Code is available at https://bitbucket.org/gotamer