Skip to content

aellwein/netcup-dns-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Workflow Status Go Report Card Codecov branch GitHub GitHub release (latest SemVer)

netcup-dns-api

Implementation for netcup DNS API in Golang.

All DNS API is implemented:

  • login
  • logout
  • infoDnsZone
  • infoDnsRecords
  • updateDnsZone
  • updateDnsRecords

Example Usage

import (
	"log"

	netcup "github.com/aellwein/netcup-dns-api/pkg/v1"
)

func main() {
	client := netcup.NewNetcupDnsClient(12345, "myApiKey", "mySecretApiPassword")

	// Login to the API
	session, err := client.Login()
	if err != nil {
		panic(err)
	}
	defer session.Logout()

	if zone, err := session.InfoDnsZone("myowndomain.org"); err != nil {
		panic(err)
	} else {
		log.Println("DNS zone:", zone)
	}
}

This should give you an output like:

DNS zone: { "DomainName": "myowndomain.org", "Ttl": "...", "Serial": "...", "Refresh": "...", "Retry": "...", "Expire": "...", "DnsSecStatus": false

Error Handling

Usually one would expect an err set only in case of a "hard" or non-recoverable error. This is true for a technical type of error, like failed REST API call or a broken network connection, but the Netcup API may set status to "error" in some cases, where you would rather assume a warning. In such case, the last response from Netcup API is preserved inside the NetcupSession and can be examined:

recs, err := session.InfoDnsRecords("myowndomain.org")
if err != nil {
	if session.LastResponse != nil && 
		sess.LastResponse.Status == string(netcup.StatusError) &&
		sess.LastResponse.StatusCode == 5029 {
			// no records are found in the DNS zone - Netcup indicates an error here.
			println("no error")
		} else {
			return fmt.Errorf("non-recoverable error on InfoDnsRecords: %v", err)
		}
}

License

MIT License