proxy

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetStatsPath added in v0.5.2

func GetStatsPath() (string, error)

GetStatsPath returns the stats file path

Types

type APIResponse

type APIResponse struct {
	Usage Usage `json:"usage"`
}

APIResponse represents the structure of API responses to extract usage

type DailyStats added in v1.4.0

type DailyStats struct {
	Date         string `json:"date"` // Format: "2006-01-02"
	Requests     int    `json:"requests"`
	Errors       int    `json:"errors"`
	InputTokens  int    `json:"inputTokens"`
	OutputTokens int    `json:"outputTokens"`
}

DailyStats represents statistics for a single day

type EndpointStats

type EndpointStats struct {
	Requests     int                    `json:"requests"`
	Errors       int                    `json:"errors"`
	InputTokens  int                    `json:"inputTokens"`
	OutputTokens int                    `json:"outputTokens"`
	LastUsed     time.Time              `json:"lastUsed"`
	DailyHistory map[string]*DailyStats `json:"dailyHistory,omitempty"` // Key: date string
}

EndpointStats represents statistics for a single endpoint

type Proxy

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

Proxy represents the proxy server

func New

func New(cfg *config.Config) *Proxy

New creates a new Proxy instance

func (*Proxy) GetCurrentEndpointName added in v1.1.1

func (p *Proxy) GetCurrentEndpointName() string

GetCurrentEndpointName returns the current endpoint name (thread-safe)

func (*Proxy) GetStats

func (p *Proxy) GetStats() *Stats

GetStats returns current statistics

func (*Proxy) SetCurrentEndpoint added in v1.1.1

func (p *Proxy) SetCurrentEndpoint(targetName string) error

SetCurrentEndpoint manually switches to a specific endpoint by name Returns error if endpoint not found or not enabled Thread-safe and won't affect ongoing requests

func (*Proxy) Start

func (p *Proxy) Start() error

Start starts the proxy server

func (*Proxy) Stop

func (p *Proxy) Stop() error

Stop stops the proxy server

func (*Proxy) UpdateConfig

func (p *Proxy) UpdateConfig(cfg *config.Config) error

UpdateConfig updates the proxy configuration

type SSEEvent

type SSEEvent struct {
	Event string
	Data  string
}

SSEEvent represents a Server-Sent Event

type Stats

type Stats struct {
	TotalRequests int                       `json:"totalRequests"`
	EndpointStats map[string]*EndpointStats `json:"endpointStats"`
	// contains filtered or unexported fields
}

Stats represents overall proxy statistics

func NewStats

func NewStats() *Stats

NewStats creates a new Stats instance

func (*Stats) CleanupOldData added in v1.4.0

func (s *Stats) CleanupOldData(daysToKeep int)

CleanupOldData removes data older than specified days

func (*Stats) GetDailyStats added in v1.4.0

func (s *Stats) GetDailyStats(date string) map[string]*DailyStats

GetDailyStats returns statistics for a specific date

func (*Stats) GetPeriodStats added in v1.4.0

func (s *Stats) GetPeriodStats(startDate, endDate string) map[string]*DailyStats

GetPeriodStats returns aggregated statistics for a time period

func (*Stats) GetStats

func (s *Stats) GetStats() (int, map[string]*EndpointStats)

GetStats returns a copy of current statistics (thread-safe)

func (*Stats) Load added in v0.5.2

func (s *Stats) Load() error

Load loads statistics from file

func (*Stats) RecordError

func (s *Stats) RecordError(endpointName string)

RecordError records an error for an endpoint

func (*Stats) RecordRequest

func (s *Stats) RecordRequest(endpointName string)

RecordRequest records a request for an endpoint

func (*Stats) RecordTokens

func (s *Stats) RecordTokens(endpointName string, inputTokens, outputTokens int)

RecordTokens records token usage for an endpoint

func (*Stats) Reset

func (s *Stats) Reset()

Reset resets all statistics

func (*Stats) Save added in v0.5.2

func (s *Stats) Save() error

Save saves statistics to file

func (*Stats) SetStatsPath added in v0.5.2

func (s *Stats) SetStatsPath(path string)

SetStatsPath sets the path for stats persistence

type Usage

type Usage struct {
	InputTokens  int `json:"input_tokens"`
	OutputTokens int `json:"output_tokens"`
}

Usage represents token usage information from API response

Jump to

Keyboard shortcuts

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