Documentation
¶
Index ¶
- Constants
- Variables
- func ForceDelete(sessionID string)
- func GetUserAddr(r *http.Request) string
- func Middleware(serviceConfMode string) rest.Middleware
- func SetToken(w http.ResponseWriter, cookie *http.Cookie)
- func Setup(c SessionConfig, store *redis.Redis)
- func Token(r *http.Request, name string) (*http.Cookie, error)
- type Session
- func (s Session) AddFlash(value interface{}, vars ...string)
- func (s Session) Authenticated() bool
- func (s Session) Clear(r *http.Request, w http.ResponseWriter)
- func (s Session) CreatedAt() time.Time
- func (s Session) Del(key string)
- func (s Session) Flashes(vars ...string) []interface{}
- func (s Session) Get(key string) any
- func (s Session) GetInt(key string) int64
- func (s Session) GetStr(key string) string
- func (s Session) ID() string
- func (s Session) Set(key string, value any)
- func (s Session) UpdatedAt() time.Time
- type SessionConfig
Constants ¶
View Source
const ( // Is the session authenticated: 0: no; 1: yes Authenticated = "authenticated" // The user's ID UserID = "user_id" // The user's name Username = "username" // The user's type: admin|<nil> UserType = "user_type" // The time when the session is created Created = "created" // The time when the session is last updated Updated = "updated" // The path where the session is last updated Path = "path" // User-Agent request header UserAgent = "user_agent" // The user's IP address UserIPAddr = "user_ipaddr" )
These are transient session keys
Variables ¶
View Source
var ErrNoToken = errors.New("http: named token not present")
Functions ¶
func ForceDelete ¶
func ForceDelete(sessionID string)
Forcely delete a session if we know its ID. Note that it only deletes the session at server side while client could initiate a session with a same ID, which he remembered in the past. ForceDelete is usually used to forbid a session programmly, maybe upon the user's password change.
func GetUserAddr ¶
GetUserAddr from the http request, considering X-Forwarded-For, Forwarded
func Middleware ¶
func Middleware(serviceConfMode string) rest.Middleware
func SetToken ¶
func SetToken(w http.ResponseWriter, cookie *http.Cookie)
SetToken adds a Set-Session-Token header to the provided [ResponseWriter]'s headers. The provided cookie must have a valid Name. Invalid cookies may be silently dropped.
func Setup ¶
func Setup(c SessionConfig, store *redis.Redis)
Types ¶
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func (Session) Authenticated ¶
type SessionConfig ¶
type SessionConfig struct { SessionSecret string // used to authenticate session cookies using HMAC SessionStorageNamespace string `json:",default=sessions"` SessionCookieName string `json:",default=SID"` SessionCookiePath string `json:",default=/"` SessionCookieDomain string `json:",optional"` // The duration in seconds that the session cookie/token is valid, // and also how long users stay logged-in to the App. SessionCookieTTL int `json:",default=600,range=[60:]"` SessionCookieSameSite string `json:",default=Lax,options=Strict|Lax|None"` SessionCookieSecure bool `json:",default=false"` // The session storage TTL is derived from its max age plus this grace period. SessionStorageGracePeriod int `json:",default=10,range=[1:60]"` SessionStorageUnauthenticatedTTL int `json:",default=60,range=[0:600]"` SessionStorageInjectedAuthenticationTTL int `json:",default=0,range=[0:60]"` }
Click to show internal directories.
Click to hide internal directories.