server

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnalyzeResponse

type AnalyzeResponse struct {
	ContentType string `json:"content_type"`
}

AnalyzeResponse for content analysis

type CompressRequest

type CompressRequest struct {
	Input  string `json:"input"`
	Mode   string `json:"mode,omitempty"`   // "minimal" or "aggressive"
	Budget int    `json:"budget,omitempty"` // Target token budget
}

CompressRequest for compression API

type CompressResponse

type CompressResponse struct {
	Output           string  `json:"output"`
	OriginalTokens   int     `json:"original_tokens"`
	FinalTokens      int     `json:"final_tokens"`
	TokensSaved      int     `json:"tokens_saved"`
	ReductionPercent float64 `json:"reduction_percent"`
	ProcessingTimeMs int64   `json:"processing_time_ms"`
}

CompressResponse for compression results

type Config

type Config struct {
	Port           int
	APIKey         string // Optional API key for authentication (empty = no auth)
	LogLevel       string // "debug", "info", "error"
	Version        string
	RateLimit      int // Requests per minute (0 = unlimited)
	PipelineConfig filter.PipelineConfig
}

Config holds server configuration

type HealthResponse

type HealthResponse struct {
	Status  string `json:"status"`
	Version string `json:"version"`
}

HealthResponse for health checks

type LogEntry

type LogEntry struct {
	Time    string         `json:"time"`
	Level   string         `json:"level"`
	Message string         `json:"message"`
	Fields  map[string]any `json:"fields,omitempty"`
}

LogEntry represents a structured log entry

type Logger

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

Logger provides structured logging

func NewLogger

func NewLogger(level string) *Logger

NewLogger creates a new logger

func (*Logger) Debug

func (l *Logger) Debug(msg string, fields map[string]any)

Debug logs at DEBUG level

func (*Logger) Error

func (l *Logger) Error(msg string, fields map[string]any)

Error logs at ERROR level

func (*Logger) Info

func (l *Logger) Info(msg string, fields map[string]any)

Info logs at INFO level

type Metrics

type Metrics struct {

	// Counters
	TotalRequests     int64
	TotalCompressions int64
	TotalTokensIn     int64
	TotalTokensOut    int64
	TotalTokensSaved  int64
	TotalErrors       int64

	// Histograms (simplified as maps)
	ProcessingTimes   []time.Duration
	ReductionPercents []float64

	// Gauges
	ActiveConnections int64

	// Content type distribution
	ContentTypeCounts map[string]int64

	// Start time for uptime
	StartTime time.Time
	// contains filtered or unexported fields
}

Metrics holds server observability data

func NewMetrics

func NewMetrics() *Metrics

NewMetrics creates a new metrics instance

func (*Metrics) PrometheusFormat

func (m *Metrics) PrometheusFormat() string

PrometheusFormat returns metrics in Prometheus text format

func (*Metrics) RecordCompression

func (m *Metrics) RecordCompression(original, final int, duration time.Duration, contentType string)

RecordCompression tracks a compression operation

func (*Metrics) RecordError

func (m *Metrics) RecordError()

RecordError tracks an error

func (*Metrics) Snapshot

func (m *Metrics) Snapshot() MetricsSnapshot

Snapshot returns a point-in-time copy of metrics

type MetricsSnapshot

type MetricsSnapshot struct {
	Uptime            time.Duration    `json:"uptime"`
	TotalRequests     int64            `json:"total_requests"`
	TotalCompressions int64            `json:"total_compressions"`
	TotalTokensIn     int64            `json:"total_tokens_in"`
	TotalTokensOut    int64            `json:"total_tokens_out"`
	TotalTokensSaved  int64            `json:"total_tokens_saved"`
	TotalErrors       int64            `json:"total_errors"`
	AvgProcessingMs   int64            `json:"avg_processing_ms"`
	AvgReductionPct   float64          `json:"avg_reduction_pct"`
	ContentTypeCounts map[string]int64 `json:"content_type_counts"`
}

MetricsSnapshot is a point-in-time view of metrics

type Server

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

Server provides REST API for token compression

func New

func New(config Config) *Server

New creates a new server

func (*Server) Start

func (s *Server) Start() error

Start begins listening for requests

func (*Server) StartContext

func (s *Server) StartContext(ctx context.Context) error

StartContext begins listening for requests and stops on context cancellation.

type StatsResponse

type StatsResponse struct {
	Version    string `json:"version"`
	LayerCount int    `json:"layer_count"`
}

StatsResponse for server stats

Jump to

Keyboard shortcuts

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