ergast

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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

View Source
const BaseURL = "https://api.jolpi.ca/ergast/f1"

BaseURL is the root every request is built from.

View Source
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.

View Source
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 NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults.

func NewClientFromConfig

func NewClientFromConfig(cfg Config) *Client

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

func (c *Client) Drivers(ctx context.Context, limit, offset int) ([]*Driver, error)

Drivers fetches the list of all F1 drivers, paginated. limit=0 returns default page.

func (*Client) Get

func (c *Client) Get(ctx context.Context, url string) ([]byte, error)

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

func (c *Client) Results(ctx context.Context, season string, round int) ([]*RaceResult, error)

Results fetches race results for season/round. Returns one record per driver.

func (*Client) Schedule

func (c *Client) Schedule(ctx context.Context, season string) ([]*Race, error)

Schedule fetches the race schedule for a season.

func (*Client) Standings

func (c *Client) Standings(ctx context.Context, season string) ([]*DriverStanding, error)

Standings fetches driver championship standings for a season.

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) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns any accepted input into the canonical (type, id).

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.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate is the inverse: the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

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.

Jump to

Keyboard shortcuts

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