Documentation
¶
Index ¶
- Constants
- func CORSMiddleware(next http.Handler) http.Handler
- func GetRequestID(ctx context.Context) string
- func HashPassword(password string) (string, error)
- func RequestIDMiddleware(next http.Handler) http.Handler
- type AuthMiddleware
- func (am *AuthMiddleware) GenerateSessionToken(username string, isAdmin bool) (string, error)
- func (am *AuthMiddleware) OptionalAuth(next http.Handler) http.Handler
- func (am *AuthMiddleware) RefreshSessionToken(token string) (string, error)
- func (am *AuthMiddleware) RequireAuth(next http.Handler) http.Handler
- func (am *AuthMiddleware) ValidateCredentials(username, password string) bool
- type User
Constants ¶
const RequestIDKey contextKey = "request_id"
const (
// UserContextKey is the key for storing user info in context
UserContextKey contextKey = "user"
)
Variables ¶
This section is empty.
Functions ¶
func CORSMiddleware ¶
CORSMiddleware adds CORS headers to responses
func GetRequestID ¶
GetRequestID retrieves the request ID from context
func HashPassword ¶
HashPassword generates a bcrypt hash from a plain text password This is a utility function for generating password hashes
Types ¶
type AuthMiddleware ¶
type AuthMiddleware struct {
// contains filtered or unexported fields
}
AuthMiddleware provides authentication functionality
func NewAuthMiddleware ¶
func NewAuthMiddleware() (*AuthMiddleware, error)
NewAuthMiddleware creates a new authentication middleware Expects ADMIN_USERNAME and ADMIN_PASSWORD_HASH environment variables
func (*AuthMiddleware) GenerateSessionToken ¶
func (am *AuthMiddleware) GenerateSessionToken(username string, isAdmin bool) (string, error)
GenerateSessionToken generates a JWT token for a user (used after successful login)
func (*AuthMiddleware) OptionalAuth ¶
func (am *AuthMiddleware) OptionalAuth(next http.Handler) http.Handler
OptionalAuth is a middleware that adds user to context if authenticated, but doesn't require it
func (*AuthMiddleware) RefreshSessionToken ¶
func (am *AuthMiddleware) RefreshSessionToken(token string) (string, error)
RefreshSessionToken refreshes an existing token
func (*AuthMiddleware) RequireAuth ¶
func (am *AuthMiddleware) RequireAuth(next http.Handler) http.Handler
RequireAuth is a middleware that requires authentication
func (*AuthMiddleware) ValidateCredentials ¶
func (am *AuthMiddleware) ValidateCredentials(username, password string) bool
ValidateCredentials checks if the provided username and password are valid