📝 Add docstrings to feat/go-rewrite
Docstrings generation was requested by @blakeridgway. * https://github.com/RideAware/admin-panel/pull/1#issuecomment-3528008426 The following files were modified: * `cmd/admin-panel/main.go` * `internal/config/config.go` * `internal/database/database.go` * `internal/email/email.go` * `internal/handlers/auth.go` * `internal/handlers/newsletter.go` * `internal/handlers/subscribers.go` * `internal/middleware/auth.go`
This commit is contained in:
committed by
GitHub
parent
899313dcac
commit
2adb7e3605
@@ -11,6 +11,9 @@ import (
|
||||
|
||||
var store *sessions.CookieStore
|
||||
|
||||
// Init initializes the package-level cookie store used for session management.
|
||||
// It panics if config.Current.SecretKey is empty.
|
||||
// The created store is configured with Path "/", MaxAge one week, HttpOnly true, Secure false, and SameSite 0.
|
||||
func Init() {
|
||||
if config.Current.SecretKey == "" {
|
||||
panic("SECRET_KEY not set")
|
||||
@@ -25,10 +28,16 @@ func Init() {
|
||||
}
|
||||
}
|
||||
|
||||
// GetStore returns the package-level Gorilla cookie store used for session management.
|
||||
// It may be nil if Init has not been called.
|
||||
func GetStore() *sessions.CookieStore {
|
||||
return store
|
||||
}
|
||||
|
||||
// Auth enforces session-based authentication for Gin handlers.
|
||||
// If the request has no session named "session" or the session lacks a "username" value,
|
||||
// the middleware redirects to "/login" (HTTP 302) and aborts further handling.
|
||||
// Otherwise the middleware calls the next handler in the chain.
|
||||
func Auth() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
session, err := store.Get(c.Request, "session")
|
||||
|
||||
Reference in New Issue
Block a user