Skip to content

Instantly share code, notes, and snippets.

@nesv
Last active August 29, 2015 14:01
Show Gist options
  • Save nesv/e0dd1f7c4e39820b7d23 to your computer and use it in GitHub Desktop.
Save nesv/e0dd1f7c4e39820b7d23 to your computer and use it in GitHub Desktop.
An example on how to use the go-dynect/dynect package
package main
import (
"log"
"strings"
"github.com/nesv/go-dynect/dynect"
)
func main() {
// Create a new client.
dyn := dynect.NewClient("dynect-customer-name")
// Log in.
err := dyn.Login("username", "password")
if err != nil {
log.Fatalln(err)
}
// Defer the log out.
defer func() {
if err := dyn.Logout(); err != nil {
log.Fatalln(err)
}
}()
// Make a request to the API to get all of the zone URIs.
var zonesResponse dynect.ZonesResponse
if err := dyn.Do("GET", "Zone", nil, &zonesResponse); err != nil {
log.Println(err)
return
}
// For each zone URI, strip the "/REST/" prefix from the URI, then
// get a list of all records in the zone.
for _, zoneURI := range zonesResponse.Data {
uri := strings.TrimPrefix("/REST/", zoneURI)
var allRecords dynect.AllRecordsResponse
if err := dyn.Do("GET", uri, nil, &allRecords); err != nil {
log.Println(err)
return
}
// Print out all records in the zone.
log.Println(strings.TrimPrefix("/Zone/", uri))
for _, rec := range allRecords.Data {
log.Println("\t", rec)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment