Skip to content
This repository has been archived by the owner on Aug 16, 2020. It is now read-only.

decker502/dnspod-go

Repository files navigation

停更通知

由于本项目维护不及时, lego 项目作者已经fork了本项目,单独维护了,建议使用 https://github.com/nrdcg/dnspod-go

dnspod-go

A Go client for the DNSPod API.

Borrowed from : dnsimple

Installation

$ go get github.com/decker502/dnspod-go

Getting Started

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

package main

import (
	"fmt"
	"log"

	"github.com/decker502/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: %d)\n", domain.Name, domain.ID)
	}

	// Get a list of your domains (with error management)
	domains, _, error := client.Domains.List()
	if error != nil {
		log.Fatalln(error)
	}
	for _, domain := range domains {
		fmt.Printf("Domain: %s (id: %d)\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: %d)", domain.Name, domain.ID)
}

License

This is Free Software distributed under the MIT license.