Help us shape the future of Go! Take the 2026 Go Developer Survey

auth

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSession

func CreateSession(gdb *gorm.DB, w http.ResponseWriter, userID uint, secure bool) error

CreateSession generates a random token, stores its SHA-256 hash in db.Session, sets an HTTP-only cookie named "golem_session", 7-day TTL. secure should be true when the server is running behind TLS.

func RequireAPIKey

func RequireAPIKey(gdb *gorm.DB) func(http.Handler) http.Handler

RequireAPIKey middleware: reads "X-Shem-Name" and "Authorization: Bearer <key>" headers, looks up the shem by name, verifies the key, and stores *db.Shem in the request context. Returns 401 on any failure.

func RequireSession

func RequireSession(gdb *gorm.DB) func(http.Handler) http.Handler

RequireSession middleware: reads "golem_session" cookie, SHA-256 hashes it, looks up db.Session (checking expires_at > now), loads db.User, stores *db.User in request context via sessionUserKey. Redirects to /login on any failure.

func SessionUser

func SessionUser(r *http.Request) *db.User

SessionUser extracts *db.User from context (set by RequireSession). Returns nil if not present.

func ShemFromRequest

func ShemFromRequest(r *http.Request) *db.Shem

ShemFromRequest extracts *db.Shem from context (set by RequireAPIKey). Returns nil if not present.

Types

This section is empty.

Jump to

Keyboard shortcuts

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