42 lines
761 B
Go
42 lines
761 B
Go
package main
|
|
|
|
import (
|
|
"DynDNS/env"
|
|
"DynDNS/hetzner"
|
|
"DynDNS/publicIp"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
env.LoadEnv()
|
|
|
|
ip, err := publicIp.ReadIp()
|
|
if err != nil {
|
|
fmt.Printf("Error getting IP: %v\n", err)
|
|
return
|
|
}
|
|
|
|
fmt.Printf("My IP is: %s\n", ip)
|
|
|
|
zoneNames := env.ReadZones()
|
|
fmt.Printf("Zones: %v\n", zoneNames)
|
|
|
|
token := os.Getenv("HETZNER_API_TOKEN")
|
|
zoneIds := hetzner.SendGetZones(token, zoneNames...)
|
|
fmt.Printf("Zone IDs: %v\n", zoneIds)
|
|
|
|
for _, zoneId := range zoneIds {
|
|
records := hetzner.SendGetRecords(token, zoneId)
|
|
for i := range records {
|
|
record := &records[i]
|
|
if record.Type == "A" {
|
|
fmt.Printf("Updating record: %s\n", record.Name)
|
|
record.Value = ip
|
|
}
|
|
}
|
|
|
|
hetzner.SendUpdateRecords(token, records)
|
|
}
|
|
}
|