downloaderconfig

package
v0.0.0-...-21ea6c5 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package downloaderconfig owns the on-disk + in-DB representation of the gitmap downloader configuration.

Slice 1 of the downloader feature only persists the config — actual download / install logic ships in later slices. Keeping the data layer isolated here means Slice 2 (aria2c installer + engine) and Slice 3 (download / download-unzip commands) can both depend on a stable Load() without re-implementing JSON parsing.

Storage model: a single JSON document under Setting[DownloaderConfig]. We deliberately do NOT introduce a new SettingTypes table — the existing Setting(Key TEXT PK, Value TEXT) shape from constants_settings.go is reused, and the type discriminator lives in code as constants.SettingType.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(doc Document) ([]byte, error)

Marshal serializes a Document with deterministic 2-space indent, matching the project's JSONIndent convention so files written back round-trip cleanly with the seed.

func SeedHash

func SeedHash(doc Document) string

SeedHash returns the SHA-256 of the canonical (re-marshaled) document. Hashing the re-marshaled form (not the raw bytes) means whitespace-only edits to the seed file do not falsely trigger a re-seed.

func Validate

func Validate(doc Document) error

Validate enforces the PascalCase + range rules. Required keys are checked first so error messages surface a missing key before a numeric range violation that may be a side effect.

Types

type DatabaseVersion

type DatabaseVersion struct {
	LastKnownVersion string `json:"LastKnownVersion"`
}

DatabaseVersion records the last gitmap version that touched the DB. Stored as a string so we can keep the literal "auto" sentinel in the shipped seed file and resolve it at apply-time to constants.Version.

type Document

type Document struct {
	DownloaderConfig DownloaderConfig `json:"DownloaderConfig"`
	DatabaseVersion  DatabaseVersion  `json:"DatabaseVersion"`
}

Document is the top-level Seedable-Config envelope. Field names are PascalCase to match the spec and the JSON file shipped under gitmap/data/downloader-config.json.

func Defaults

func Defaults() Document

Defaults returns a Document populated from the hard-coded constants. Used as the last-resort fallback when both the DB and the seed file are unavailable (e.g. first-run race before Migrate completes).

func LoadFile

func LoadFile(path string) (Document, error)

LoadFile reads + validates a Seedable-Config JSON file from disk. Used by `gitmap downloader-config <path>` and by the seeder.

func Parse

func Parse(raw []byte) (Document, error)

Parse validates a raw JSON byte slice and returns the typed Document.

type DownloaderConfig

type DownloaderConfig struct {
	PreferredDownloader string `json:"PreferredDownloader"`
	FallbackDownloader  string `json:"FallbackDownloader"`
	ParallelDownloads   int    `json:"ParallelDownloads"`
	SplitConnections    int    `json:"SplitConnections"`
	DefaultSplitSize    string `json:"DefaultSplitSize"`
	LargeFileSplitSize  string `json:"LargeFileSplitSize"`
	LargeFileThreshold  string `json:"LargeFileThreshold"`
	TinyFileThreshold   string `json:"TinyFileThreshold"`
	TinyFileSplitSize   string `json:"TinyFileSplitSize"`
	TinyFileSplits      int    `json:"TinyFileSplits"`
	AllowFallback       bool   `json:"AllowFallback"`
	OverwriteUserConfig bool   `json:"OverwriteUserConfig"`
}

DownloaderConfig is the per-downloader runtime config consumed by Slice 2 (aria2c installer + engine).

Jump to

Keyboard shortcuts

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