beego: Index | Files

package mysql

import ""

Package mysql for session provider

depends on

go install

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`)

Usage: import(

_ ""


func init() {
	globalSessions, _ = session.NewManager("mysql", ``{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...&paramN=valueN]"}``)
	go globalSessions.GC()

more docs:


Package Files



var (
    // TableName store the session in MySQL
    TableName = "session"

type Provider Uses

type Provider struct {
    // contains filtered or unexported fields

Provider mysql session provider

func (*Provider) SessionAll Uses

func (mp *Provider) SessionAll(context.Context) int

SessionAll count values in mysql session

func (*Provider) SessionDestroy Uses

func (mp *Provider) SessionDestroy(ctx context.Context, sid string) error

SessionDestroy delete mysql session by sid

func (*Provider) SessionExist Uses

func (mp *Provider) SessionExist(ctx context.Context, sid string) (bool, error)

SessionExist check mysql session exist

func (*Provider) SessionGC Uses

func (mp *Provider) SessionGC(context.Context)

SessionGC delete expired values in mysql session

func (*Provider) SessionInit Uses

func (mp *Provider) SessionInit(ctx context.Context, maxlifetime int64, savePath string) error

SessionInit init mysql session. savepath is the connection string of mysql.

func (*Provider) SessionRead Uses

func (mp *Provider) SessionRead(ctx context.Context, sid string) (session.Store, error)

SessionRead get mysql session by sid

func (*Provider) SessionRegenerate Uses

func (mp *Provider) SessionRegenerate(ctx context.Context, oldsid, sid string) (session.Store, error)

SessionRegenerate generate new sid for mysql session

type SessionStore Uses

type SessionStore struct {
    // contains filtered or unexported fields

SessionStore mysql session store

func (*SessionStore) Delete Uses

func (st *SessionStore) Delete(ctx context.Context, key interface{}) error

Delete value in mysql session

func (*SessionStore) Flush Uses

func (st *SessionStore) Flush(context.Context) error

Flush clear all values in mysql session

func (*SessionStore) Get Uses

func (st *SessionStore) Get(ctx context.Context, key interface{}) interface{}

Get value from mysql session

func (*SessionStore) SessionID Uses

func (st *SessionStore) SessionID(context.Context) string

SessionID get session id of this mysql session store

func (*SessionStore) SessionRelease Uses

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.

func (*SessionStore) Set Uses

func (st *SessionStore) Set(ctx context.Context, key, value interface{}) error

Set value in mysql session. it is temp value in map.

Package mysql imports 7 packages (graph) and is imported by 1 packages. Updated 2020-11-07. Refresh now. Tools for package owners.