handlers

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

handlers/generic.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handle

func Handle[T any, R any](handlerFunc HandlerFunc[T, R], opts HandlerOptions) http.HandlerFunc

Handle creates a generic HTTP handler that processes requests of type T and returns responses of type R

Types

type CacheStats

type CacheStats struct {
	Hits             uint64    `json:"hits"`
	Misses           uint64    `json:"misses"`
	CurrentSize      int64     `json:"current_size_bytes"`
	MaxSize          int64     `json:"max_size_bytes"`
	EntryCount       int       `json:"entry_count"`
	LastCleanupTime  time.Time `json:"last_cleanup_time"`
	TotalRequests    uint64    `json:"total_requests"`
	CacheHitRatio    float64   `json:"cache_hit_ratio"`
	AvgResponseTime  float64   `json:"avg_response_time_ms"`
	CompressionRatio float64   `json:"compression_ratio"`
}

type DeleteObjectRequest

type DeleteObjectRequest struct{}

type ErrorResponse

type ErrorResponse struct {
	Error   string `json:"error"`
	Code    int    `json:"code"`
	Message string `json:"message"`
}

ErrorResponse represents a standard error response

type GetObjectRequest

type GetObjectRequest struct {
	AcceptGzip bool
}

Object request/response types

type GetObjectResponse

type GetObjectResponse struct {
	Data        []byte
	ContentType string
	Size        int64
	ETag        string
}

type HandlerFunc

type HandlerFunc[T any, R any] func(context.Context, *Request, T) (R, error)

HandlerFunc is the generic handler function type

type HandlerOptions

type HandlerOptions struct {
	Logger        *slog.Logger
	DecodeBody    bool
	ValidateInput func(interface{}) error
}

HandlerOptions contains configuration for the handler

type HeadObjectRequest

type HeadObjectRequest struct{}

type HealthHandler

type HealthHandler struct {
	// contains filtered or unexported fields
}

func NewHealthHandler

func NewHealthHandler(logger *slog.Logger) *HealthHandler

func (*HealthHandler) ServeHTTP

func (h *HealthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type NotFoundError

type NotFoundError struct {
	Resource string
	ID       string
}

Custom error types

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type ObjectHandler

type ObjectHandler struct {
	// contains filtered or unexported fields
}

ObjectHandler handles object storage operations

func NewObjectHandler

func NewObjectHandler(client *minio.Client, logger *slog.Logger) (*ObjectHandler, error)

func (*ObjectHandler) RegisterRoutes

func (h *ObjectHandler) RegisterRoutes(mux *http.ServeMux)

func (*ObjectHandler) ServeHTTP

func (h *ObjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ObjectResponse

type ObjectResponse struct {
	Data            []byte
	ContentType     string
	ContentEncoding string
	Size            int64
	LastModified    time.Time
	ETag            string
}

type PutObjectRequest

type PutObjectRequest struct {
	ContentType     string
	ContentEncoding string
	Data            []byte
}

type Request

type Request struct {
	Method      string
	PathParams  map[string]string
	QueryParams map[string]string
	Headers     http.Header
	Body        []byte
}

Request represents the base request structure

type Response

type Response struct {
	StatusCode  int
	Headers     http.Header
	Body        interface{}
	ContentType string
}

Response represents the base response structure

type StatsHandler

type StatsHandler struct {
	// contains filtered or unexported fields
}

func NewStatsHandler

func NewStatsHandler() *StatsHandler

func (*StatsHandler) RecordHit

func (h *StatsHandler) RecordHit()

func (*StatsHandler) RecordMiss

func (h *StatsHandler) RecordMiss()

func (*StatsHandler) ServeHTTP

func (h *StatsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*StatsHandler) UpdateSize

func (h *StatsHandler) UpdateSize(size int64)

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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