This file provides guidance to agents when working with code in this repository.
- Configuration is Global: Configuration is initialized in
cmd/knocker/main.gousingcobra.OnInitializeand is accessed globally viaviper.Get...()calls. There is no central config struct passed around. - Service Logic is Decoupled: The
kardianos/serviceimplementation is in theprogramstruct incmd/knocker/program.go. This is a thin wrapper that starts the main application logic, which resides entirely ininternal/service/service.go. - Graceful Shutdown: The service is stopped cleanly using a
quitchannel. This channel is created inprogram.Start, passed to the core service'sRunmethod, and closed inprogram.Stop. This is the only way to terminate the service loop. - Conditional IP Detection: The core function
checkAndKnock()ininternal/service/service.gohas two distinct behaviors. Ifip_check_urlis an empty string in the config, it simply "knocks" on the API. Otherwise, it fetches and compares the IP before knocking. This is a critical conditional branch. - Shared Logger: A single, shared logger for the
mainpackage is initialized in aPersistentPreRunfunction on therootCmdincmd/knocker/main.go. This makes theloggervariable globally available to all command files (e.g.,run.go,knock.go).
- Build:
go build -o knocker ./cmd/knocker - Test:
go test ./... - Install:
go install ./... - Run Foreground:
knocker run - Release (Cross-Platform):
goreleaser release --snapshot --clean
- Run Tests: After any significant code change, you must run the test suite with
go test ./...to ensure no regressions have been introduced. - Update Documentation: If you add or modify a feature, you must update the relevant documentation in
README.mdanddocs/architecture.mdto reflect the changes.