Documentation
¶
Overview ¶
Package webserver exposes gocrawl over HTTP: an API to start and inspect crawls, backed by the same runner.Run seam the CLI and MCP server use, plus the embedded single-page app (see assets.go) that drives it from a browser.
Each feature registers its routes from its own file (crawls.go, sitemap.go, compare.go, import.go, redirects.go, settings.go, profiles.go, login.go), so features can be added without editing each other's handlers.
Index ¶
Constants ¶
const DefaultMaxRunning = 4
DefaultMaxRunning is the crawl-concurrency cap applied when WithMaxRunning isn't given.
const ( // StaleLoginProfileAge is how long a login window's throwaway browser profile must have // been untouched before SweepStaleLoginProfiles removes it. StaleLoginProfileAge = time.Hour )
Variables ¶
This section is empty.
Functions ¶
func DefaultGUISettingsPath ¶
func DefaultGUISettingsPath() string
DefaultGUISettingsPath is ~/.gocrawl/gui.json, next to the crawl store and header profiles.
func SweepStaleLoginProfiles ¶
SweepStaleLoginProfiles removes login-window profile directories (render.LoginProfilePrefix) in dir that were last modified more than maxAge ago: profiles a killed server (SIGKILL, crash) never got to delete. Only real directories are removed: a symlink with the prefix is left alone, and so is whatever it points at. Nothing else in dir is touched. Errors are ignored; this is housekeeping. gocrawl serve calls it once at startup, not New, so tests and embedders never sweep a temp directory they didn't ask about.
Types ¶
type GUISettings ¶
type GUISettings struct {
Theme string `json:"theme"` // "dark" (default) | "light" | "system"
CrawlDefaults crawlrequest.Params `json:"crawl_defaults"`
}
GUISettings is what the web UI keeps between launches, in gui.json. The UI is served from a different port on every desktop launch, so nothing may live in localStorage. It never holds a secret: see stripSecrets.
type Job ¶
type Job[T any] struct { ID string Status Status Err string StartedAt time.Time FinishedAt time.Time Data T // contains filtered or unexported fields }
Job is one background job started through the web API. The lifecycle fields are shared by every kind of job; Data holds what is specific to one kind (crawlJob, redirectJob).
type JobView ¶
type JobView struct {
ID string `json:"id"`
Seed string `json:"seed"`
Status string `json:"status"`
Err string `json:"error,omitempty"`
StartedAt string `json:"started_at,omitempty"`
FinishedAt string `json:"finished_at,omitempty"`
Persisted bool `json:"persisted"`
Report *report.Report `json:"report,omitempty"`
Progress *progressView `json:"progress,omitempty"`
}
JobView is the API representation of a crawl job.
type Option ¶ added in v0.9.0
type Option func(*Server)
Option configures a Server.
func AllowAnyHost ¶ added in v0.9.0
func AllowAnyHost() Option
AllowAnyHost disables the loopback Host-header check. gocrawl serve applies it when the operator deliberately binds to a non-loopback address, at which point the server is reachable from other machines by design and the Host header can legitimately be anything.
func WithGUISettingsPath ¶
WithGUISettingsPath sets the file GET and PUT /api/settings read and write (gocrawl serve passes ~/.gocrawl/gui.json, see DefaultGUISettingsPath). An empty path, the default, means settings are not stored: GET returns the defaults and PUT answers 503. Declared by wave 0.
func WithLoginBrowser ¶
func WithLoginBrowser(b loginBrowser) Option
WithLoginBrowser replaces the Chromium launcher behind /api/login-sessions; tests pass a fake.
func WithMaxRunning ¶ added in v0.9.0
WithMaxRunning caps the number of crawls that may run at once; POST /api/crawls returns 429 once the cap is reached. n <= 0 leaves the default.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server serves the gocrawl web API and embedded frontend.
func New ¶
New builds a Server backed by st for crawl history (persisted via --save). By default it only answers requests whose Host header is a loopback address and runs at most DefaultMaxRunning crawls at once; see the Option values to change either.
func (*Server) Close ¶
func (s *Server) Close()
Close releases what the server holds outside its own memory: running and paused crawl and redirect-check jobs, and open login windows with their throwaway browser profiles. gocrawl serve calls it on shutdown, after the HTTP server has stopped; once Close has run, no login window can be opened.
Jobs are canceled, then Close waits up to closeGrace for them to finish, so runner.Run's deferred fetcher Close (the headless Chromium process) has run before the process exits.