A Go service that scans existing basemap tile directories and vector files, catalogues them in SQLite, issues scoped access tokens, and serves tiles and downloads to downstream systems. It deliberately does not generate or process raster data: GIS software produces the tiles, this service catalogues, authorises and distributes them. Capabilities - scans basemap tile directories (manifest-based or raw z/x/y) and vector assets (.geojson, .json, .zip, shapefiles with sidecars) - token auth with per-resource grants, expiry and coarse scopes (read, slice) - resource health inspection flags a moved or deleted tile root before a client hits a 404 - downstream push with exponential-backoff retries and manual re-queue - image slicing jobs driven by the GDAL bundled with QGIS, including VRT mosaicking so successive drone flights accumulate into one seamless layer - a narrow, non-admin slicing API for external callers: submit, poll, idempotent by job code, completion callback - ops console covering health, ledger, tokens, pushes, scans, slicing and service info - native Windows service install/start/stop with crash recovery, auto-start and a rotating log file, so no NSSM or WinSW wrapper is needed Verified with 49 tests plus live runs against real tile data and real GDAL.
94 lines
2.3 KiB
Go
94 lines
2.3 KiB
Go
package basemap
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
func LoadManifest(path string) (Manifest, error) {
|
|
content, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return Manifest{}, err
|
|
}
|
|
|
|
var item Manifest
|
|
if err := json.Unmarshal(content, &item); err != nil {
|
|
return Manifest{}, fmt.Errorf("decode manifest %s: %w", path, err)
|
|
}
|
|
|
|
item.Code = normalizeCode(item.Code)
|
|
item.Name = strings.TrimSpace(item.Name)
|
|
item.Type = defaultText(strings.TrimSpace(item.Type), "xyz")
|
|
item.Description = strings.TrimSpace(item.Description)
|
|
item.Version = strings.TrimSpace(item.Version)
|
|
item.Status = defaultText(strings.TrimSpace(item.Status), "ready")
|
|
item.TileFormat = normalizeTileFormat(item.TileFormat)
|
|
item.TileScheme = defaultText(strings.TrimSpace(item.TileScheme), "xyz")
|
|
item.Attribution = strings.TrimSpace(item.Attribution)
|
|
item.RootPath = strings.TrimSpace(item.RootPath)
|
|
if item.RootPath == "" {
|
|
item.RootPath = "tiles"
|
|
}
|
|
if item.MaxZoom < item.MinZoom {
|
|
return Manifest{}, fmt.Errorf("manifest %s has invalid zoom range", path)
|
|
}
|
|
if len(item.BBox) != 0 && len(item.BBox) != 4 {
|
|
return Manifest{}, fmt.Errorf("manifest %s has invalid bbox", path)
|
|
}
|
|
if item.Code == "" {
|
|
return Manifest{}, fmt.Errorf("manifest %s missing code", path)
|
|
}
|
|
if item.Name == "" {
|
|
item.Name = item.Code
|
|
}
|
|
if item.Version == "" {
|
|
item.Version = filepath.Base(filepath.Dir(path))
|
|
}
|
|
if item.Metadata == nil {
|
|
item.Metadata = map[string]any{}
|
|
}
|
|
return item, nil
|
|
}
|
|
|
|
func normalizeCode(value string) string {
|
|
value = strings.TrimSpace(strings.ToLower(value))
|
|
if value == "" {
|
|
return ""
|
|
}
|
|
var builder strings.Builder
|
|
lastDash := false
|
|
for _, r := range value {
|
|
switch {
|
|
case r >= 'a' && r <= 'z':
|
|
builder.WriteRune(r)
|
|
lastDash = false
|
|
case r >= '0' && r <= '9':
|
|
builder.WriteRune(r)
|
|
lastDash = false
|
|
case r == '_' || r == '-' || r == '.' || r == ' ':
|
|
if builder.Len() > 0 && !lastDash {
|
|
builder.WriteByte('-')
|
|
lastDash = true
|
|
}
|
|
}
|
|
}
|
|
return strings.Trim(builder.String(), "-")
|
|
}
|
|
|
|
func normalizeTileFormat(value string) string {
|
|
value = strings.TrimSpace(strings.ToLower(value))
|
|
switch value {
|
|
case "jpg", "jpeg":
|
|
return "jpg"
|
|
case "png", "webp", "pbf":
|
|
return value
|
|
case "":
|
|
return "png"
|
|
default:
|
|
return value
|
|
}
|
|
}
|