imo

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

Documentation

Overview

Package imo is the library behind the imo command line: the HTTP client, request shaping, and typed data models for imo-official.org.

The Client sets a real User-Agent, paces requests so a busy session stays polite, and retries transient failures (429 and 5xx) with exponential backoff.

Index

Constants

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

BaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "Mozilla/5.0 (compatible; imo-cli/dev; +https://github.com/tamnd/imo-cli)"

DefaultUserAgent identifies the client to the site.

View Source
const Host = "imo-official.org"

Host is the site this client talks to, and the host the URI driver in domain.go claims.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to imo-official.org over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) Editions

func (c *Client) Editions(ctx context.Context) ([]*Edition, error)

Editions fetches all IMO editions sorted by year ascending (rank 1 = 1959).

func (*Client) Problems

func (c *Client) Problems(ctx context.Context, year int) ([]*Problem, error)

Problems fetches all competition problems for the given year.

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: 300 ms between requests, 30 s timeout, 3 retries.

type Domain

type Domain struct{}

Domain is the IMO 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 — a bare year or a full URL — into the canonical (type, id), so `ant resolve` and `ant url` touch no network.

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 IMO operation onto app.

type Edition

type Edition struct {
	Rank int    `json:"rank" table:"RANK" kit:"id"`
	Year int    `json:"year" table:"YEAR"`
	URL  string `json:"url"  table:"URL"`
}

Edition represents one year of the International Mathematical Olympiad.

type Problem

type Problem struct {
	Year   int    `json:"year"    table:"YEAR"`
	Number int    `json:"number"  table:"NUM"  kit:"id"`
	Day    int    `json:"day"     table:"DAY"`
	Text   string `json:"text"    table:"TEXT" kit:"body"`
	PDFURL string `json:"pdf_url" table:"PDF_URL"`
	URL    string `json:"url"     table:"URL"`
}

Problem represents one competition problem from an IMO edition.

Jump to

Keyboard shortcuts

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