server

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package server implements the HTTP server for the PR Cost API.

Index

Constants

View Source
const (
	// DefaultRateLimit is the default requests per second limit.
	DefaultRateLimit = 100
	// DefaultRateBurst is the default burst size for rate limiting.
	DefaultRateBurst = 100
)

Variables

View Source
var (
	ErrAccessDenied   = errors.New("access denied")
	ErrNotFound       = errors.New("not found")
	ErrInvalidRequest = errors.New("invalid request")
	ErrRateLimit      = errors.New("rate limit exceeded")
	ErrTimeout        = errors.New("request timeout")
)

Error types.

Functions

func IsAccessError

func IsAccessError(err error) bool

IsAccessError checks if an error is an access error.

func NewAccessError

func NewAccessError(statusCode int, message string) error

NewAccessError creates a new access error.

Types

type AccessError

type AccessError struct {
	Message    string
	StatusCode int
}

AccessError represents an error due to access denial.

func (*AccessError) Error

func (e *AccessError) Error() string

type CalculateRequest

type CalculateRequest struct {
	URL    string       `json:"url"`
	Config *cost.Config `json:"config,omitempty"`
}

CalculateRequest represents a request to calculate PR costs.

type CalculateResponse

type CalculateResponse struct {
	Breakdown      cost.Breakdown `json:"breakdown"`
	Timestamp      time.Time      `json:"timestamp"`
	Commit         string         `json:"commit"`
	SecondsInState map[string]int `json:"seconds_in_state,omitempty"` // Only populated when using turnserver
}

CalculateResponse represents the response from a cost calculation.

type OrgSampleRequest

type OrgSampleRequest struct {
	Org        string       `json:"org"`
	SampleSize int          `json:"sample_size,omitempty"` // Default: 30
	Days       int          `json:"days,omitempty"`        // Default: 90
	Config     *cost.Config `json:"config,omitempty"`
}

OrgSampleRequest represents a request to sample and calculate costs for an organization.

type ProgressUpdate

type ProgressUpdate struct {
	Type           string                      `json:"type"` // "fetching", "processing", "complete", "error", "done"
	PR             int                         `json:"pr,omitempty"`
	Owner          string                      `json:"owner,omitempty"`
	Repo           string                      `json:"repo,omitempty"`
	Progress       string                      `json:"progress,omitempty"` // e.g., "5/15"
	Error          string                      `json:"error,omitempty"`
	Result         *cost.ExtrapolatedBreakdown `json:"result,omitempty"`
	Commit         string                      `json:"commit,omitempty"`
	R2RCallout     bool                        `json:"r2r_callout,omitempty"`
	SecondsInState map[string]int              `json:"seconds_in_state,omitempty"` // Only in "done" messages
}

ProgressUpdate represents a progress update for streaming responses.

type RepoSampleRequest

type RepoSampleRequest struct {
	Owner      string       `json:"owner"`
	Repo       string       `json:"repo"`
	SampleSize int          `json:"sample_size,omitempty"` // Default: 30
	Days       int          `json:"days,omitempty"`        // Default: 90
	Config     *cost.Config `json:"config,omitempty"`
}

RepoSampleRequest represents a request to sample and calculate costs for a repository.

type SampleResponse

type SampleResponse struct {
	Extrapolated   cost.ExtrapolatedBreakdown `json:"extrapolated"`
	Timestamp      time.Time                  `json:"timestamp"`
	Commit         string                     `json:"commit"`
	SecondsInState map[string]int             `json:"seconds_in_state,omitempty"` // Aggregated across all sampled PRs
}

SampleResponse represents the response from a sampling operation.

type Server

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

Server handles HTTP requests for the PR Cost API.

func New

func New() *Server

New creates a new Server instance.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler interface.

func (*Server) SetCORSConfig

func (s *Server) SetCORSConfig(origins string, allowAll bool)

SetCORSConfig sets the CORS configuration.

func (*Server) SetCommit

func (s *Server) SetCommit(commit string)

SetCommit sets the server commit hash.

func (*Server) SetDataSource

func (s *Server) SetDataSource(source string)

SetDataSource sets the data source for PR data fetching.

func (*Server) SetR2RCallout

func (s *Server) SetR2RCallout(enabled bool)

SetR2RCallout enables or disables the Ready-to-Review promotional callout.

func (*Server) SetRateLimit

func (s *Server) SetRateLimit(rps int, burst int)

SetRateLimit sets the rate limiting configuration.

func (*Server) SetTokenValidation

func (s *Server) SetTokenValidation(appID string, keyFile string) error

SetTokenValidation configures GitHub token validation.

func (*Server) Shutdown

func (*Server) Shutdown()

Shutdown gracefully shuts down the server.

Jump to

Keyboard shortcuts

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