Last active
August 29, 2015 14:01
-
-
Save nesv/e0dd1f7c4e39820b7d23 to your computer and use it in GitHub Desktop.
An example on how to use the go-dynect/dynect package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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