Documentation
¶
Overview ¶
Package changedetect implements a content monitoring engine that detects changes on web pages using multiple diffing strategies and notifications.
Index ¶
- type ChangeEvent
- type DiffType
- type LogNotifier
- type Monitor
- func (m *Monitor) AddNotifier(n Notifier)
- func (m *Monitor) AddWatch(cfg WatchConfig) error
- func (m *Monitor) Close() error
- func (m *Monitor) GetChanges(url string, limit int) ([]ChangeEvent, error)
- func (m *Monitor) GetHistory(url string, limit int) ([]Snapshot, error)
- func (m *Monitor) RecordSnapshot(ctx context.Context, url string, content []byte, statusCode int) (*ChangeEvent, error)
- type Notifier
- type Snapshot
- type WatchConfig
- type WebhookNotifier
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 LogNotifier ¶
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 ¶
NewMonitor creates a change detection monitor.
func (*Monitor) AddNotifier ¶
AddNotifier registers a notification channel.
func (*Monitor) AddWatch ¶
func (m *Monitor) AddWatch(cfg WatchConfig) error
AddWatch adds a URL to monitor.
func (*Monitor) GetChanges ¶
func (m *Monitor) GetChanges(url string, limit int) ([]ChangeEvent, error)
GetChanges returns detected changes for a URL.
func (*Monitor) GetHistory ¶
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 ¶
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