Documentation ¶
Overview ¶
Package mysql for session provider
depends on github.com/go-sql-driver/mysql:
go install github.com/go-sql-driver/mysql
mysql session support need create table as sql:
CREATE TABLE `session` ( `session_key` char(64) NOT NULL, `session_data` blob, `session_expiry` int(11) unsigned NOT NULL, PRIMARY KEY (`session_key`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Usage: import(
_ "github.com/beego/beego/v2/server/web/session/mysql" "github.com/beego/beego/v2/server/web/session"
)
func init() { globalSessions, _ = session.NewManager("mysql", ``{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...¶mN=valueN]"}``) go globalSessions.GC() }
Index ¶
- Variables
- type Provider
- func (mp *Provider) SessionAll(context.Context) int
- func (mp *Provider) SessionDestroy(ctx context.Context, sid string) error
- func (mp *Provider) SessionExist(ctx context.Context, sid string) (bool, error)
- func (mp *Provider) SessionGC(context.Context)
- func (mp *Provider) SessionInit(ctx context.Context, maxlifetime int64, savePath string) error
- func (mp *Provider) SessionRead(ctx context.Context, sid string) (session.Store, error)
- func (mp *Provider) SessionRegenerate(ctx context.Context, oldsid, sid string) (session.Store, error)
- type SessionStore
- func (st *SessionStore) Delete(ctx context.Context, key interface{}) error
- func (st *SessionStore) Flush(context.Context) error
- func (st *SessionStore) Get(ctx context.Context, key interface{}) interface{}
- func (st *SessionStore) SessionID(context.Context) string
- func (st *SessionStore) SessionRelease(ctx context.Context, w http.ResponseWriter)
- func (st *SessionStore) Set(ctx context.Context, key, value interface{}) error
Constants ¶
This section is empty.
Variables ¶
var (
// TableName store the session in MySQL
TableName = "session"
)
Functions ¶
This section is empty.
Types ¶
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider mysql session provider
func (*Provider) SessionAll ¶
SessionAll count values in mysql session
func (*Provider) SessionDestroy ¶
SessionDestroy delete mysql session by sid
func (*Provider) SessionExist ¶
SessionExist check mysql session exist
func (*Provider) SessionInit ¶
SessionInit init mysql session. savepath is the connection string of mysql.
func (*Provider) SessionRead ¶
SessionRead get mysql session by sid
type SessionStore ¶
type SessionStore struct {
// contains filtered or unexported fields
}
SessionStore mysql session store
func (*SessionStore) Delete ¶
func (st *SessionStore) Delete(ctx context.Context, key interface{}) error
Delete value in mysql session
func (*SessionStore) Flush ¶
func (st *SessionStore) Flush(context.Context) error
Flush clear all values in mysql session
func (*SessionStore) Get ¶
func (st *SessionStore) Get(ctx context.Context, key interface{}) interface{}
Get value from mysql session
func (*SessionStore) SessionID ¶
func (st *SessionStore) SessionID(context.Context) string
SessionID get session id of this mysql session store
func (*SessionStore) SessionRelease ¶
func (st *SessionStore) SessionRelease(ctx context.Context, w http.ResponseWriter)
SessionRelease save mysql session values to database. must call this method to save values to database.