How zebradil/cloudflare-dynamic-dns works
Main Components
• CLI Entry Point: Represent the main executable (main.go) which wires up the application.
• Command Modules: Under the “cmd” directory, include components like “cloudflare.go”, “ip.go”, and “cmd.go” that parse command line arguments and configure the operation mode (manual run vs. daemon mode).
• Configuration Layer: Show how configuration is loaded from various sources such as command line flags, a YAML configuration file (default location in $HOME), and environment variables.
• IP Address Detection Module: Highlight the process of obtaining the current IP address. This includes:
– Directly reading from a specified network interface.
– Running an external command (via functions in the internal/execext package) to fetch the IP.
• Cloudflare API Client: Represent the component that constructs and sends HTTP requests to Cloudflare’s API to update DNS records based on the detected IP.
• State Management: Include how the state file (if enabled) is used to avoid unnecessary API calls by persisting the last used IP.
• Deployment & Automation Components:
• Build & Release: Optionally include supporting scripts and configuration files (goreleaser configuration, Taskfile.yaml) that manage the building, releasing, and dependency management.
Relationships and Data Flow
• Processing Layer: Show the command module invoking the IP detection module. Clarify how the tool processes the selection rules for both IPv4 and IPv6.
• API Interaction: Illustrate that the processed IP is then used by the Cloudflare API client to make REST calls to update DNS records.
• Feedback/State Update: Show that, on success, the state file gets updated to store the current IP, preventing redundant Cloudflare API calls.
Important Architectural Patterns
• Modularity: Each functionality (command parsing, IP detection, API interaction) is separated into distinct modules (e.g., located in “cmd” and “internal” directories).
• Configuration Abstraction: The design supports multiple configuration mechanisms, making the tool flexible and deployable in different environments (manual run, Docker, systemd).
• Daemon vs. One-shot: Emphasize the dual mode of execution; the flow branches in daemon mode where a scheduler (systemd or --run-every in manual invocation) repeatedly invokes the tool.