store

package
v1.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package store persists crawl reports to disk and reads them back, so crawls can be listed, reopened, and compared over time. A report is already a complete, self-contained JSON artifact (see internal/report), so the store is a thin filesystem layer over it: one JSON file per crawl, laid out by host and timestamp.

Layout:

<root>/<host>/<timestamp>.json

e.g. ~/.gocrawl/crawls/example.com/20260630T120000Z.json. The crawl ID is the "<host>/<timestamp>" stem — sortable (newest = lexicographically greatest) and readable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultRoot

func DefaultRoot() string

DefaultRoot is the store directory used when none is configured: ~/.gocrawl/crawls, or ./.gocrawl/crawls if the home directory can't be determined.

Types

type Entry

type Entry struct {
	ID           string         `json:"id"`
	Host         string         `json:"host"`
	Seed         string         `json:"seed"`
	FinishedAt   string         `json:"finished_at"`
	PagesCrawled int            `json:"pages_crawled"`
	BySeverity   map[string]int `json:"by_severity"`
	// ByStatus, SitemapTotal and SitemapFetched let a crawl list draw a status tape and
	// sitemap coverage per crawl without loading the report again.
	ByStatus       map[string]int `json:"pages_by_status,omitempty"`
	SitemapTotal   int            `json:"sitemap_total,omitempty"`
	SitemapFetched int            `json:"sitemap_fetched,omitempty"`
	// StatusClasses counts the report's coverage.tape per status class, so a saved crawl shows
	// the same classes the live tape did. Empty for reports saved before tapes were stored
	// (use ByStatus then).
	StatusClasses map[string]int `json:"status_classes,omitempty"`
	// TapePreview is crawler.TapePreview of the report's coverage.tape (at most 160
	// characters); empty for reports saved before tapes were stored.
	TapePreview string `json:"tape_preview,omitempty"`
	Path        string `json:"path"`
}

Entry is the metadata of one saved crawl, cheap to list without rendering the full report.

type Store

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

Store reads and writes crawl reports under a root directory.

func New

func New(dir string) *Store

New returns a Store rooted at dir. An empty dir uses DefaultRoot.

func (*Store) List

func (s *Store) List(host string) ([]Entry, error)

List returns every saved crawl, newest first. An optional host filters to one site (matched against the report seed's host); empty lists all.

func (*Store) Load

func (s *Store) Load(id string) (*report.Report, error)

Load reads the report stored under the given crawl ID ("<host>/<timestamp>").

func (*Store) Resolve

func (s *Store) Resolve(ref string) (*report.Report, string, error)

Resolve turns a user-supplied reference into a report. A ref may be:

  • a path to an existing JSON file (loaded directly, not from the store);
  • "latest" — the newest crawl in the store;
  • a bare host like "example.com" — that host's newest crawl;
  • a crawl ID "<host>/<timestamp>".

It returns the resolved report and the ID it resolved to (empty for a direct file path).

func (*Store) ResolveStored

func (s *Store) ResolveStored(ref string) (*report.Report, string, error)

ResolveStored resolves ref the way Resolve does, but only inside the store: "latest", a bare host, or a crawl ID. It never reads a file path. Callers that take refs from the network (the web API's compare endpoint) use it, so a request cannot make the server read an arbitrary JSON file from disk.

func (*Store) Root

func (s *Store) Root() string

Root returns the store's root directory.

func (*Store) Save

func (s *Store) Save(rep *report.Report) (string, error)

Save writes rep to the store and returns its crawl ID. The host comes from the report's seed and the timestamp from its StartedAt (falling back to FinishedAt, then now). The write is atomic: a failure partway through leaves any previously saved crawl at that path intact.

Jump to

Keyboard shortcuts

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