Documentation
¶
Overview ¶
Package ergast is the library behind the ergast command line: the HTTP client, request shaping, and the typed data models for the Jolpica Ergast Formula 1 API.
The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public API throws under load.
Index ¶
- Constants
- type Client
- func (c *Client) ConstructorStandings(ctx context.Context, season string) ([]*ConstructorStanding, error)
- func (c *Client) Drivers(ctx context.Context, limit, offset int) ([]*Driver, error)
- func (c *Client) Get(ctx context.Context, url string) ([]byte, error)
- func (c *Client) Results(ctx context.Context, season string, round int) ([]*RaceResult, error)
- func (c *Client) Schedule(ctx context.Context, season string) ([]*Race, error)
- func (c *Client) Standings(ctx context.Context, season string) ([]*DriverStanding, error)
- type Config
- type ConstructorStanding
- type Domain
- type Driver
- type DriverStanding
- type Race
- type RaceResult
Constants ¶
const BaseURL = "https://api.jolpi.ca/ergast/f1"
BaseURL is the root every request is built from.
const DefaultUserAgent = "ergast-cli/0.1.0 (github.com/tamnd/ergast-cli)"
DefaultUserAgent identifies the client to the Jolpica API. A real, honest User-Agent is both polite and the thing most likely to keep you unblocked.
const Host = "api.jolpi.ca"
Host is the API host this client talks to.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
HTTP *http.Client
UserAgent string
BaseURL string
// Rate is the minimum gap between requests. Zero means no pacing.
Rate time.Duration
Retries int
// contains filtered or unexported fields
}
Client talks to the Jolpica Ergast F1 API over HTTP.
func NewClientFromConfig ¶
NewClientFromConfig builds a Client from a Config.
func (*Client) ConstructorStandings ¶
func (c *Client) ConstructorStandings(ctx context.Context, season string) ([]*ConstructorStanding, error)
ConstructorStandings fetches constructor championship standings for a season.
func (*Client) Drivers ¶
Drivers fetches the list of all F1 drivers, paginated. limit=0 returns default page.
func (*Client) Get ¶
Get fetches url and returns the response body. It paces and retries according to the client's settings. The caller owns nothing extra; the body is read fully and closed here.
func (*Client) Results ¶
Results fetches race results for season/round. Returns one record per driver.
type Config ¶
type Config struct {
BaseURL string
UserAgent string
Rate time.Duration
Timeout time.Duration
Retries int
}
Config holds client configuration.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults.
type ConstructorStanding ¶
type ConstructorStanding struct {
Season string `json:"season"`
Position int `json:"position"`
Points string `json:"points"`
Wins string `json:"wins"`
ConstructorID string `json:"constructor_id"`
Name string `json:"name"`
Nationality string `json:"nationality"`
}
ConstructorStanding is one constructor's standing in a championship.
type Domain ¶
type Domain struct{}
Domain is the ergast driver. It carries no state; the per-run client is built by the factory Register hands kit.
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.
type Driver ¶
type Driver struct {
ID string `json:"id"`
Code string `json:"code,omitempty"`
Number string `json:"number,omitempty"`
GivenName string `json:"given_name"`
FamilyName string `json:"family_name"`
Nationality string `json:"nationality"`
DateOfBirth string `json:"date_of_birth,omitempty"`
}
Driver is an F1 driver's biography record.
type DriverStanding ¶
type DriverStanding struct {
Season string `json:"season"`
Position int `json:"position"`
Points string `json:"points"`
Wins string `json:"wins"`
DriverID string `json:"driver_id"`
Name string `json:"name"`
Nationality string `json:"nationality"`
Constructor string `json:"constructor"`
}
DriverStanding is one driver's standing in a championship.
type Race ¶
type Race struct {
Season string `json:"season"`
Round int `json:"round"`
Name string `json:"name"`
Circuit string `json:"circuit"`
Date string `json:"date"`
Time string `json:"time,omitempty"`
URL string `json:"url,omitempty"`
}
Race is one entry in a season schedule.
type RaceResult ¶
type RaceResult struct {
Season string `json:"season"`
Round int `json:"round"`
RaceName string `json:"race_name"`
Circuit string `json:"circuit"`
Date string `json:"date"`
Position int `json:"position"`
DriverID string `json:"driver_id"`
DriverName string `json:"driver_name"`
Constructor string `json:"constructor"`
Points string `json:"points"`
Laps string `json:"laps"`
Time string `json:"time,omitempty"`
Status string `json:"status"`
}
RaceResult is one driver's result in a race.