openf1

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: 11 Imported by: 0

Documentation

Overview

domain.go exposes OpenF1 as a kit Domain: a driver that a multi-domain host (ant) enables with a single blank import,

import _ "github.com/tamnd/openf1-cli/openf1"

exactly as a database/sql program enables a driver with `import _ "github.com/lib/pq"`. The init below registers it; the host then dereferences openf1:// URIs by routing to the operations Register installs. The same Domain also builds the standalone openf1 binary (see cli.NewApp), so the binary and a host share one source of truth.

Package openf1 is the library behind the openf1 command line: the HTTP client, request shaping, and the typed data models for the OpenF1 API (api.openf1.org/v1).

OpenF1 is a free, open-source API providing Formula 1 live timing and historical session data. No API key required. Data includes sessions, meetings, drivers, lap timing, stints, pit stops, race control messages, and telemetry.

Index

Constants

View Source
const BaseURL = "https://api.openf1.org/v1"

BaseURL is the API base URL.

View Source
const Host = "api.openf1.org"

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 {
	// contains filtered or unexported fields
}

Client talks to the OpenF1 API over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client configured with the default config.

func NewClientConfig

func NewClientConfig(cfg Config) *Client

NewClientConfig returns a Client configured with cfg.

func (*Client) GetDrivers

func (c *Client) GetDrivers(ctx context.Context, f DriverFilter) ([]Driver, error)

GetDrivers fetches drivers matching the filter.

func (*Client) GetLaps

func (c *Client) GetLaps(ctx context.Context, f LapFilter) ([]Lap, error)

GetLaps fetches laps matching the filter.

func (*Client) GetMeetings

func (c *Client) GetMeetings(ctx context.Context, f MeetingFilter) ([]Meeting, error)

GetMeetings fetches meetings matching the filter.

func (*Client) GetPit

func (c *Client) GetPit(ctx context.Context, f PitFilter) ([]PitStop, error)

GetPit fetches pit stops matching the filter.

func (*Client) GetRaceControl

func (c *Client) GetRaceControl(ctx context.Context, f RaceControlFilter) ([]RaceControlMsg, error)

GetRaceControl fetches race control messages matching the filter.

func (*Client) GetSessions

func (c *Client) GetSessions(ctx context.Context, f SessionFilter) ([]Session, error)

GetSessions fetches sessions matching the filter.

func (*Client) GetStints

func (c *Client) GetStints(ctx context.Context, f StintFilter) ([]Stint, error)

GetStints fetches stints matching the filter.

type Config

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Timeout   time.Duration
	Retries   int
}

Config holds all tunable parameters for the Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type Domain

type Domain struct{}

Domain is the openf1 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 is not deeply meaningful for an API-only domain with no browsable page hierarchy, so we return an error to signal this domain is query-driven.

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 returns an error since OpenF1 sessions are not web-browsable pages.

func (Domain) Register

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

Register installs the client factory and every OpenF1 operation onto app.

type Driver

type Driver struct {
	DriverNumber int    `json:"driver_number" kit:"id" table:"driver_number"`
	FullName     string `json:"full_name" table:"full_name"`
	NameAcronym  string `json:"name_acronym" table:"acronym"`
	TeamName     string `json:"team_name" table:"team"`
	TeamColour   string `json:"team_colour" table:"team_colour"`
	CountryCode  string `json:"country_code" table:"country"`
	HeadshotURL  string `json:"headshot_url" table:"headshot_url,url"`
}

Driver represents a driver entry in a session as returned by /drivers.

type DriverFilter

type DriverFilter struct {
	SessionKey   int
	DriverNumber int
}

DriverFilter holds optional filter params for the drivers endpoint.

type Lap

type Lap struct {
	LapNumber    int      `json:"lap_number" kit:"id" table:"lap_number"`
	DriverNumber int      `json:"driver_number" table:"driver_number"`
	LapDuration  *float64 `json:"lap_duration,omitempty" table:"lap_duration"`
	I1Speed      int      `json:"i1_speed" table:"i1_speed"`
	I2Speed      int      `json:"i2_speed" table:"i2_speed"`
	STSpeed      int      `json:"st_speed" table:"st_speed"`
	IsPitOutLap  bool     `json:"is_pit_out_lap" table:"pit_out"`
}

Lap represents one lap's timing data as returned by /laps. LapDuration may be null when no clean lap time was recorded.

type LapFilter

type LapFilter struct {
	SessionKey   int
	DriverNumber int
	LapNumber    int
}

LapFilter holds optional filter params for the laps endpoint.

type Meeting

type Meeting struct {
	MeetingKey   int    `json:"meeting_key" kit:"id" table:"meeting_key"`
	Year         int    `json:"year" table:"year"`
	MeetingName  string `json:"meeting_name" table:"meeting_name"`
	CountryName  string `json:"country_name" table:"country_name"`
	CountryCode  string `json:"country_code" table:"country_code"`
	DateStart    string `json:"date_start" table:"date_start"`
	OfficialName string `json:"meeting_official_name" table:"official_name"`
}

Meeting represents one F1 race weekend as returned by the /meetings endpoint.

type MeetingFilter

type MeetingFilter struct {
	Year int
}

MeetingFilter holds optional filter params for the meetings endpoint.

type PitFilter

type PitFilter struct {
	SessionKey   int
	DriverNumber int
}

PitFilter holds optional filter params for the pit endpoint.

type PitStop

type PitStop struct {
	DriverNumber int      `json:"driver_number" kit:"id" table:"driver_number"`
	LapNumber    int      `json:"lap_number" table:"lap_number"`
	PitDuration  *float64 `json:"pit_duration,omitempty" table:"pit_duration"`
	Date         string   `json:"date" table:"date"`
}

PitStop represents one pit stop event as returned by /pit. PitDuration may be null for in-laps or laps where the stop time was not recorded.

type RaceControlFilter

type RaceControlFilter struct {
	SessionKey int
	Flag       string
}

RaceControlFilter holds optional filter params for the race_control endpoint.

type RaceControlMsg

type RaceControlMsg struct {
	Date         string `json:"date" table:"date"`
	DriverNumber *int   `json:"driver_number,omitempty" table:"driver_number"`
	LapNumber    *int   `json:"lap_number,omitempty" table:"lap_number"`
	Category     string `json:"category" table:"category"`
	Flag         string `json:"flag,omitempty" table:"flag"`
	Scope        string `json:"scope,omitempty" table:"scope"`
	Sector       *int   `json:"sector,omitempty" table:"sector"`
	Message      string `json:"message" table:"message"`
}

RaceControlMsg represents one race control message as returned by /race_control. DriverNumber, LapNumber, and Sector are nullable in the API.

type Session

type Session struct {
	SessionKey       int    `json:"session_key" kit:"id" table:"session_key"`
	MeetingKey       int    `json:"meeting_key" table:"meeting_key"`
	Year             int    `json:"year" table:"year"`
	MeetingName      string `json:"meeting_name" table:"meeting_name"`
	CountryName      string `json:"country_name" table:"country_name"`
	CircuitShortName string `json:"circuit_short_name" table:"circuit_short_name"`
	SessionName      string `json:"session_name" table:"session_name"`
	SessionType      string `json:"session_type" table:"session_type"`
	DateStart        string `json:"date_start" table:"date_start"`
	DateEnd          string `json:"date_end" table:"date_end"`
}

Session represents one F1 session (Race, Qualifying, Sprint, etc.) as returned by the /sessions endpoint.

type SessionFilter

type SessionFilter struct {
	Year        int
	SessionName string // "Race", "Qualifying", "Sprint", etc.
	Circuit     string // circuit_short_name
}

SessionFilter holds optional filter params for the sessions endpoint.

type Stint

type Stint struct {
	StintNumber    int    `json:"stint_number" kit:"id" table:"stint_number"`
	DriverNumber   int    `json:"driver_number" table:"driver_number"`
	LapStart       int    `json:"lap_start" table:"lap_start"`
	LapEnd         int    `json:"lap_end" table:"lap_end"`
	Compound       string `json:"compound" table:"compound"`
	TyreAgeAtStart int    `json:"tyre_age_at_start" table:"tyre_age"`
}

Stint represents one tyre stint as returned by /stints.

type StintFilter

type StintFilter struct {
	SessionKey   int
	DriverNumber int
}

StintFilter holds optional filter params for the stints endpoint.

Jump to

Keyboard shortcuts

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