By default, flash will be only used for the next coming response corresponding to the session, but functions Success, Error, Info and Warning are all accept a second argument to indicate whether output flash in current response or not.
// ...f.Success("yes!!!", true)f.Error("opps...", true)f.Info("aha?!", true)f.Warning("Just be careful.", true)// ...
But remember, flash can only be used once no matter which way you use.
Options
session.Sessioner comes with a variety of configuration options(session.Options):
//...m.Use(session.Sessioner(session.Options{// Name of provider. Default is "memory". Provider: "memory",// Provider configuration, it's corresponding to provider. ProviderConfig: "",// Cookie name to save session ID. Default is "MacaronSession". CookieName: "MacaronSession",// Cookie path to store. Default is "/". CookiePath: "/",// GC interval time in seconds. Default is 3600. Gclifetime: 3600,// Max life time in seconds. Default is whatever GC interval time is. Maxlifetime: 3600,// Use HTTPS only. Default is false. Secure: false,// Cookie life time. Default is 0. CookieLifeTime: 0,// Cookie domain name. Default is empty. Domain: "",// Session ID length. Default is 16. IDLength: 16,// Configuration section name. Default is "session". Section: "session",}))//...
Providers
There are 9 built-in implementations of session provider, you have to import provider driver explicitly except for memory and file providers.
Following are some basic usage examples for providers.
In case you need to have your own implementation of session storage and provider, you can implement following two interfaces and take memory provider as a study example.
// RawStore is the interface that operates the session data.typeRawStoreinterface {// Set sets value to given key in session.Set(key, value interface{}) error// Get gets value by given key in session.Get(key interface{}) interface{}// Delete deletes a key from session.Delete(key interface{}) error// ID returns current session ID.ID() string// Release releases session resource and save data to provider.Release() error// Flush deletes all session data.Flush() error}// Provider is the interface that provides session manipulations.typeProviderinterface {// Init initializes session provider.Init(gclifetime int64, config string) error// Read returns raw session store by session ID.Read(sid string) (RawStore, error)// Exist returns true if session with given ID exists.Exist(sid string) bool// Destory deletes a session by session ID.Destory(sid string) error// Regenerate regenerates a session store from old session ID to new one.Regenerate(oldsid, sid string) (RawStore, error)// Count counts and returns number of sessions.Count() int// GC calls GC to clean expired sessions.GC()}