espn

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package espn is the library behind the espn command line: the HTTP client, request shaping, and the typed data models for ESPN.

The Client talks to site.api.espn.com, ESPN's unofficial public API. No API key is required. It sets a real User-Agent, paces requests to stay polite, and retries transient failures (429 and 5xx).

Index

Constants

View Source
const BaseURL = "https://" + Host

BaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "espn-cli/0.1 (tamnd87@gmail.com)"

DefaultUserAgent identifies this client to ESPN.

View Source
const Host = "site.api.espn.com"

Host is the ESPN API host this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Article

type Article struct {
	Headline      string `json:"headline"`
	Description   string `json:"description"`
	Byline        string `json:"byline,omitempty"`
	PublishedDate string `json:"published_date"`
	Premium       bool   `json:"premium"`
	WebURL        string `json:"web_url,omitempty"`
	ImageURL      string `json:"image_url,omitempty"`
}

Article is one news article.

type Client

type Client struct {
	HTTP      *http.Client
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Retries   int
	// contains filtered or unexported fields
}

Client talks to the ESPN API over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with DefaultConfig settings.

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 settings. The body is read and closed here.

func (*Client) ListNews

func (c *Client) ListNews(ctx context.Context, sport, league string, limit int) ([]*Article, error)

ListNews fetches the latest news for the given sport/league.

func (*Client) ListSchedule

func (c *Client) ListSchedule(ctx context.Context, sport, league string) ([]*Game, error)

ListSchedule fetches the schedule (same endpoint as scoreboard).

func (*Client) ListScores

func (c *Client) ListScores(ctx context.Context, sport, league string) ([]*Game, error)

ListScores fetches current/recent scoreboard for the given sport/league.

func (*Client) ListStandings

func (c *Client) ListStandings(ctx context.Context, sport, league string) ([]*Standing, error)

ListStandings fetches current standings for the given sport/league.

func (*Client) ListTeams

func (c *Client) ListTeams(ctx context.Context, sport, league string) ([]*Team, error)

ListTeams fetches all teams for the given sport/league.

type Config

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

Config holds the client settings.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults.

type Domain

type Domain struct{}

Domain is the ESPN 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.

func (Domain) Register

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

Register installs the client factory and every operation onto app.

type Game

type Game struct {
	ID        string `json:"id"`
	Date      string `json:"date"`
	ShortName string `json:"short_name"`
	HomeTeam  string `json:"home_team"`
	HomeScore string `json:"home_score"`
	AwayTeam  string `json:"away_team"`
	AwayScore string `json:"away_score"`
	Status    string `json:"status"`
	Season    int    `json:"season"`
}

Game is one scoreboard entry.

type Standing

type Standing struct {
	Team       string  `json:"team"`
	Wins       float64 `json:"wins"`
	Losses     float64 `json:"losses"`
	Ties       float64 `json:"ties"`
	WinPct     string  `json:"win_pct"`
	Division   string  `json:"division"`
	Conference string  `json:"conference"`
}

Standing is one team's standing in the league.

type Team

type Team struct {
	ID           string `json:"id"`
	Name         string `json:"name"`
	Abbreviation string `json:"abbreviation"`
	Location     string `json:"location"`
	Slug         string `json:"slug"`
	LogoURL      string `json:"logo_url,omitempty"`
	WebURL       string `json:"web_url,omitempty"`
}

Team is one team entry.

Jump to

Keyboard shortcuts

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