web

package
v0.0.0-...-6697815 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2023 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTime

func AddTime(t time.Time, duration time.Duration) time.Time

func Base64Decode

func Base64Decode(s string) string

Base64Decode takes a base64 encoded string and returns a plaintext string

func Base64Encode

func Base64Encode(s string) string

Base64Encode takes a plaintext string and returns a base64 encoded string

func GetSingleton

func GetSingleton[T any]() (t *T)

func RandStringN

func RandStringN(n int) string

RandStringN creates a random string N characters in length

func URLDecode

func URLDecode(s string) string

URLDecode takes a URL encoded string and returns a plaintext string

func URLEncode

func URLEncode(s string) string

URLEncode takes a plaintext string and returns a URL encoded string

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

func (s *Session) Del(k any)

func (*Session) ExpiresIn

func (s *Session) ExpiresIn() int64

func (*Session) Get

func (s *Session) Get(k any) (any, bool)

func (*Session) GetUser

func (s *Session) GetUser() (*SystemUser, bool)

func (*Session) Has

func (s *Session) Has(k any) bool

func (*Session) ID

func (s *Session) ID() string

func (*Session) Register

func (s *Session) Register(username, password, role string)

func (*Session) Set

func (s *Session) Set(k, v any)

type SessionID

type SessionID [32]byte

func MakeSessionID

func MakeSessionID() SessionID

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)

type SessionT

type SessionT struct {
	// contains filtered or unexported fields
}

func (*SessionT) Del

func (s *SessionT) Del(k string)

func (*SessionT) ExpiresIn

func (s *SessionT) ExpiresIn() time.Duration

func (*SessionT) Get

func (s *SessionT) Get(k string) (string, bool)

func (*SessionT) ID

func (s *SessionT) ID() SessionID

func (*SessionT) IsExpired

func (s *SessionT) IsExpired() bool

func (*SessionT) Set

func (s *SessionT) Set(k, v string)

type SystemUser

type SystemUser struct {
	Username string `json:"username"`
	Password string `json:"password"`
	Role     string `json:"role"`
}

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL