proxy

package
v0.1.22 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRateLimited   = errors.New("rate limit exceeded")
	ErrInvalidPath   = errors.New("invalid proxy path")
	ErrUpstreamError = errors.New("upstream error")
)

Functions

func CopyResponse

func CopyResponse(w http.ResponseWriter, resp *ProxyResponse) error

Types

type Proxy

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

func NewProxy

func NewProxy(whoopLimiter storage.WhoopRateLimiter, rateLimitCfg RateLimitConfig) *Proxy

func (*Proxy) CheckRateLimit

func (p *Proxy) CheckRateLimit(ctx context.Context, userID int64) (*RateLimitInfo, error)

func (*Proxy) ProxyRequest

func (p *Proxy) ProxyRequest(ctx context.Context, req *ProxyRequest) (*ProxyResponse, error)

type ProxyRequest

type ProxyRequest struct {
	Method  string
	Path    string
	Query   string
	Headers http.Header
	Body    io.ReadCloser
	UserID  int64
}

type ProxyResponse

type ProxyResponse struct {
	StatusCode int
	Headers    http.Header
	Body       io.ReadCloser
}

type RateLimitConfig

type RateLimitConfig struct {
	PerUserDayLimit   int
	GlobalMinuteLimit int
	GlobalDayLimit    int
}

type RateLimitInfo

type RateLimitInfo struct {
	RetryAfter time.Duration
	Reason     string
	Message    string
}

type Service

type Service interface {
	// CheckRateLimit checks if the user can make a request.
	// Returns nil if allowed.
	// Returns ErrRateLimited with RateLimitInfo if rate limited.
	CheckRateLimit(ctx context.Context, userID int64) (*RateLimitInfo, error)

	// ProxyRequest forwards a request to the WHOOP API.
	// Returns the upstream response.
	// Returns ErrInvalidPath if the path is malformed.
	// Returns ErrUpstreamError if the upstream request fails.
	// Caller is responsible for closing ProxyResponse.Body.
	ProxyRequest(ctx context.Context, req *ProxyRequest) (*ProxyResponse, error)
}

Jump to

Keyboard shortcuts

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