Documentation
¶
Overview ¶
Package dataset finds, downloads, verifies and caches the published dataset for a game build.
Releases are GitHub releases of the data repo named `dataset-<build>`, each with a `manifest-<build>.json` and a `wowc-dataset-<build>.tar.zst` asset (see the data repo's docs/releases.md). A dataset is cached at `<root>/<build>`; the cache only ever holds directories whose every file matched the manifest's sha256 when they were put there.
Index ¶
- Constants
- Variables
- func DefaultRoot() (string, error)
- func Matches(gameBuild, clientVersion, clientBuild string) bool
- func Same(a, b Manifest) bool
- type Manifest
- type Result
- type Store
- func (s Store) Cached() (good []string, bad map[string]error)
- func (s Store) CachedManifest(build string) (Manifest, error)
- func (s Store) Dir(build string) string
- func (s Store) Ensure(ctx context.Context, want string, update bool) (Result, error)
- func (s Store) Refresh(ctx context.Context, want string) (build string, updated bool, err error)
Constants ¶
const ( DefaultReleasesURL = "https://github.com/WoW-Companion/data/releases" DefaultAPIURL = "https://api.github.com/repos/WoW-Companion/data/releases" )
Variables ¶
var ErrNoDataset = errors.New("no dataset available")
ErrNoDataset means no cached dataset satisfies the request and none could be downloaded.
Functions ¶
func DefaultRoot ¶
DefaultRoot is the per-user cache: %LOCALAPPDATA%\wowc\dataset on Windows, the XDG cache ($XDG_CACHE_HOME or ~/.cache) on Linux and ~/Library/Caches on macOS.
Types ¶
type Manifest ¶
type Manifest struct {
DatasetVersion string `json:"dataset_version"`
GameBuild string `json:"game_build"`
Created string `json:"created"`
Revision string `json:"revision"` // bumped when the data repo republishes the same build
Tables []struct {
Path string `json:"path"`
SHA256 string `json:"sha256"`
} `json:"tables"`
}
Manifest is the part of manifest.json the loader checks.
func ParseManifest ¶
ParseManifest decodes and checks manifest.json bytes: a game build and tables with safe paths and sha256 sums.
type Result ¶
type Result struct {
Dir string
Build string
Downloaded bool // fetched by this call
Offline error // set when the network failed and the cache was used instead
}
Result is a usable dataset directory.
type Store ¶
type Store struct {
Root string // cache root; each dataset is Root/<build>
ReleasesURL string // download base, default DefaultReleasesURL
APIURL string // releases API, default DefaultAPIURL
HTTP *http.Client // default http.DefaultClient
}
Store downloads into and reads from one cache root.
func (Store) Cached ¶
Cached lists the full builds in the cache whose directories verify, newest first. Directories that fail verification are returned in bad with the reason.
func (Store) CachedManifest ¶ added in v0.7.18
CachedManifest reads the manifest of the cached dataset for a full build.
func (Store) Ensure ¶
Ensure returns a verified dataset for want, a client build (a full "1.60.1.71037" or just the number "71037"), downloading it when the cache lacks it. An empty want means the newest: the newest cached dataset when update is false, else the newest release. When the network fails and the cache has a match, the cache is used and Result.Offline says why.
func (Store) Refresh ¶ added in v0.7.18
Refresh checks the published manifest for a cached build and, when it differs from the cached one (a republish of the same build), downloads and verifies the new archive and replaces the cache directory by a rename. want is a client build as for Ensure; "" means the newest release. It returns the full build checked and whether the cache was replaced. A build that is not cached is left to Ensure; on any error the cache is untouched.