Documentation
¶
Overview ¶
Package guard implements a background daemon that detects port conflicts.
Index ¶
- func IsRunning() (running bool, pid int)
- func LogPath() string
- func OpenLog(path string) (*os.File, error)
- func PIDPath() string
- func ReadLogTail(path string, n int) ([]string, error)
- func ReadPID() (int, error)
- func RemovePID() error
- func RunDaemon(ctx context.Context, s scanner.PortScanner, watchPorts []uint16, ...) error
- func SendNotification(title, message string) error
- func Stop() error
- func WritePID() error
- type Event
- type EventKind
- type Notifier
- type Watcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadLogTail ¶
ReadLogTail returns the last n lines of the log file.
func RunDaemon ¶
func RunDaemon(ctx context.Context, s scanner.PortScanner, watchPorts []uint16, interval time.Duration, notify bool) error
RunDaemon runs the guard daemon in the foreground. It writes its PID file, sets up signal handling, and starts the watcher loop. Blocks until canceled.
func SendNotification ¶
SendNotification sends a desktop notification using notify-send on Linux. Falls back to logging if notify-send is not available.
Types ¶
type Event ¶
type Event struct {
OldProcess string
NewProcess string
Kind EventKind
Port uint16
OldPID int
NewPID int
}
Event describes a port conflict or takeover detected by the watcher.
type Watcher ¶
type Watcher struct {
Scanner scanner.PortScanner
WatchPorts []uint16
// contains filtered or unexported fields
}
Watcher polls the scanner and detects port changes between scans.
func NewWatcher ¶
func NewWatcher(s scanner.PortScanner, watchPorts []uint16) *Watcher
NewWatcher creates a Watcher. If watchPorts is empty, all ports are watched.
Click to show internal directories.
Click to hide internal directories.