Documentation
¶
Index ¶
- Constants
- Variables
- func RegisterRoutes(r modulekit.Mux, c *Controller, admin func(http.Handler) http.Handler)
- func Wire(d modulekit.Deps) modulekit.Parts
- type Controller
- func (c *Controller) Clear(w http.ResponseWriter, r *http.Request)
- func (c *Controller) Ignore(w http.ResponseWriter, r *http.Request)
- func (c *Controller) List(w http.ResponseWriter, r *http.Request)
- func (c *Controller) Redirect(w http.ResponseWriter, r *http.Request)
- func (c *Controller) Settings(w http.ResponseWriter, r *http.Request)
- type Filter
- type Path
- type Recorder
- func (r *Recorder) CountNew(ctx context.Context) (int, error)
- func (r *Recorder) Ignored(ctx context.Context, path string) bool
- func (r *Recorder) Purge(ctx context.Context) error
- func (r *Recorder) Record(ctx context.Context, path, referrer string)
- func (r *Recorder) Redirected(path string) bool
- func (r *Recorder) SaveSettings(ctx context.Context, st Settings) error
- func (r *Recorder) Settings(ctx context.Context) Settings
- type Repo
- func (r *Repo) ByID(ctx context.Context, id int) (Path, error)
- func (r *Repo) Clear(ctx context.Context) (int, error)
- func (r *Repo) CountNew(ctx context.Context) (int, error)
- func (r *Repo) Delete(ctx context.Context, id int) error
- func (r *Repo) Hit(ctx context.Context, path, referrer string, now time.Time) error
- func (r *Repo) List(ctx context.Context, f Filter, limit, offset int) ([]Path, int, error)
- func (r *Repo) Purge(ctx context.Context, before time.Time, redirected func(path string) bool) (int, error)
- func (r *Repo) SaveSettings(ctx context.Context, s Settings) error
- func (r *Repo) SetIgnored(ctx context.Context, id int, ignored bool) error
- func (r *Repo) Settings(ctx context.Context) (Settings, error)
- type Settings
Constants ¶
const ( StatusNew = "new" StatusIgnored = "ignored" StatusAll = "all" )
The paths a list shows (Filter.Status).
Variables ¶
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 ¶
RegisterRoutes registers the log, its actions and its settings (behind admin, like the Redirects page).
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 ¶
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 ¶
NewRecorder creates a Recorder.
func (*Recorder) CountNew ¶
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) Purge ¶
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 ¶
Record logs a request answered 404 (the listener of modulekit.OnNotFound). Its failure is logged: the answer is given.
func (*Recorder) Redirected ¶
Redirected - whether a redirect answers path now.
func (*Recorder) SaveSettings ¶
SaveSettings saves the settings.
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
Repo - the module's tables.
func (*Repo) Hit ¶
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 ¶
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 ¶
SaveSettings saves the module's settings.
func (*Repo) SetIgnored ¶
SetIgnored marks a path ignored or new again.
Directories
¶
| Path | Synopsis |
|---|---|
|
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. |