notfoundlog

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusNew     = "new"
	StatusIgnored = "ignored"
	StatusAll     = "all"
)

The paths a list shows (Filter.Status).

Variables

View Source
var Assets embed.FS

Assets - the module's templates/ and static/, built into the binary (modules.Assets, paths.SetModuleAssets): a site runs without the module's source directory.

Functions

func RegisterRoutes

func RegisterRoutes(r modulekit.Mux, c *Controller, admin func(http.Handler) http.Handler)

RegisterRoutes registers the log, its actions and its settings (behind admin, like the Redirects page).

func Wire

func Wire(d modulekit.Deps) modulekit.Parts

Wire - the listener logging the 404s, the job forgetting the old and redirected paths, the count by the Redirects menu item and on the tab, the log's pages.

Types

type Controller

type Controller struct {
	*modulekit.BaseController
	// contains filtered or unexported fields
}

Controller - the log (a tab of the Redirects page) and its settings.

func NewController

func NewController(base *modulekit.BaseController, repo *Repo, recorder *Recorder, redirects modulekit.RedirectService) *Controller

NewController creates a Controller.

func (*Controller) Clear

func (c *Controller) Clear(w http.ResponseWriter, r *http.Request)

Clear handles POST /admin/config/redirects/not-found/clear: every path forgotten (the redirects and the settings stay).

func (*Controller) Ignore

func (c *Controller) Ignore(w http.ResponseWriter, r *http.Request)

Ignore handles POST …/{id}/ignore and …/{id}/restore: the path leaves the new ones, or comes back to them.

func (*Controller) List

func (c *Controller) List(w http.ResponseWriter, r *http.Request)

List renders GET /admin/config/redirects/not-found: the paths the filter (a part of the path; new, ignored or all) shows, the most asked for first; a path a redirect answers now is left out.

func (*Controller) Redirect

func (c *Controller) Redirect(w http.ResponseWriter, r *http.Request)

Redirect handles POST /admin/config/redirects/not-found/{id}/redirect: a redirect (the site's, on the Redirects page too) from the path to the address given; the path leaves the log.

func (*Controller) Settings

func (c *Controller) Settings(w http.ResponseWriter, r *http.Request)

Settings renders GET /admin/config/redirects/not-found/settings and saves it (POST): how long paths are kept, the menu's count, the paths never logged.

type Filter

type Filter struct {
	Q      string
	Status string
}

Filter - what the list shows: Q - a part of the path; Status - the new ones (the default), the ignored ones, or all.

type Path

type Path struct {
	ID        int
	Path      string
	Hits      int
	FirstSeen time.Time
	LastSeen  time.Time
	Referrer  string
	Ignored   bool
}

Path - a path the site answered 404 to: how many times, when first and last, where the last visitor came from; Ignored - not among the new.

type Recorder

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

Recorder logs the paths answered 404 (modulekit.OnNotFound) while the module is on, skipping the ignore patterns, and forgets the old ones.

func NewRecorder

func NewRecorder(repo *Repo, redirects modulekit.RedirectService, logger *slog.Logger) *Recorder

NewRecorder creates a Recorder.

func (*Recorder) CountNew

func (r *Recorder) CountNew(ctx context.Context) (int, error)

CountNew - the number by the Redirects menu item (the core's, shown with the module off too): the new paths, while the module is on and the settings show it.

func (*Recorder) Ignored

func (r *Recorder) Ignored(ctx context.Context, path string) bool

Ignored - whether path matches an ignore pattern.

func (*Recorder) Purge

func (r *Recorder) Purge(ctx context.Context) error

Purge forgets the paths not asked for longer than the settings keep them, and those a redirect answers now - the module's background job.

func (*Recorder) Record

func (r *Recorder) Record(ctx context.Context, path, referrer string)

Record logs a request answered 404 (the listener of modulekit.OnNotFound). Its failure is logged: the answer is given.

func (*Recorder) Redirected

func (r *Recorder) Redirected(path string) bool

Redirected - whether a redirect answers path now.

func (*Recorder) SaveSettings

func (r *Recorder) SaveSettings(ctx context.Context, st Settings) error

SaveSettings saves the settings.

func (*Recorder) Settings

func (r *Recorder) Settings(ctx context.Context) Settings

Settings returns the module's settings (kept in memory once read).

type Repo

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

Repo - the module's tables.

func NewRepo

func NewRepo(db *sql.DB) *Repo

NewRepo creates a Repo on db, in the repositories' dialect.

func (*Repo) ByID

func (r *Repo) ByID(ctx context.Context, id int) (Path, error)

ByID returns a path.

func (*Repo) Clear

func (r *Repo) Clear(ctx context.Context) (int, error)

Clear forgets every path; returns how many.

func (*Repo) CountNew

func (r *Repo) CountNew(ctx context.Context) (int, error)

CountNew - how many paths are new (not ignored).

func (*Repo) Delete

func (r *Repo) Delete(ctx context.Context, id int) error

Delete forgets a path (a redirect now answers it).

func (*Repo) Hit

func (r *Repo) Hit(ctx context.Context, path, referrer string, now time.Time) error

Hit counts a request answered 404 to path: a new path is added (while the log has fewer than maxPaths), a known one gets one more hit, now as its last, referrer as its last source.

func (*Repo) List

func (r *Repo) List(ctx context.Context, f Filter, limit, offset int) ([]Path, int, error)

List returns the paths the filter shows, the most asked for first, a page at a time, with how many there are.

func (*Repo) Purge

func (r *Repo) Purge(ctx context.Context, before time.Time, redirected func(path string) bool) (int, error)

Purge forgets the paths not asked for since before, and the ones answered by a redirect now (redirected); returns how many.

func (*Repo) SaveSettings

func (r *Repo) SaveSettings(ctx context.Context, s Settings) error

SaveSettings saves the module's settings.

func (*Repo) SetIgnored

func (r *Repo) SetIgnored(ctx context.Context, id int, ignored bool) error

SetIgnored marks a path ignored or new again.

func (*Repo) Settings

func (r *Repo) Settings(ctx context.Context) (Settings, error)

Settings returns the module's settings (the defaults until saved).

type Settings

type Settings struct {
	KeepDays  int
	ShowCount bool
	Ignore    []string
}

Settings - the module's settings: KeepDays - a path not asked for longer is forgotten; ShowCount - the count by the Redirects menu item; Ignore - the patterns of paths never logged.

Directories

Path Synopsis
ent
Package ent - the 404 log module's own ent schema (schema/), its generated client (generated/, go generate) and migration files (migrations/<dialect>/, scripts/migrations_gen.sh writes them), apart from the core's: the module's set of migrations (Schema).
Package ent - the 404 log module's own ent schema (schema/), its generated client (generated/, go generate) and migration files (migrations/<dialect>/, scripts/migrations_gen.sh writes them), apart from the core's: the module's set of migrations (Schema).
schema
Package schema - the 404 log module's own ent schema: the paths asked for and not found, and the module's settings.
Package schema - the 404 log module's own ent schema: the paths asked for and not found, and the module's settings.
Package manifest declares the 404 log module (its registry entry): the paths visitors asked for and the site didn't find, with a redirect made from any of them in a click.
Package manifest declares the 404 log module (its registry entry): the paths visitors asked for and the site didn't find, with a redirect made from any of them in a click.

Jump to

Keyboard shortcuts

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