README.md
1# DNSPod Go API client
2
3[![Build Status](https://travis-ci.com/nrdcg/dnspod-go.svg?branch=master)](https://travis-ci.com/nrdcg/dnspod-go)
4[![GoDoc](https://godoc.org/github.com/nrdcg/dnspod-go?status.svg)](https://godoc.org/github.com/nrdcg/dnspod-go)
5[![Go Report Card](https://goreportcard.com/badge/github.com/nrdcg/dnspod-go)](https://goreportcard.com/report/github.com/nrdcg/dnspod-go)
6
7A Go client for the [DNSPod API](https://www.dnspod.cn/docs/index.html).
8
9Originally inspired by [dnsimple](https://github.com/weppos/dnsimple-go/dnsimple)
10
11## Getting Started
12
13This library is a Go client you can use to interact with the [DNSPod API](https://www.dnspod.cn/docs/index.html).
14
15```go
16package main
17
18import (
19 "fmt"
20 "log"
21
22 "github.com/nrdcg/dnspod-go"
23)
24
25func main() {
26 apiToken := "xxxxx"
27
28 params := dnspod.CommonParams{LoginToken: apiToken, Format: "json"}
29 client := dnspod.NewClient(params)
30
31 // Get a list of your domains
32 domains, _, _ := client.Domains.List()
33 for _, domain := range domains {
34 fmt.Printf("Domain: %s (id: %d)\n", domain.Name, domain.ID)
35 }
36
37 // Get a list of your domains (with error management)
38 domains, _, err := client.Domains.List()
39 if err != nil {
40 log.Fatalln(err)
41 }
42 for _, domain := range domains {
43 fmt.Printf("Domain: %s (id: %d)\n", domain.Name, domain.ID)
44 }
45
46 // Create a new Domain
47 newDomain := dnspod.Domain{Name: "example.com"}
48 domain, _, _ := client.Domains.Create(newDomain)
49 fmt.Printf("Domain: %s\n (id: %d)", domain.Name, domain.ID)
50}
51```
52
53## License
54
55This is Free Software distributed under the MIT license.
56