mapscatalog

package
v0.13.3 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: GPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package mapscatalog fetches the public download catalog from the graywolf-maps Worker (GET <base>/manifest.json) and caches it in-process with a TTL. Stale-on-error: a refresh that fails after the catalog is warm continues serving the previous copy with a warning. A cold failure (no cached copy) returns the error.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache fetches and caches the worker catalog.

func New

func New(baseURL string, tokenProvider func(context.Context) string, ttl time.Duration) *Cache

New constructs a Cache. baseURL is the maps host root (e.g. https://maps.nw5w.com). tokenProvider returns the current bearer token (may be empty for public testing). ttl is the cache lifetime; 0 means always refresh.

func (*Cache) Get

func (c *Cache) Get(ctx context.Context) (Catalog, error)

Get returns the current catalog. Fresh fetch on miss or expired TTL. Stale-on-error after the first successful fetch. Concurrent callers who arrive while a fetch is in flight share the result rather than issuing duplicate upstream calls.

func (*Cache) Refresh

func (c *Cache) Refresh(ctx context.Context) (Catalog, error)

Refresh forces a fetch and updates the cache. Returns the new catalog and any error from the fetch (cache is unchanged on error).

type Catalog

type Catalog struct {
	SchemaVersion int        `json:"schemaVersion"`
	GeneratedAt   string     `json:"generatedAt"`
	Countries     []Country  `json:"countries"`
	Provinces     []Province `json:"provinces"`
	States        []State    `json:"states"`
	// contains filtered or unexported fields
}

func (*Catalog) HasSlug

func (c *Catalog) HasSlug(slug string) bool

HasSlug reports whether slug names a published archive in this catalog. Slugs are namespaced ("state/colorado", "country/de", "province/ca/british-columbia"). O(1) when the index is populated (every catalog returned by Cache.Get is); falls back to a linear scan for hand-constructed Catalog values where indexSlugs has not run.

type Country

type Country struct {
	ISO2      string      `json:"iso2"`
	Name      string      `json:"name"`
	SizeBytes int64       `json:"sizeBytes"`
	SHA256    string      `json:"sha256"`
	BBox      *[4]float64 `json:"bbox,omitempty"`
}

type Province

type Province struct {
	ISO2      string      `json:"iso2"`
	Slug      string      `json:"slug"`
	Name      string      `json:"name"`
	Code      string      `json:"code,omitempty"`
	SizeBytes int64       `json:"sizeBytes"`
	SHA256    string      `json:"sha256"`
	BBox      *[4]float64 `json:"bbox,omitempty"`
}

type State

type State struct {
	Slug      string      `json:"slug"`
	Name      string      `json:"name"`
	Code      string      `json:"code,omitempty"`
	SizeBytes int64       `json:"sizeBytes"`
	SHA256    string      `json:"sha256"`
	BBox      *[4]float64 `json:"bbox,omitempty"`
}

Jump to

Keyboard shortcuts

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