visitors

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package visitors counts unique daily visitors and persists the running total in the settings table, shared across instances.

Index

Constants

View Source
const (

	// OptOutCookie, when present, stops this browser being counted. The
	// privacy page sets it; counting relies on PECR's statistics exemption,
	// which requires a simple way to object.
	OptOutCookie = "afc_no_visit_count"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

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

Counter records visits locally and flushes them to the database.

func New

func New(store SettingStore, interval time.Duration, cookieDomain string) *Counter

func (*Counter) Count

func (c *Counter) Count() int

Count is the last known total across all instances.

func (*Counter) Flush

func (c *Counter) Flush(ctx context.Context)

Flush adds pending visits to the database total, or, with nothing pending, re-reads the total so this instance sees other instances' visits.

func (*Counter) Middleware

func (c *Counter) Middleware(next echo.HandlerFunc) echo.HandlerFunc

Middleware counts a visit the first time a browser is seen in 24 hours, unless it has opted out.

func (*Counter) Record

func (c *Counter) Record(visitorID string)

Record counts visitorID once per hour-long cache window.

func (*Counter) Start

func (c *Counter) Start(ctx context.Context)

Start seeds the total from the database and flushes every interval until Stop.

func (*Counter) Stop

func (c *Counter) Stop()

Stop ends the flusher. It is safe to call more than once.

type SettingStore

type SettingStore interface {
	GetSetting(ctx context.Context, settingID string) (setting.Setting, error)
	IncrementSetting(ctx context.Context, settingID string, delta int) (setting.Setting, error)
}

SettingStore persists the running total (satisfied by *setting.Store).

Jump to

Keyboard shortcuts

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