Documentation
¶
Index ¶
- Constants
- func GenerateToken(role, secret string, expiry ...time.Duration) (string, error)
- func LimitBody(w http.ResponseWriter, body io.ReadCloser, max int64) io.ReadCloser
- func Middleware(cfg MiddlewareConfig, forceDBE bool, getDBName GetDatabaseNameFn) heligo.Middleware
- type Claims
- type GetDatabaseNameFn
- type MiddlewareConfig
- type Session
- type SessionList
- type SessionManager
- type SessionStatistics
Constants ¶
const DefaultMaxSessions = 10000
DefaultMaxSessions bounds the session map when no MaxSessions is configured
Variables ¶
This section is empty.
Functions ¶
func GenerateToken ¶
GenerateToken creates a signed JWT for the given role. If expiry > 0, the token will include exp and iat claims. If expiry == 0, the token has no expiration (for testing or long-lived tokens).
func LimitBody ¶ added in v0.8.3
func LimitBody(w http.ResponseWriter, body io.ReadCloser, max int64) io.ReadCloser
LimitBody caps the request body at max bytes. A non-positive max means unlimited, as RequestMaxBytes documents: MaxBytesReader(0) would instead fail on the first byte and block every request with a body.
func Middleware ¶
func Middleware(cfg MiddlewareConfig, forceDBE bool, getDBName GetDatabaseNameFn) heligo.Middleware
Types ¶
type Claims ¶
type Claims struct {
Role string `json:"role"`
Id string `json:"id"`
jwt.RegisteredClaims
RawClaims string `json:"-"`
}
func (*Claims) UnmarshalJSON ¶ added in v0.2.11
type MiddlewareConfig ¶
type Session ¶
type Session struct {
Claims *Claims
LastUsedAt time.Time
Db *database.Database
DbConn *database.DbPoolConn
// contains filtered or unexported fields
}
A Session for SmoothDB is the way to cache information about a user and his connection to a database
type SessionList ¶
type SessionList struct {
// contains filtered or unexported fields
}
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
SessionManager manages user sessions and monitors them efficiently. When disabled, it simply returns Sessions without managing or monitoring.
func NewSessionManager ¶
func NewSessionManager(logger *logging.Logger, enabled bool, shutdown chan struct{}) *SessionManager
func (*SessionManager) SetMaxSessions ¶ added in v0.8.3
func (sm *SessionManager) SetMaxSessions(n int)
SetMaxSessions bounds the number of stored sessions (non-positive: default)
func (*SessionManager) SetRetainConnections ¶ added in v0.8.3
func (sm *SessionManager) SetRetainConnections(retain bool)
SetRetainConnections selects between "role" mode (true: the prepared connection stays attached to the session between requests) and "claims" mode (false: only the verified claims are cached, the connection goes back to the pool at the end of every request).
func (*SessionManager) Statistics ¶
func (sm *SessionManager) Statistics() SessionStatistics