Package that will be used across Unaxiom to generate and maintain sessions.
Package has been rewritten using a faster in-memory DB. PostgreSQL is no longer required. This version is incompatible with v1.
go get -u github.com/Unaxiom/sessions
- github.com/tidwall/buntdb (for using BuntDB as the backend store)
- github.com/twinj/uuid
- github.com/go-redis/redis (for using Redis as the backend store)
import (
"github.com/Unaxiom/sessions"
)
sessionExpiryTime := int64(86400)
dbFolder, _ := os.Getwd()
sessionObject, err := Init("name_of_session", false, sessionExpiryTime, dbFolder)
sessionData, err := sessionObject.NewSession("somekeyhere", "userIPAddress")
fmt.Println("Auth Token is ", sessionData.Token)
// Check the status of the token. An error is returned in case the token does not exist. Returns nil otherwise.
_, err = sessionObject.CheckStatus(sessionData.Token)
// To delete a token
sessionObject.DeleteSession(sessionData.Token)
// For using Redis as the backend store
shortRedisDBSession, err := InitRedis("", "", 0, sessionExpiryTime)