Documentation
¶
Index ¶
- Variables
- func CountActive(db *sql.DB) (map[models.Role]int, error)
- func Create(role models.Role, name string, db *sql.DB, root string) (*models.Session, error)
- func CreateSystem(role models.Role, db *sql.DB) (*models.Session, error)
- func End(root string, db *sql.DB) (sessionID string, err error)
- func ExpireByID(id string, db *sql.DB) error
- func GenerateName(name string) string
- func GenerateULID() string
- func LoadActive(root string, db *sql.DB) (*models.Session, error)
- func ValidateName(name string) error
Constants ¶
This section is empty.
Variables ¶
var ErrExpiredSession = errors.New("session has expired")
ErrExpiredSession is returned by LoadActive when the session's expired_at is set. This is a distinct sentinel from ErrNoSession — both appear in logs and must be distinguishable by humans and by errors.Is callers.
var ErrNoSession = errors.New("no active session")
ErrNoSession is returned by LoadActive when the .tkt/session file is absent.
Functions ¶
func CountActive ¶
CountActive returns count of non-expired sessions broken down by base role. Keys are models.RoleArchitect and models.RoleImplementer. Roles not present in the result had zero active sessions.
func Create ¶
Create generates a new ULID, inserts a row into the sessions table, and writes the bare session ULID to the .tkt/session file.
name is the user-supplied session name (may be empty for random word). If non-empty, it must already have been validated by ValidateName.
func CreateSystem ¶
CreateSystem inserts a DB-only session row for a built-in system role (e.g. monitor) WITHOUT writing to the .tkt/session file. Used by tkt monitor to own its own session without displacing any user session.
func End ¶
End marks the current active session as expired by setting expired_at = NOW(). Reads the session ID from the .tkt/session file. Returns ErrNoSession when no session file exists or the file is empty. Calling End on an already-expired session is idempotent — it simply updates expired_at again.
func ExpireByID ¶
ExpireByID sets expired_at = datetime('now') for the session with the given ID. Returns nil if no row matched (idempotent).
func GenerateName ¶ added in v0.2.0
GenerateName returns a user-supplied session name or a random word.
func GenerateULID ¶ added in v0.2.0
func GenerateULID() string
GenerateULID returns a new session ID.
func LoadActive ¶
LoadActive reads the active session from the .tkt/session file, looks it up in the DB, updates last_active, and returns the Session.
- Returns ErrNoSession when the session file does not exist.
- Returns ErrExpiredSession when expired_at is set on the session row.
- Returns a wrapped error (not ErrNoSession) when the file exists but the row is gone.
func ValidateName ¶
ValidateName checks that a user-supplied session name conforms to the naming rules:
- Lowercase alphanumeric + hyphens only
- No leading or trailing hyphen
- No consecutive hyphens
- At least 1 character, at most 32 characters
Returns a descriptive error if the name is invalid, nil otherwise.
Types ¶
This section is empty.