diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index dac1a20..bb32539 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -35,8 +35,10 @@ jobs: /go_cache key: go_path-${{ steps.hash-go.outputs.hash }} restore-keys: |- - go_cache-${{ steps.hash-go.outputs.hash }} + go_cache-${{ steps.hash-go.outputs.hash }} - name: build run: make build - name: test run: make test + - name: check:format + run: make check-format diff --git a/Makefile b/Makefile index 142723b..07246c5 100644 --- a/Makefile +++ b/Makefile @@ -6,3 +6,18 @@ build: lint: golint ./... + +run: + make build + ./realdyndns + +format: + gofmt -w . + +check-format: + @OUTPUT=$$(gofmt -l .); \ + if [ -n "$$OUTPUT" ]; then \ + echo "Formatter failed for:"; \ + echo "$$OUTPUT"; \ + exit 1; \ + fi diff --git a/main.go b/main.go index 477ce94..ca05c00 100644 --- a/main.go +++ b/main.go @@ -74,20 +74,20 @@ func main() { rdd := realDynDns.New(externalIpProvider, dnsProvider, notificationProvider, configClient.Domains) switch configClient.Mode { - case config.ScheduledMode: - schedule, job, err := rdd.RunWithSchedule(configClient.CheckInterval) - if err != nil { - panic(err) - } + case config.ScheduledMode: + schedule, job, err := rdd.RunWithSchedule(configClient.CheckInterval) + if err != nil { + panic(err) + } - fmt.Println("Starting scheduler") - fmt.Println("Next run:", job.NextRun()) - schedule.StartBlocking() - case config.RunOnceMode: - numberOfChanges, err := rdd.RunOnce() - if err != nil { - panic(err) - } - fmt.Println("Number of changes:", numberOfChanges) + fmt.Println("Starting scheduler") + fmt.Println("Next run:", job.NextRun()) + schedule.StartBlocking() + case config.RunOnceMode: + numberOfChanges, err := rdd.RunOnce() + if err != nil { + panic(err) + } + fmt.Println("Number of changes:", numberOfChanges) } } diff --git a/pkg/config/config.go b/pkg/config/config.go index 00560ee..2c2975d 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -18,8 +18,8 @@ type Config struct { } const ( - RunOnceMode = "RunOnce" - ScheduledMode = "Scheduled" + RunOnceMode = "RunOnce" + ScheduledMode = "Scheduled" ) type DomainConfig struct { @@ -56,7 +56,7 @@ func (c *Config) Load(filePath string) error { return fmt.Errorf("failed to validate config: %w", err) } - return nil; + return nil } func (c *Config) validate() error { @@ -68,5 +68,5 @@ func (c *Config) validate() error { return errors.New("check interval must be set when mode is 'Scheduled'") } - return nil; -} \ No newline at end of file + return nil +} diff --git a/pkg/dnsProvider/ionos/api/ionosAPI.go b/pkg/dnsProvider/ionos/api/ionosAPI.go index 351dd0d..3f3d543 100644 --- a/pkg/dnsProvider/ionos/api/ionosAPI.go +++ b/pkg/dnsProvider/ionos/api/ionosAPI.go @@ -123,7 +123,7 @@ func (i *IonosAPIImpl) GetRecordId(zoneId string, tld string, subdomain string, json.Unmarshal(responseBody, &zone) var domain string - if subdomain == "@" || subdomain == "" { + if subdomain == "@" || subdomain == "" { domain = tld } else { domain = subdomain + "." + tld @@ -171,8 +171,6 @@ func (i *IonosAPIImpl) SetARecord(tld string, subdomain string, ip net.IP, ttl i return nil, errors.New("error updating record") } - - changeRecord := ChangeRecord{} json.Unmarshal(responseBody, &changeRecord)