dnspod

package module
v0.0.0-...-62c9140 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2018 License: MIT Imports: 9 Imported by: 0

README

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.

Documentation

Overview

Package dnspod implements a client for the dnspod API.

In order to use this package you will need a dnspod account and your API Token.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if the status code is different than 2xx. Specific requests may have additional requirements, but this is sufficient in most of the cases.

Types

type Client

type Client struct {
	// HTTP client used to communicate with the API.
	HttpClient *http.Client

	// CommonParams used communicating with the dnspod API.
	CommonParams CommonParams

	// Base URL for API requests.
	// Defaults to the public dnspod API, but can be set to a different endpoint (e.g. the sandbox).
	// BaseURL should always be specified with a trailing slash.
	BaseURL string

	// User agent used when communicating with the dnspod API.
	UserAgent string

	// Services used for talking to different parts of the dnspod API.
	Domains *DomainsService
}

func NewClient

func NewClient(CommonParams CommonParams) *Client

NewClient returns a new dnspod API client.

func (*Client) Do

func (c *Client) Do(method, path string, payload url.Values, v interface{}) (*Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to decode it.

func (*Client) NewRequest

func (client *Client) NewRequest(method, path string, payload url.Values) (*http.Request, error)

NewRequest creates an API request. The path is expected to be a relative path and will be resolved according to the BaseURL of the Client. Paths should always be specified without a preceding slash.

type CommonParams

type CommonParams struct {
	LoginToken   string
	Format       string
	Lang         string
	ErrorOnEmpty string
	UserID       string
}

type Date

type Date struct {
	time.Time
}

Date custom type.

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(data []byte) error

UnmarshalJSON handles the deserialization of the custom Date type.

type Domain

type Domain struct {
	ID               string `json:"id,omitempty"`
	Name             string `json:"name,omitempty"`
	PunyCode         string `json:"punycode,omitempty"`
	Grade            string `json:"grade,omitempty"`
	GradeTitle       string `json:"grade_title,omitempty"`
	Status           string `json:"status,omitempty"`
	ExtStatus        string `json:"ext_status,omitempty"`
	Records          string `json:"records,omitempty"`
	GroupID          string `json:"group_id,omitempty"`
	IsMark           string `json:"is_mark,omitempty"`
	Remark           string `json:"remark,omitempty"`
	IsVIP            string `json:"is_vip,omitempty"`
	SearchenginePush string `json:"searchengine_push,omitempty"`
	UserID           string `json:"user_id,omitempty"`
	CreatedOn        string `json:"created_on,omitempty"`
	UpdatedOn        string `json:"updated_on,omitempty"`
	TTL              string `json:"ttl,omitempty"`
	CNameSpeedUp     string `json:"cname_speedup,omitempty"`
	Owner            string `json:"owner,omitempty"`
	AuthToAnquanBao  bool   `json:"auth_to_anquanbao,omitempty"`
}

func (Domain) String

func (d Domain) String() string

type DomainInfo

type DomainInfo struct {
	DomainTotal   int `json:"domain_total,omitempty"`
	AllTotal      int `json:"all_total,omitempty"`
	MineTotal     int `json:"mine_total,omitempty"`
	ShareTotal    int `json:"share_total,omitempty"`
	VipTotal      int `json:"vip_total,omitempty"`
	IsMarkTotal   int `json:"ismark_total,omitempty"`
	PauseTotal    int `json:"pause_total,omitempty"`
	ErrorTotal    int `json:"error_total,omitempty"`
	LockTotal     int `json:"lock_total,omitempty"`
	SpamTotal     int `json:"spam_total,omitempty"`
	VipExpire     int `json:"vip_expire,omitempty"`
	ShareOutTotal int `json:"share_out_total,omitempty"`
	RecentTotal   int `json:"recent_total,omitempty"`
}

type DomainQuery

type DomainQuery struct {
	Type        string `json:"type,omitempty"`
	CurrentPage int    `json:"currentPage,omitempty"`
	PageSize    int    `json:"pageSize,omitempty"`
	GroupId     string `json:"groupId,omitempty"`
	Keyword     string `json:"keyword,omitempty"`
}

type DomainsService

type DomainsService struct {
	// contains filtered or unexported fields
}

DomainsService handles communication with the domain related methods of the dnspod API.

dnspod API docs: https://www.dnspod.cn/docs/domains.html

func (*DomainsService) Create

func (s *DomainsService) Create(domainAttributes Domain) (Domain, *Response, error)

Create a new domain.

dnspod API docs: https://www.dnspod.cn/docs/domains.html#domain-create

func (*DomainsService) CreateRecord

func (s *DomainsService) CreateRecord(domain string, recordAttributes Record) (Record, *Response, error)

CreateRecord creates a domain record.

dnspod API docs: https://www.dnspod.cn/docs/records.html#record-create

func (*DomainsService) Delete

func (s *DomainsService) Delete(ID int) (*Response, error)

Delete a domain.

dnspod API docs: https://dnsapi.cn/Domain.Remove

func (*DomainsService) DeleteRecord

func (s *DomainsService) DeleteRecord(domain string, recordID string) (*Response, error)

DeleteRecord deletes a domain record.

dnspod API docs: https://www.dnspod.cn/docs/records.html#record-remove

func (*DomainsService) Get

func (s *DomainsService) Get(ID int) (Domain, *Response, error)

Get fetches a domain.

dnspod API docs: https://www.dnspod.cn/docs/domains.html#domain-info

func (*DomainsService) GetRecord

func (s *DomainsService) GetRecord(domain string, recordID string) (Record, *Response, error)

GetRecord fetches the domain record.

dnspod API docs: https://www.dnspod.cn/docs/records.html#record-info

func (*DomainsService) GetRecordLine

func (s *DomainsService) GetRecordLine(domainGrade string, domainID string) ([]RecordLine, *Response, error)

func (*DomainsService) GetUserInfo

func (s *DomainsService) GetUserInfo() (User, *Response, error)

func (*DomainsService) List

List the domains.

dnspod API docs: https://www.dnspod.cn/docs/domains.html#domain-list

func (*DomainsService) ListRecords

func (s *DomainsService) ListRecords(query RecordQuery) (PaginationRecordList, *Response, error)

func (*DomainsService) UpdateRecord

func (s *DomainsService) UpdateRecord(domain string, recordID string, recordAttributes Record) (Record, *Response, error)

UpdateRecord updates a domain record.

dnspod API docs: https://www.dnspod.cn/docs/records.html#record-modify

func (*DomainsService) UpdateRecordStatus

func (s *DomainsService) UpdateRecordStatus(domainID string, recordID string, status string) (*Response, error)

func (*DomainsService) UpdateStatus

func (s *DomainsService) UpdateStatus(id string, status string) (*Response, error)

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response // HTTP response that caused this error
	Message  string         `json:"message"` // human-readable message
}

An ErrorResponse represents an error caused by an API request.

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

Error implements the error interface.

type PaginationDomainList

type PaginationDomainList struct {
	CurrentPage int      `json:"currentPage"`
	PageSize    int      `json:"pageSize"`
	Total       int      `json:"total"`
	List        []Domain `json:"list"`
}

type PaginationRecordList

type PaginationRecordList struct {
	CurrentPage int      `json:"currentPage"`
	PageSize    int      `json:"pageSize"`
	Total       int      `json:"total"`
	List        []Record `json:"list"`
}

type Record

type Record struct {
	ID            string `json:"id,omitempty"`
	Name          string `json:"name,omitempty"`
	Line          string `json:"line,omitempty"`
	LineID        string `json:"line_id,omitempty"`
	Type          string `json:"type,omitempty"`
	TTL           string `json:"ttl,omitempty"`
	Value         string `json:"value,omitempty"`
	MX            string `json:"mx,omitempty"`
	Enabled       string `json:"enabled,omitempty"`
	Status        string `json:"status,omitempty"`
	MonitorStatus string `json:"monitor_status,omitempty"`
	Remark        string `json:"remark,omitempty"`
	UpdateOn      string `json:"updated_on,omitempty"`
	UseAQB        string `json:"use_aqb,omitempty"`
	SubDomain     string `json:"sub_domain,omitempty"`
	RecordType    string `json:"record_type,omitempty"`
	RecordLine    string `json:"record_line,omitempty"`
	RecordLineID  string `json:"record_line_id,omitempty"`
}

func (Record) String

func (r Record) String() string

type RecordLine

type RecordLine struct {
	Line   string `json:"line"`
	LineID string `json:"line_id"`
}

type RecordQuery

type RecordQuery struct {
	DomainID    string `json:"domainID"`
	Domain      string `json:"domain,omitempty"`
	CurrentPage int    `json:"currentPage,omitempty"`
	PageSize    int    `json:"pageSize,omitempty"`
	SubDomain   string `json:"subDomain,omitempty"`
	Keyword     string `json:"keyword,omitempty"`
}

type RecordsInfo

type RecordsInfo struct {
	SubDomains  int `json:"sub_domains"`
	RecordTotal int `json:"record_total"`
}

type Response

type Response struct {
	*http.Response
}

A Response represents an API response.

type Status

type Status struct {
	Code      string `json:"code,omitempty"`
	Message   string `json:"message,omitempty"`
	CreatedAt string `json:"created_at,omitempty"`
}

type User

type User struct {
	RealName      string `json:"real_name"`
	UserType      string `json:"user_type"`
	Tel           string `json:"telephone"`
	IM            string `json:"im"`
	Nick          string `json:"nick"`
	ID            string `json:"id"`
	Email         string `json:"email"`
	Status        string `json:"status"`
	EmailVerified string `json:"email_verified"`
	TelVerified   string `json:"telephone_verified"`
	WeixinBinded  string `json:"weixin_binded"`
	AgentPending  bool   `json:"agent_pending"`
	Balance       int    `json:"balance"`
	SmsBalance    int    `json:"smsbalance"`
	UserGrade     string `json:"user_grade"`
}

func (User) String

func (u User) String() string

type UserInfo

type UserInfo struct {
	User User `json:"user"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL