This is my implementation of golang support for the Hetzner Public DNS API. This project was part of a self-built ACME client implementation and it was needed to update DNS records of domains during the ACME Challenge.
Visit this page to generate a Hetzner Public DNS API Token.
Refer to the wiki tab in this repository for further examples.
package main
import (
"fmt"
"os"
"github.com/StarHack/go-hetzner-dns"
)
func main() {
h := hetzner.Hetzner{APIKey: "<your_api_key>"}
zones, err := h.FindAllZones()
if err != nil {
panic(err)
}
for _, zone := range zones {
fmt.Println(zone.Name)
}
zoneId, err := h.FindZoneID("example.com")
if err != nil {
panic(err)
}
h.CreateOrUpdateRecord(zoneId, "A", "www", "1.2.3.4")
h.CreateRecord(zoneId, "TXT", "_acme-challenge", "ABCD")
h.UpdateRecord(...)
h.DeleteRecord(...)
data, _ := h.ExportZoneFile("example.com")
os.WriteFile("zone.txt", data, 0755)
}
This is a Go project so download and install the latest version from https://go.dev/. Create a new directory test/
and create a file main.go
with above file content in it. We may then run the following to init and build the project:
go mod init test
go get
go build
./test
As of today, the current version of Hetzner DNS Public API is 1.1.1
. So far, the following core features were implemented. A couple of features such as pagination are still missing but the basic functionality for all of the provided endpoints is there.
- Auth-API-Token
- Get All Zones
- Create Zone
- Get Zone
- Update Zone
- Delete Zone
- Import Zone file plain
- Export Zone file
- Validate Zone file plain
- Get All Records
- Create Record
- Get Record
- Update Record
- Delete Record
- Bulk Create Records
- Bulk Update Records
The following endpoints were implemented but not tested yet.
- Get All Primary Servers
- Create Primary Server
- Get Primary Server
- Update Primary Server
- Delete Primary Server