Help us shape the future of Go! Take the 2026 Go Developer Survey

changedetect

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package changedetect implements a content monitoring engine that detects changes on web pages using multiple diffing strategies and notifications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangeEvent

type ChangeEvent struct {
	URL         string    `json:"url"`
	Name        string    `json:"name"`
	OldHash     string    `json:"old_hash"`
	NewHash     string    `json:"new_hash"`
	OldLen      int       `json:"old_len"`
	NewLen      int       `json:"new_len"`
	DiffPercent float64   `json:"diff_percent"`
	DetectedAt  time.Time `json:"detected_at"`
	Details     string    `json:"details,omitempty"`
}

ChangeEvent represents a detected change.

type DiffType

type DiffType string

DiffType determines how changes are detected.

const (
	DiffHash     DiffType = "hash"     // SHA256 of full content.
	DiffText     DiffType = "text"     // Line-by-line text diff.
	DiffSelector DiffType = "selector" // CSS selector content only.
	DiffVisual   DiffType = "visual"   // Screenshot comparison.
)

type LogNotifier

type LogNotifier struct {
	Logger *slog.Logger
}

LogNotifier logs changes to slog.

func (*LogNotifier) Name

func (n *LogNotifier) Name() string

func (*LogNotifier) Notify

func (n *LogNotifier) Notify(ctx context.Context, event ChangeEvent) error

type Monitor

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

Monitor tracks changes on a set of URLs.

func NewMonitor

func NewMonitor(dbPath string, logger *slog.Logger) (*Monitor, error)

NewMonitor creates a change detection monitor.

func (*Monitor) AddNotifier

func (m *Monitor) AddNotifier(n Notifier)

AddNotifier registers a notification channel.

func (*Monitor) AddWatch

func (m *Monitor) AddWatch(cfg WatchConfig) error

AddWatch adds a URL to monitor.

func (*Monitor) Close

func (m *Monitor) Close() error

Close closes the monitor database.

func (*Monitor) GetChanges

func (m *Monitor) GetChanges(url string, limit int) ([]ChangeEvent, error)

GetChanges returns detected changes for a URL.

func (*Monitor) GetHistory

func (m *Monitor) GetHistory(url string, limit int) ([]Snapshot, error)

GetHistory returns recent snapshots for a URL.

func (*Monitor) RecordSnapshot

func (m *Monitor) RecordSnapshot(ctx context.Context, url string, content []byte, statusCode int) (*ChangeEvent, error)

RecordSnapshot stores a new content snapshot and checks for changes.

type Notifier

type Notifier interface {
	Notify(ctx context.Context, event ChangeEvent) error
	Name() string
}

Notifier sends change notifications.

type Snapshot

type Snapshot struct {
	ID          string    `json:"id"`
	WatchURL    string    `json:"watch_url"`
	ContentHash string    `json:"content_hash"`
	ContentLen  int       `json:"content_len"`
	StatusCode  int       `json:"status_code"`
	CapturedAt  time.Time `json:"captured_at"`
}

Snapshot holds a point-in-time capture of a URL's content.

type WatchConfig

type WatchConfig struct {
	URL      string            `json:"url" yaml:"url"`
	Interval time.Duration     `json:"interval" yaml:"interval"`
	DiffType DiffType          `json:"diff_type" yaml:"diff_type"`
	Selector string            `json:"selector,omitempty" yaml:"selector,omitempty"` // For selector diff.
	Name     string            `json:"name,omitempty" yaml:"name,omitempty"`
	Headers  map[string]string `json:"headers,omitempty" yaml:"headers,omitempty"`
}

WatchConfig defines a single URL to watch.

type WebhookNotifier

type WebhookNotifier struct {
	URL     string
	Headers map[string]string
}

WebhookNotifier sends change events to a webhook URL.

func (*WebhookNotifier) Name

func (n *WebhookNotifier) Name() string

func (*WebhookNotifier) Notify

func (n *WebhookNotifier) Notify(ctx context.Context, event ChangeEvent) error

Jump to

Keyboard shortcuts

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