api

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RateLimitMiddleware

func RateLimitMiddleware(maxRequests int, window time.Duration) func(http.Handler) http.Handler

RateLimitMiddleware provides basic rate limiting

Types

type DB

type DB interface {
	LogRequest(ctx context.Context, log database.RequestLog) (int64, error)
	GetRecentRequests(ctx context.Context, limit int) ([]database.RequestLog, error)
	GetRequestsByType(ctx context.Context, agentType string, limit int) ([]database.RequestLog, error)
	GetStats(ctx context.Context) (*database.Stats, error)
	DeleteOldRequests(ctx context.Context, olderThan time.Duration) (int64, error)
}

DB interface for database operations

type ErrorResponse

type ErrorResponse struct {
	Success bool   `json:"success"`
	Error   string `json:"error"`
}

ErrorResponse represents an error response

type Handler

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

Handler handles HTTP requests

func NewHandler

func NewHandler(db DB) *Handler

NewHandler creates a new API handler

func (*Handler) GetAllDesktop

func (h *Handler) GetAllDesktop(w http.ResponseWriter, r *http.Request)

GetAllDesktop returns all desktop user agents

func (*Handler) GetAllMobile

func (h *Handler) GetAllMobile(w http.ResponseWriter, r *http.Request)

GetAllMobile returns all mobile user agents

func (*Handler) GetRandom

func (h *Handler) GetRandom(w http.ResponseWriter, r *http.Request)

GetRandom returns a random user agent (desktop or mobile)

func (*Handler) GetRandomDesktop

func (h *Handler) GetRandomDesktop(w http.ResponseWriter, r *http.Request)

GetRandomDesktop returns a random desktop user agent

func (*Handler) GetRandomMobile

func (h *Handler) GetRandomMobile(w http.ResponseWriter, r *http.Request)

GetRandomMobile returns a random mobile user agent

func (*Handler) GetRecentRequests

func (h *Handler) GetRecentRequests(w http.ResponseWriter, r *http.Request)

GetRecentRequests returns recent request logs

func (*Handler) GetStats

func (h *Handler) GetStats(w http.ResponseWriter, r *http.Request)

GetStats returns aggregated statistics

func (*Handler) Health

func (h *Handler) Health(w http.ResponseWriter, r *http.Request)

Health returns the health status of the service

type Response

type Response struct {
	Success bool        `json:"success"`
	Data    interface{} `json:"data,omitempty"`
	Error   string      `json:"error,omitempty"`
}

Response represents a standard API response

Jump to

Keyboard shortcuts

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