common

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAuthenticatedUser

func GetAuthenticatedUser(ctx context.Context) (*user.User, bool)

func ParseLimit

func ParseLimit(limitStr string, defaultLimit, maxLimit int) int

ParseLimit parses and validates limit parameter

func ParseOffset

func ParseOffset(offsetStr string) int

ParseOffset parses and validates offset parameter

func RequirePermission

func RequirePermission(userService user.Service, resourceType, action string) func(http.HandlerFunc) http.HandlerFunc

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 WithAuth

func WithAuth(userService user.Service, authService auth.Service) func(http.HandlerFunc) http.HandlerFunc

WithAuth middleware handles both API key and JWT authentication

Types

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 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 TimeRange

type TimeRange struct {
	Start time.Time `json:"start"`
	End   time.Time `json:"end"`
}

TimeRange represents a time-based filter range

type ValidationError

type ValidationError struct {
	Field   string `json:"field"`
	Message string `json:"message"`
}

ValidationError represents a field validation error

Jump to

Keyboard shortcuts

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