Documentation
¶
Overview ¶
Package server implements the HTTP server for the PR Cost API.
Index ¶
- Constants
- Variables
- func IsAccessError(err error) bool
- func NewAccessError(statusCode int, message string) error
- type AccessError
- type CalculateRequest
- type CalculateResponse
- type OrgSampleRequest
- type ProgressUpdate
- type RepoSampleRequest
- type SampleResponse
- type Server
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) SetCORSConfig(origins string, allowAll bool)
- func (s *Server) SetCommit(commit string)
- func (s *Server) SetDataSource(source string)
- func (s *Server) SetR2RCallout(enabled bool)
- func (s *Server) SetRateLimit(rps int, burst int)
- func (s *Server) SetTokenValidation(appID string, keyFile string) error
- func (*Server) Shutdown()
Constants ¶
const ( // DefaultRateLimit is the default requests per second limit. DefaultRateLimit = 100 // DefaultRateBurst is the default burst size for rate limiting. DefaultRateBurst = 100 )
Variables ¶
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 ¶
IsAccessError checks if an error is an access error.
func NewAccessError ¶
NewAccessError creates a new access error.
Types ¶
type AccessError ¶
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 (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler interface.
func (*Server) SetCORSConfig ¶
SetCORSConfig sets the CORS configuration.
func (*Server) SetDataSource ¶
SetDataSource sets the data source for PR data fetching.
func (*Server) SetR2RCallout ¶
SetR2RCallout enables or disables the Ready-to-Review promotional callout.
func (*Server) SetRateLimit ¶
SetRateLimit sets the rate limiting configuration.
func (*Server) SetTokenValidation ¶
SetTokenValidation configures GitHub token validation.