Adding a data provider
A provider is a Go package that implements provider.Provider
(internal/provider/provider.go):
type Provider interface { Name() string // stored with every raw payload, e.g. "sportmonks" ParserVersion() string // bump when parsing the same payload can give different output
FetchSeason(ctx, seasonRef) (Raw, error) // I/O ParseSeason(Raw) (Season, error) // pure FetchSchedule(ctx, seasonRef) (Raw, error) ParseSchedule(Raw) (Schedule, error) // matchday number -> fixture refs FetchFixture(ctx, fixtureRef) (Raw, error) ParseFixture(Raw) (Fixture, error) // the important one}Steps:
- Create
internal/provider/<name>/. Usehttpx.Clientfor requests: it handles timeouts, retries with backoff,Retry-Afterand client-side rate limiting. If the provider reports back-off somewhere other than theRetry-Afterheader, setRetryAfter. - Keep Fetch and Parse separate. Fetch returns the response body verbatim. Parse must be pure, because stored payloads are re-parsed later without the network.
ParseFixtureproducesdomain.MatchFactsusing the provider’s own IDs: lineups with roles and starters, optional ratings, and the events that matter (goals, penalties scored, missed or saved, own goals, substitutions, cards). Order events withSeq. Skip rescinded events and penalty shoot-outs. SetFinalonly once the match is over.- Add recorded responses under
testdata/with a golden test, and check thattimeline.Deriveaccepts the parsed facts. The Sportmonks package is a complete example. - Wire it in
cmd/openfanta(today the Sportmonks client is created innewService).
Ingest owns caching, ID mapping (provider IDs never leak into the API) and versioning, so a provider needs none of that.