mirror of
https://github.com/AmanTahiliani/cloudflare-dns-updater.git
synced 2026-08-07 11:53:08 -04:00
Initial Commit
This commit is contained in:
34
main.go
Normal file
34
main.go
Normal file
@@ -0,0 +1,34 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user