middleware

package
v0.0.0-...-74adf86 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const RequestIDKey contextKey = "request_id"
View Source
const (
	// UserContextKey is the key for storing user info in context
	UserContextKey contextKey = "user"
)

Variables

This section is empty.

Functions

func CORSMiddleware

func CORSMiddleware(next http.Handler) http.Handler

CORSMiddleware adds CORS headers to responses

func GetRequestID

func GetRequestID(ctx context.Context) string

GetRequestID retrieves the request ID from context

func HashPassword

func HashPassword(password string) (string, error)

HashPassword generates a bcrypt hash from a plain text password This is a utility function for generating password hashes

func RequestIDMiddleware

func RequestIDMiddleware(next http.Handler) http.Handler

RequestIDMiddleware adds a unique request ID to each request

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

type User

type User struct {
	Username string
	IsAdmin  bool
}

User represents an authenticated user

func GetUserFromContext

func GetUserFromContext(ctx context.Context) (*User, bool)

GetUserFromContext retrieves the user from the request context

Jump to

Keyboard shortcuts

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