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 ¶
- func DefaultRoot() string
- type Entry
- type Store
- func (s *Store) List(host string) ([]Entry, error)
- func (s *Store) Load(id string) (*report.Report, error)
- func (s *Store) Resolve(ref string) (*report.Report, string, error)
- func (s *Store) ResolveStored(ref string) (*report.Report, string, error)
- func (s *Store) Root() string
- func (s *Store) Save(rep *report.Report) (string, error)
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 (*Store) List ¶
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) Resolve ¶
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 ¶
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.