Skip to content

nrdcg/dnspod-go

 
 

Repository files navigation

DNSPod Go API client

Build Status PkgGoDev Go Report Card

A Go client for the DNSPod API.

Originally inspired by dnsimple


DNSPod is now a part of Tencent Cloud.

We recommend using https://github.com/tencentcloud/tencentcloud-sdk-go

https://github.com/TencentCloud/tencentcloud-sdk-go/tree/master/tencentcloud/dnspod


Getting Started

This library is a Go client you can use to interact with the DNSPod API.

package main

import (
	"fmt"
	"log"

	"github.com/nrdcg/dnspod-go"
)

func main() {
	apiToken := "xxxxx"

	params := dnspod.CommonParams{LoginToken: apiToken, Format: "json"}
	client := dnspod.NewClient(params)

	// Get a list of your domains
	domains, _, _ := client.Domains.List()
	for _, domain := range domains {
		fmt.Printf("Domain: %s (id: %s)\n", domain.Name, domain.ID)
	}

	// Get a list of your domains (with error management)
	domains, _, err := client.Domains.List()
	if err != nil {
		log.Fatalln(err)
	}
	for _, domain := range domains {
		fmt.Printf("Domain: %s (id: %s)\n", domain.Name, domain.ID)
	}

	// Create a new Domain
	newDomain := dnspod.Domain{Name: "example.com"}
	domain, _, _ := client.Domains.Create(newDomain)
	fmt.Printf("Domain: %s\n (id: %s)", domain.Name, domain.ID)
}

API documentation

License

This is Free Software distributed under the MIT license.