Documentation
¶
Overview ¶
Package api wraps the Ergast F1 REST API with an optional file-based cache.
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) GetDriverStandings(year, round int) ([]DriverStanding, error)
- func (c *Client) GetPointsEarnedInRound(year, round int) ([]RaceResult, error)
- func (c *Client) GetRaceInfo(year, round int) (Race, error)
- func (c *Client) GetRaceResults(year, round int) ([]RaceResult, error)
- func (c *Client) GetSeasonSchedule(year int) ([]Race, error)
- func (c *Client) GetStandingsBeforeRound(year, round int) ([]DriverStanding, error)
- func (c *Client) GetTotalRounds(year int) (int, error)
- type DriverStanding
- type FileCache
- type Race
- type RaceResult
Constants ¶
const ( BaseURL = "https://ergast.com/api/f1" FallbackBaseURL = "https://api.jolpi.ca/ergast/f1" )
Variables ¶
var ( ErrAPIUnreachable = errors.New("Ergast API unreachable") ErrResourceNotFound = errors.New("resource not found in Ergast dataset") ErrInvalidSeason = errors.New("season is outside the supported range") )
Sentinel errors the caller can test with errors.Is.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the Ergast API with automatic primary→fallback retry and an optional file-based response cache. Pass nil for cache to disable caching.
func (*Client) GetDriverStandings ¶
func (c *Client) GetDriverStandings(year, round int) ([]DriverStanding, error)
GetDriverStandings returns the championship table after round in year.
func (*Client) GetPointsEarnedInRound ¶
func (c *Client) GetPointsEarnedInRound(year, round int) ([]RaceResult, error)
GetPointsEarnedInRound returns only the drivers who scored points.
func (*Client) GetRaceInfo ¶
GetRaceInfo returns metadata for one race.
func (*Client) GetRaceResults ¶
func (c *Client) GetRaceResults(year, round int) ([]RaceResult, error)
GetRaceResults returns the full race classification for (year, round).
func (*Client) GetSeasonSchedule ¶
GetSeasonSchedule returns the race calendar for year.
func (*Client) GetStandingsBeforeRound ¶
func (c *Client) GetStandingsBeforeRound(year, round int) ([]DriverStanding, error)
GetStandingsBeforeRound returns the championship state entering round. Returns an empty slice for round 1 (no prior data exists).
type DriverStanding ¶
type DriverStanding struct {
Position int `json:"position"`
Points float64 `json:"points"`
Wins int `json:"wins"`
DriverID string `json:"driver_id"`
Code string `json:"code"`
GivenName string `json:"given_name"`
FamilyName string `json:"family_name"`
DriverName string `json:"driver_name"`
TeamName string `json:"team_name"`
}
DriverStanding is one row in the drivers' championship table.
type FileCache ¶
type FileCache struct {
// contains filtered or unexported fields
}
FileCache stores one JSON file per URL under a directory. The cache key is the SHA-256 hex of the full request URL.
func NewFileCache ¶
NewFileCache initialises the cache directory and returns a FileCache.
type Race ¶
type Race struct {
Season int `json:"season"`
Round int `json:"round"`
RaceName string `json:"race_name"`
Date string `json:"date"`
Time string `json:"time,omitempty"`
CircuitID string `json:"circuit_id"`
CircuitName string `json:"circuit_name"`
Locality string `json:"locality"`
Country string `json:"country"`
}
Race holds metadata for a single Grand Prix weekend.
type RaceResult ¶
type RaceResult struct {
Position int `json:"position"`
PositionText string `json:"position_text"`
Points float64 `json:"points"`
Grid int `json:"grid"`
Laps int `json:"laps"`
Status string `json:"status"`
RaceTime string `json:"race_time,omitempty"`
DriverID string `json:"driver_id"`
DriverName string `json:"driver_name"`
TeamName string `json:"team_name"`
}
RaceResult is one row in the race classification table.