mirror of
https://github.com/AmanTahiliani/cloudflare-dns-updater.git
synced 2026-08-07 11:53:08 -04:00
35 lines
860 B
Go
35 lines
860 B
Go
|
|
package main
|
||
|
|
|
||
|
|
import "log"
|
||
|
|
|
||
|
|
func main() {
|
||
|
|
config, err := LoadConfig()
|
||
|
|
if err != nil {
|
||
|
|
log.Fatalf("Failed to load config: %v", err)
|
||
|
|
}
|
||
|
|
log.Printf("Config: %+v", config)
|
||
|
|
dnsUpdater := DnsUpdater{config: config}
|
||
|
|
for _, recordName := range config.RecordNames {
|
||
|
|
record, err := dnsUpdater.CheckIfRecordsExist(recordName)
|
||
|
|
if err != nil {
|
||
|
|
log.Fatalf("Failed to check if record exists: %v", err)
|
||
|
|
}
|
||
|
|
if record.Id != "" {
|
||
|
|
log.Printf("Record %s exists", recordName)
|
||
|
|
err = dnsUpdater.Update(record)
|
||
|
|
if err != nil {
|
||
|
|
log.Fatalf("Failed to update DNS: %v", err)
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
log.Printf("Record %s does not exist. Creating it.....", recordName)
|
||
|
|
err = dnsUpdater.Create(recordName)
|
||
|
|
if err != nil {
|
||
|
|
log.Fatalf("Failed to create DNS: %v", err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if err != nil {
|
||
|
|
log.Fatalf("Failed to update or create DNS: %v", err)
|
||
|
|
}
|
||
|
|
}
|