Documentation ¶
Index ¶
- func AddTime(t time.Time, duration time.Duration) time.Time
- func Base64Decode(s string) string
- func Base64Encode(s string) string
- func GetSingleton[T any]() (t *T)
- func RandStringN(n int) string
- func URLDecode(s string) string
- func URLEncode(s string) string
- type AuthUser
- type Session
- func (s *Session) Authenticate(username, password string) (*SystemUser, bool)
- func (s *Session) Del(k any)
- func (s *Session) ExpiresIn() int64
- func (s *Session) Get(k any) (any, bool)
- func (s *Session) GetUser() (*SystemUser, bool)
- func (s *Session) Has(k any) bool
- func (s *Session) ID() string
- func (s *Session) Register(username, password, role string)
- func (s *Session) Set(k, v any)
- type SessionID
- type SessionManager
- type SessionStore
- type SessionStoreConfig
- type SessionStoreT
- type SessionT
- type SystemUser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Base64Decode ¶
Base64Decode takes a base64 encoded string and returns a plaintext string
func Base64Encode ¶
Base64Encode takes a plaintext string and returns a base64 encoded string
func GetSingleton ¶
func GetSingleton[T any]() (t *T)
func RandStringN ¶
RandStringN creates a random string N characters in length
Types ¶
type AuthUser ¶
type AuthUser interface { Register(username, password, role string) Authenticate(username, password string) (*SystemUser, bool) }
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func (*Session) Authenticate ¶
func (s *Session) Authenticate(username, password string) (*SystemUser, bool)
func (*Session) GetUser ¶
func (s *Session) GetUser() (*SystemUser, bool)
type SessionManager ¶
type SessionManager interface { // New should create and return a new session New() *Session // Get should return a cached session Get(r *http.Request) (*Session, bool) // Save should persist session to the underlying store // implementation. Passing a nil session erases it. Save(w http.ResponseWriter, r *http.Request, s *Session) }
type SessionStore ¶
type SessionStore struct { *SessionStoreConfig // contains filtered or unexported fields }
SessionStore implements the session manager interface and is a basic session manager using cookies.
var SessionStoreInstance *SessionStore
func NewSessionStore ¶
func NewSessionStore(conf *SessionStoreConfig) *SessionStore
NewSessionStore takes a *SessionStoreConfig. It initializes and returns a *SessionStore. The sid (provided in the config) will be used as the key for all session cookies, and the timeout (provided in the config) is the maximum allowable idle session time before the session is expired. This function uses sync.Once to ensure that only one *SessionStore is alive. You may call NewSessionStore() multiple times throughout your application and the same instance will be returned.
func (*SessionStore) Get ¶
func (ss *SessionStore) Get(r *http.Request) (*Session, bool)
Get returns a cached session (if one exists)
func (*SessionStore) MustGet ¶
func (ss *SessionStore) MustGet(r *http.Request) (*Session, bool)
MustGet returns a cached session (if one exists), otherwise, it creates and returns a new session. It is guaranteed to return a session.
func (*SessionStore) New ¶
func (ss *SessionStore) New() *Session
New creates and returns a new session
func (*SessionStore) Save ¶
func (ss *SessionStore) Save(w http.ResponseWriter, r *http.Request, session *Session)
Save persists the provided session. If you would like to remove a session, simply pass it a nil session, and it will time the cookie out.
func (*SessionStore) String ¶
func (ss *SessionStore) String() string
String is the session store's stringer method
type SessionStoreConfig ¶
type SessionStoreConfig struct { SessionID string `json:"session_id"` // SessionID is the global session id Domain string `json:"domain"` // Domain is the domain to limit the session scope Timeout time.Duration `json:"timeout_duration"` // Timeout is the max idle session time allowed }
SessionStoreConfig is a configuration object for a session manager
type SessionStoreT ¶
type SessionStoreT struct {
// contains filtered or unexported fields
}
var DefaultSessionStore *SessionStoreT
func NewSessionStoreManager ¶
func NewSessionStoreManager(key string, timeout time.Duration) *SessionStoreT
func (*SessionStoreT) Close ¶
func (ss *SessionStoreT) Close()
func (*SessionStoreT) GetSession ¶
func (ss *SessionStoreT) GetSession(sid SessionID) (*SessionT, bool)
GetSession takes a SessionID and attempts to locate the matching *Session. If a matching *Session can be found it is returned along with a boolean indicating weather or not the session was found.
func (*SessionStoreT) GetSessionCount ¶
func (ss *SessionStoreT) GetSessionCount() int
func (*SessionStoreT) NewSession ¶
func (ss *SessionStoreT) NewSession() *SessionT
func (*SessionStoreT) SaveSession ¶
func (ss *SessionStoreT) SaveSession(session *SessionT)