oracle-watchdog

wandns

import "github.com/afreidah/oracle-watchdog/internal/wandns"

Index

Variables

ErrAllProvidersFailed is returned when every configured detection provider failed to return a parseable IPv4 address on a single tick.

var ErrAllProvidersFailed = errors.New("all detection providers failed")

ErrTokenMissing is returned when the configured environment variable does not contain a Cloudflare API token at construction time.

var ErrTokenMissing = errors.New("cloudflare api token environment variable is empty")

type HTTPDoer

HTTPDoer narrows the *http.Client surface to the single Do method so tests can inject a custom round-tripper without standing up a server.

type HTTPDoer interface {
    // Do executes the request and returns its response.
    Do(req *http.Request) (*http.Response, error)
}

type Option

Option configures the Updater. Used to inject test doubles for the HTTP client, the base URL, the logger, and the token source.

type Option func(*Updater)

func WithBaseURL

func WithBaseURL(url string) Option

WithBaseURL overrides the Cloudflare API base URL. Used by tests to point at an httptest.Server.

func WithHTTPClient

func WithHTTPClient(c HTTPDoer) Option

WithHTTPClient overrides the default *http.Client.

func WithLogger

func WithLogger(l *slog.Logger) Option

WithLogger overrides the default scoped logger.

func WithToken

func WithToken(token string) Option

WithToken overrides the Cloudflare API token. When supplied, the env var named in cfg.Cloudflare.APITokenEnv is not consulted.

type Updater

Updater polls detection providers for the current WAN IP and updates a Cloudflare DNS A record when the value changes.

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

func New

func New(cfg config.WanDNSConfig, opts ...Option) (*Updater, error)

New constructs an Updater from the given config. Reads the Cloudflare token from the configured environment variable unless overridden via WithToken so missing-token errors surface at construction time rather than first poll.

func (*Updater) Run

func (u *Updater) Run(ctx context.Context)

Run drives the polling loop until ctx is cancelled. Performs an initial tick on entry so endpoint changes are picked up promptly after the updater starts.

Generated by gomarkdoc