Documentation
¶
Index ¶
- func GetAnonymousUser(roleName string) *user.User
- func GetAuthenticatedUser(ctx context.Context) (*user.User, bool)
- func ParseLimit(limitStr string, defaultLimit, maxLimit int) int
- func ParseOffset(offsetStr string) int
- func RequirePermission(userService user.Service, resourceType, action string) func(http.HandlerFunc) http.HandlerFunc
- func RespondError(w http.ResponseWriter, status int, message string)
- func RespondJSON(w http.ResponseWriter, status int, data interface{})
- func WithAnonymousContext(ctx context.Context, role string) context.Context
- func WithAuth(userService user.Service, authService auth.Service, cfg *config.Config) func(http.HandlerFunc) http.HandlerFunc
- func WithRateLimit(cfg *config.Config, limit int, window int) func(http.HandlerFunc) http.HandlerFunc
- type AnonymousContext
- type ContextKey
- type ErrorResponse
- type Filter
- type RateLimitStore
- type Route
- type TimeRange
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAnonymousUser ¶ added in v0.2.0
GetAnonymousUser returns a singleton anonymous user with the specified role
func GetAuthenticatedUser ¶
GetAuthenticatedUser returns the current authenticated user
func ParseLimit ¶
ParseLimit parses and validates limit parameter
func ParseOffset ¶
ParseOffset parses and validates offset parameter
func RequirePermission ¶
func RequirePermission(userService user.Service, resourceType, action string) func(http.HandlerFunc) http.HandlerFunc
RequirePermission middleware checks if the user has required permissions
func RespondError ¶
func RespondError(w http.ResponseWriter, status int, message string)
RespondError sends a standard error response
func RespondJSON ¶
func RespondJSON(w http.ResponseWriter, status int, data interface{})
RespondJSON sends a JSON response with standard headers
func WithAnonymousContext ¶ added in v0.2.0
WithAnonymousContext adds anonymous context to the request context
func WithAuth ¶
func WithAuth(userService user.Service, authService auth.Service, cfg *config.Config) func(http.HandlerFunc) http.HandlerFunc
WithAuth middleware handles both API key and JWT authentication
func WithRateLimit ¶ added in v0.3.2
func WithRateLimit(cfg *config.Config, limit int, window int) func(http.HandlerFunc) http.HandlerFunc
WithRateLimit middleware enforces rate limiting per user/IP with per-endpoint limits
Types ¶
type AnonymousContext ¶ added in v0.2.0
type AnonymousContext struct {
RoleName string
}
AnonymousContext represents an authentication context for anonymous access
func GetAnonymousContext ¶ added in v0.2.0
func GetAnonymousContext(ctx context.Context) (AnonymousContext, bool)
GetAnonymousContext retrieves anonymous context from the request context
type ContextKey ¶
type ContextKey string
Context keys for storing authenticated user info
const (
UserContextKey ContextKey = "user"
)
type ErrorResponse ¶
type ErrorResponse struct {
Error string `json:"error"`
}
ErrorResponse represents an API error response
type Filter ¶
type Filter struct {
Limit int `json:"limit"`
Offset int `json:"offset"`
Sort []string `json:"sort,omitempty"`
}
Filter represents common query parameters for list operations
type RateLimitStore ¶ added in v0.3.2
type RateLimitStore struct {
// contains filtered or unexported fields
}
RateLimitStore manages rate limit counters in memory
func NewRateLimitStore ¶ added in v0.3.2
func NewRateLimitStore() *RateLimitStore
NewRateLimitStore creates a new in-memory rate limit store
type Route ¶
type Route struct {
Path string
Method string
Handler http.HandlerFunc
Middleware []func(http.HandlerFunc) http.HandlerFunc
}
Route represents a route for the HTTP server
type ValidationError ¶
ValidationError represents a field validation error