Documentation
¶
Overview ¶
Package catalogsource yields a full *catalog.IndexedCatalog from one of four places: the catalog embedded in this SDK version, a local catalog file, a relay-catalog release asset fetched by tag and cached on disk (Release), or the newest release of this SDK's schema channel, refreshed periodically with labelled fallbacks (Latest). Consumers that pin a catalog tag (modeldir, modelroutes) read it through here, so sdk/catalog itself never touches the network or the disk beyond an explicit LoadFile.
A release whose tag matches the embedded catalog is served from the embed without fetching, so a file pinned to the tag this SDK ships with resolves offline.
Out of scope: signature checks on release assets beyond sha256 over HTTPS, cache eviction, and merging catalogs. A cached tag is trusted forever because release tags are immutable.
Index ¶
Constants ¶
const ( // EnvCatalogURL is the base URL of a catalog server that Latest reads; "off" serves the embedded catalog with no network access. EnvCatalogURL = "WR_CATALOG_URL" // EnvCatalogCacheDir turns on Latest's disk cache in that directory. EnvCatalogCacheDir = "WR_CATALOG_CACHE_DIR" // DefaultRefreshInterval is how long Latest serves a result before it checks the index again. DefaultRefreshInterval = 10 * time.Minute )
const ( // Channel is the catalog schema channel this SDK reads. "Latest" resolves within it, so a schema bump never hands this SDK a catalog it cannot parse. Channel = "v1alpha3" // DefaultIndexURL maps each schema channel to its newest catalog release. DefaultIndexURL = "https://catalog.wyolet.com/index.yaml" // DefaultDownloadURL is the release download base; assets live at <base>/<tag>/<asset>. DefaultDownloadURL = "https://catalog.wyolet.com/releases" )
Variables ¶
This section is empty.
Functions ¶
func EmbeddedVersion ¶
func EmbeddedVersion() string
EmbeddedVersion is the relay-catalog release tag the embedded catalog was generated from, or "" when the embed records none.
Types ¶
type LatestOption ¶ added in v0.7.23
type LatestOption func(*LatestSource)
LatestOption configures Latest.
func WithBaseURL ¶ added in v0.7.23
func WithBaseURL(base string) LatestOption
WithBaseURL points Latest at a catalog server: the index at base/index.yaml, releases under base/releases. "off" serves the embedded catalog with no network access.
func WithCacheDir ¶ added in v0.7.23
func WithCacheDir(dir string) LatestOption
WithCacheDir caches release assets and the last resolved tag in dir. "" turns the disk cache off.
func WithLatestDownloadURL ¶ added in v0.7.23
func WithLatestDownloadURL(base string) LatestOption
WithLatestDownloadURL replaces DefaultDownloadURL.
func WithLatestHTTPClient ¶ added in v0.7.23
func WithLatestHTTPClient(c *http.Client) LatestOption
WithLatestHTTPClient replaces the default client (a plain client with a 60s timeout).
func WithLatestIndexURL ¶ added in v0.7.23
func WithLatestIndexURL(url string) LatestOption
WithLatestIndexURL replaces DefaultIndexURL.
func WithRefreshInterval ¶ added in v0.7.23
func WithRefreshInterval(d time.Duration) LatestOption
WithRefreshInterval replaces DefaultRefreshInterval; 0 checks the index on every call.
type LatestResult ¶ added in v0.7.23
type LatestResult struct {
Catalog *catalog.IndexedCatalog
// Tag is the release tag Catalog was built from; "" when the embed records none.
Tag string
// Embedded marks the catalog compiled into this SDK, served because the network is off, the server's latest is older, or nothing else could be read.
Embedded bool
// Stale marks an earlier fetched copy, served because a refresh failed.
Stale bool
// Err is the cause behind Stale or an embedded fallback; nil when the catalog is current.
Err error
}
LatestResult is one Fetch.
type LatestSource ¶ added in v0.7.23
type LatestSource struct {
// contains filtered or unexported fields
}
LatestSource reads the newest catalog release for Channel. Build it with Latest.
func Latest ¶ added in v0.7.23
func Latest(opts ...LatestOption) *LatestSource
Latest is the newest catalog release for Channel, read from DefaultIndexURL and DefaultDownloadURL. WR_CATALOG_URL and WR_CATALOG_CACHE_DIR are read here, and opts override them; a URL option overrides "off". Nothing is fetched until the first Fetch or Catalog, and the disk is written only with a cache dir. A release older than the embedded catalog is never served.
func (*LatestSource) Catalog ¶ added in v0.7.23
func (s *LatestSource) Catalog(ctx context.Context) (*catalog.IndexedCatalog, error)
Catalog returns Fetch's catalog, so a LatestSource is a Source.
func (*LatestSource) Fetch ¶ added in v0.7.23
func (s *LatestSource) Fetch(ctx context.Context) (*LatestResult, error)
Fetch returns the newest release, checking the index at most once per refresh interval. When the index or the release can't be read, it serves, with Err set: the copy held in memory (Stale), else the last tag in the disk cache (Stale), else the embed (Embedded). The error is non-nil only when the embed fails to load.
type ReleaseOption ¶
type ReleaseOption func(*releaseSource)
ReleaseOption configures Release.
func WithDownloadURL ¶
func WithDownloadURL(base string) ReleaseOption
WithDownloadURL replaces DefaultDownloadURL.
func WithHTTPClient ¶
func WithHTTPClient(c *http.Client) ReleaseOption
WithHTTPClient replaces the default client (a plain client with a 60s timeout).
func WithIndexURL ¶
func WithIndexURL(url string) ReleaseOption
WithIndexURL replaces DefaultIndexURL.
type Source ¶
type Source interface {
Catalog(ctx context.Context) (*catalog.IndexedCatalog, error)
}
Source yields a full catalog.
func Release ¶
func Release(tag, cacheDir string, opts ...ReleaseOption) Source
Release is a relay-catalog GitHub release asset. tag "" resolves the newest release for Channel through the index on every call. A tag equal to EmbeddedVersion is served from the embedded catalog without fetching. Otherwise the asset is checked against its published sha256 and cached under cacheDir/<tag>; a cached tag is never fetched again because release tags are immutable. cacheDir "" disables the cache. The returned catalog's Version is the tag.