Vendor main dependencies.

This commit is contained in:
Timo Reimann 2017-02-07 22:33:23 +01:00
parent 49a09ab7dd
commit dd5e3fba01
2738 changed files with 1045689 additions and 0 deletions

209
vendor/github.com/decker502/dnspod-go/dnspod.go generated vendored Normal file
View file

@ -0,0 +1,209 @@
// 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.
package dnspod
import (
// "bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"strings"
"time"
)
const (
libraryVersion = "0.1"
baseURL = "https://dnsapi.cn/"
userAgent = "dnspod-go/" + libraryVersion
apiVersion = "v1"
)
// dnspod API docs: https://www.dnspod.cn/docs/info.html
type CommonParams struct {
LoginToken string
Format string
Lang string
ErrorOnEmpty string
UserID string
}
func newPayLoad(params CommonParams) url.Values {
p := url.Values{}
if params.LoginToken != "" {
p.Set("login_token", params.LoginToken)
}
if params.Format != "" {
p.Set("format", params.Format)
}
if params.Lang != "" {
p.Set("lang", params.Lang)
}
if params.ErrorOnEmpty != "" {
p.Set("error_on_empty", params.ErrorOnEmpty)
}
if params.UserID != "" {
p.Set("user_id", params.UserID)
}
return p
}
type Status struct {
Code string `json:"code,omitempty"`
Message string `json:"message,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
}
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
}
// NewClient returns a new dnspod API client.
func NewClient(CommonParams CommonParams) *Client {
c := &Client{HttpClient: &http.Client{}, CommonParams: CommonParams, BaseURL: baseURL, UserAgent: userAgent}
c.Domains = &DomainsService{client: c}
return c
}
// 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.
func (client *Client) NewRequest(method, path string, payload url.Values) (*http.Request, error) {
url := client.BaseURL + fmt.Sprintf("%s", path)
req, err := http.NewRequest(method, url, strings.NewReader(payload.Encode()))
if err != nil {
return nil, err
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Accept", "application/json")
req.Header.Add("User-Agent", client.UserAgent)
return req, nil
}
func (c *Client) get(path string, v interface{}) (*Response, error) {
return c.Do("GET", path, nil, v)
}
func (c *Client) post(path string, payload url.Values, v interface{}) (*Response, error) {
return c.Do("POST", path, payload, v)
}
func (c *Client) put(path string, payload url.Values, v interface{}) (*Response, error) {
return c.Do("PUT", path, payload, v)
}
func (c *Client) delete(path string, payload url.Values) (*Response, error) {
return c.Do("DELETE", path, payload, nil)
}
// 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 (c *Client) Do(method, path string, payload url.Values, v interface{}) (*Response, error) {
req, err := c.NewRequest(method, path, payload)
if err != nil {
return nil, err
}
res, err := c.HttpClient.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
response := &Response{Response: res}
err = CheckResponse(res)
if err != nil {
return response, err
}
if v != nil {
if w, ok := v.(io.Writer); ok {
io.Copy(w, res.Body)
} else {
err = json.NewDecoder(res.Body).Decode(v)
}
}
return response, err
}
// A Response represents an API response.
type Response struct {
*http.Response
}
// An ErrorResponse represents an error caused by an API request.
type ErrorResponse struct {
Response *http.Response // HTTP response that caused this error
Message string `json:"message"` // human-readable message
}
// Error implements the error interface.
func (r *ErrorResponse) Error() string {
return fmt.Sprintf("%v %v: %d %v",
r.Response.Request.Method, r.Response.Request.URL,
r.Response.StatusCode, r.Message)
}
// 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.
func CheckResponse(r *http.Response) error {
if code := r.StatusCode; 200 <= code && code <= 299 {
return nil
}
errorResponse := &ErrorResponse{Response: r}
err := json.NewDecoder(r.Body).Decode(errorResponse)
if err != nil {
return err
}
return errorResponse
}
// Date custom type.
type Date struct {
time.Time
}
// UnmarshalJSON handles the deserialization of the custom Date type.
func (d *Date) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("date should be a string, got %s", data)
}
t, err := time.Parse("2006-01-02", s)
if err != nil {
return fmt.Errorf("invalid date: %v", err)
}
d.Time = t
return nil
}

237
vendor/github.com/decker502/dnspod-go/domain_records.go generated vendored Normal file
View file

@ -0,0 +1,237 @@
package dnspod
import (
"fmt"
)
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"`
}
type recordsWrapper struct {
Status Status `json:"status"`
Info DomainInfo `json:"info"`
Records []Record `json:"records"`
}
type recordWrapper struct {
Status Status `json:"status"`
Info DomainInfo `json:"info"`
Record Record `json:"record"`
}
// recordAction generates the resource path for given record that belongs to a domain.
func recordAction(action string) string {
if len(action) > 0 {
return fmt.Sprintf("Record.%s", action)
}
return "Record.List"
}
// List the domain records.
//
// dnspod API docs: https://www.dnspod.cn/docs/records.html#record-list
func (s *DomainsService) ListRecords(domain string, recordName string) ([]Record, *Response, error) {
path := recordAction("List")
payload := newPayLoad(s.client.CommonParams)
payload.Add("domain_id", domain)
if recordName != "" {
payload.Add("sub_domain", recordName)
}
wrappedRecords := recordsWrapper{}
res, err := s.client.post(path, payload, &wrappedRecords)
if err != nil {
return []Record{}, res, err
}
if wrappedRecords.Status.Code != "1" {
return wrappedRecords.Records, nil, fmt.Errorf("Could not get domains: %s", wrappedRecords.Status.Message)
}
records := []Record{}
for _, record := range wrappedRecords.Records {
records = append(records, record)
}
return records, res, nil
}
// CreateRecord creates a domain record.
//
// dnspod API docs: https://www.dnspod.cn/docs/records.html#record-create
func (s *DomainsService) CreateRecord(domain string, recordAttributes Record) (Record, *Response, error) {
path := recordAction("Create")
payload := newPayLoad(s.client.CommonParams)
payload.Add("domain_id", domain)
if recordAttributes.Name != "" {
payload.Add("sub_domain", recordAttributes.Name)
}
if recordAttributes.Type != "" {
payload.Add("record_type", recordAttributes.Type)
}
if recordAttributes.Line != "" {
payload.Add("record_line", recordAttributes.Line)
}
if recordAttributes.LineID != "" {
payload.Add("record_line_id", recordAttributes.LineID)
}
if recordAttributes.Value != "" {
payload.Add("value", recordAttributes.Value)
}
if recordAttributes.MX != "" {
payload.Add("mx", recordAttributes.MX)
}
if recordAttributes.TTL != "" {
payload.Add("ttl", recordAttributes.TTL)
}
if recordAttributes.Status != "" {
payload.Add("status", recordAttributes.Status)
}
returnedRecord := recordWrapper{}
res, err := s.client.post(path, payload, &returnedRecord)
if err != nil {
return Record{}, res, err
}
if returnedRecord.Status.Code != "1" {
return returnedRecord.Record, nil, fmt.Errorf("Could not get domains: %s", returnedRecord.Status.Message)
}
return returnedRecord.Record, res, nil
}
// GetRecord fetches the domain record.
//
// dnspod API docs: https://www.dnspod.cn/docs/records.html#record-info
func (s *DomainsService) GetRecord(domain string, recordID string) (Record, *Response, error) {
path := recordAction("Info")
payload := newPayLoad(s.client.CommonParams)
payload.Add("domain_id", domain)
payload.Add("record_id", recordID)
returnedRecord := recordWrapper{}
res, err := s.client.post(path, payload, &returnedRecord)
if err != nil {
return Record{}, res, err
}
if returnedRecord.Status.Code != "1" {
return returnedRecord.Record, nil, fmt.Errorf("Could not get domains: %s", returnedRecord.Status.Message)
}
return returnedRecord.Record, res, nil
}
// UpdateRecord updates a domain record.
//
// dnspod API docs: https://www.dnspod.cn/docs/records.html#record-modify
func (s *DomainsService) UpdateRecord(domain string, recordID string, recordAttributes Record) (Record, *Response, error) {
path := recordAction("Modify")
payload := newPayLoad(s.client.CommonParams)
payload.Add("domain_id", domain)
if recordAttributes.Name != "" {
payload.Add("sub_domain", recordAttributes.Name)
}
if recordAttributes.Type != "" {
payload.Add("record_type", recordAttributes.Type)
}
if recordAttributes.Line != "" {
payload.Add("record_line", recordAttributes.Line)
}
if recordAttributes.LineID != "" {
payload.Add("record_line_id", recordAttributes.LineID)
}
if recordAttributes.Value != "" {
payload.Add("value", recordAttributes.Value)
}
if recordAttributes.MX != "" {
payload.Add("mx", recordAttributes.MX)
}
if recordAttributes.TTL != "" {
payload.Add("ttl", recordAttributes.TTL)
}
if recordAttributes.Status != "" {
payload.Add("status", recordAttributes.Status)
}
returnedRecord := recordWrapper{}
res, err := s.client.post(path, payload, &returnedRecord)
if err != nil {
return Record{}, res, err
}
if returnedRecord.Status.Code != "1" {
return returnedRecord.Record, nil, fmt.Errorf("Could not get domains: %s", returnedRecord.Status.Message)
}
return returnedRecord.Record, res, nil
}
// DeleteRecord deletes a domain record.
//
// dnspod API docs: https://www.dnspod.cn/docs/records.html#record-remove
func (s *DomainsService) DeleteRecord(domain string, recordID string) (*Response, error) {
path := recordAction("Remove")
payload := newPayLoad(s.client.CommonParams)
payload.Add("domain_id", domain)
payload.Add("record_id", recordID)
returnedRecord := recordWrapper{}
res, err := s.client.post(path, payload, &returnedRecord)
if err != nil {
return res, err
}
if returnedRecord.Status.Code != "1" {
return nil, fmt.Errorf("Could not get domains: %s", returnedRecord.Status.Message)
}
return res, nil
}

161
vendor/github.com/decker502/dnspod-go/domains.go generated vendored Normal file
View file

@ -0,0 +1,161 @@
package dnspod
import (
"fmt"
"strconv"
// "time"
)
// DomainsService handles communication with the domain related
// methods of the dnspod API.
//
// dnspod API docs: https://www.dnspod.cn/docs/domains.html
type DomainsService struct {
client *Client
}
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"`
}
type Domain struct {
ID int `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"`
}
type domainListWrapper struct {
Status Status `json:"status"`
Info DomainInfo `json:"info"`
Domains []Domain `json:"domains"`
}
type domainWrapper struct {
Status Status `json:"status"`
Info DomainInfo `json:"info"`
Domain Domain `json:"domain"`
}
// domainRequest represents a generic wrapper for a domain request,
// when domainWrapper cannot be used because of type constraint on Domain.
type domainRequest struct {
Domain interface{} `json:"domain"`
}
// domainAction generates the resource path for given domain.
func domainAction(action string) string {
if len(action) > 0 {
return fmt.Sprintf("Domain.%s", action)
}
return "Domain.List"
}
// List the domains.
//
// dnspod API docs: https://www.dnspod.cn/docs/domains.html#domain-list
func (s *DomainsService) List() ([]Domain, *Response, error) {
path := domainAction("List")
returnedDomains := domainListWrapper{}
payload := newPayLoad(s.client.CommonParams)
res, err := s.client.post(path, payload, &returnedDomains)
if err != nil {
return []Domain{}, res, err
}
domains := []Domain{}
if returnedDomains.Status.Code != "1" {
return domains, nil, fmt.Errorf("Could not get domains: %s", returnedDomains.Status.Message)
}
for _, domain := range returnedDomains.Domains {
domains = append(domains, domain)
}
return domains, res, nil
}
// Create a new domain.
//
// dnspod API docs: https://www.dnspod.cn/docs/domains.html#domain-create
func (s *DomainsService) Create(domainAttributes Domain) (Domain, *Response, error) {
path := domainAction("Create")
returnedDomain := domainWrapper{}
payload := newPayLoad(s.client.CommonParams)
payload.Set("domain", domainAttributes.Name)
payload.Set("group_id", domainAttributes.GroupID)
payload.Set("is_mark", domainAttributes.IsMark)
res, err := s.client.post(path, payload, &returnedDomain)
if err != nil {
return Domain{}, res, err
}
return returnedDomain.Domain, res, nil
}
// Get fetches a domain.
//
// dnspod API docs: https://www.dnspod.cn/docs/domains.html#domain-info
func (s *DomainsService) Get(ID int) (Domain, *Response, error) {
path := domainAction("Info")
returnedDomain := domainWrapper{}
payload := newPayLoad(s.client.CommonParams)
payload.Set("domain_id", strconv.FormatInt(int64(ID), 10))
res, err := s.client.post(path, payload, &returnedDomain)
if err != nil {
return Domain{}, res, err
}
return returnedDomain.Domain, res, nil
}
// Delete a domain.
//
// dnspod API docs: https://dnsapi.cn/Domain.Remove
func (s *DomainsService) Delete(ID int) (*Response, error) {
path := domainAction("Remove")
returnedDomain := domainWrapper{}
payload := newPayLoad(s.client.CommonParams)
payload.Set("domain_id", strconv.FormatInt(int64(ID), 10))
res, err := s.client.post(path, payload, &returnedDomain)
if err != nil {
return res, err
}
return res, nil
}