dnspodcn

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2020 License: BSD-3-Clause Imports: 10 Imported by: 1

README

DNSPod.cn Go SDK DNSPod.cn Go 开发工具包

Build Status Coverage Status Go.Dev reference Go Report Card Release

dnspodcnDNSPod API 的 Go SDK。其中 Provider 实现了 libdns 接口。

安装

$ go get -u clevergo.tech/dnspodcn

使用

import "clevergo.tech/dnspodcn"

client := dnspodcn.NewClient("APP_ID", "APP_TOKEN")

APP_IDAPP_TOKEN 为 DNSPod 后台生成的 API 的 ID 和 Token。

接口

  • DNS 记录
    • 新增记录:client.CreateRecord
    • 删除记录:client.DeleteRecord
    • 查询记录:client.QueryRecords
    • 修改记录:client.UpdateRecord
  • ...

目前仅实现了 DNS 记录的相关接口,如果你有其他接口要求,可以通过 issue 反馈,也可以自行实现并通过 PR 提交。

Documentation

Index

Constants

View Source
const (
	CodeSuccess   = "1"
	CodeNoRecords = "10"
)

Response codes

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicRequest

type BasicRequest struct {
	// The HTTP request method.
	Method string `json:"-"`

	// The endpoint of API.
	Endpoint string `json:"-"`
}

BasicRequest contains the basic fields of API request.

func NewBasicRequest

func NewBasicRequest(method, endpoint string) BasicRequest

NewBasicRequest returns a basic request with the given method and endpoint.

func (BasicRequest) GetEndpoint

func (req BasicRequest) GetEndpoint() string

GetEndpoint returns the endpoint of API.

func (BasicRequest) GetMethod

func (req BasicRequest) GetMethod() string

GetMethod returns the HTTP request method.

type BasicResponse

type BasicResponse struct {
	Status StatusResponse `json:"status"`
}

BasicResponse contains the basic fields of response.

func (BasicResponse) Error

func (resp BasicResponse) Error() error

Error returns the error of the response.

type Client

type Client struct {
	// The ID of application.
	AppID string
	// The API token of application.
	AppToken string
	// The base URL of API.
	BaseURL string
	// The language of API response, en or zh.
	Language string
}

Client is an API client.

func NewClient

func NewClient(appID, appToken string) *Client

NewClient returns a client with the given app ID, token and default settings.

func (*Client) CreateRecord

func (c *Client) CreateRecord(ctx context.Context, req *CreateRecordRequest) (*CreateRecordResponse, error)

CreateRecord creates a DNS record.

func (*Client) DeleteRecord

func (c *Client) DeleteRecord(ctx context.Context, req *DeleteRecordRequest) (*DeleteRecordResponse, error)

DeleteRecord deletes a DNS record.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req Request, resp Response) error

Do makes a request and returns the response.

func (*Client) QueryRecords

func (c *Client) QueryRecords(ctx context.Context, req *QueryRecordsRequest) (*QueryRecordsResponse, error)

QueryRecords queries DNS records.

func (*Client) UpdateRecord

func (c *Client) UpdateRecord(ctx context.Context, req *UpdateRecordRequest) (*UpdateRecordResponse, error)

UpdateRecord updates a DNS record.

type CreateRecordRequest

type CreateRecordRequest struct {
	BasicRequest
	Domain       string `json:"domain,omitempty"`
	DomainID     string `json:"domain_id,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"`
	Value        string `json:"value,omitempty"`
	MX           string `json:"mx,omitempty"`
	TTL          string `json:"ttl,omitempty"`
	Weight       string `json:"weight,omitempty"`
}

CreateRecordRequest is a request for creating a DNS record.

func NewCreateRecordRequest

func NewCreateRecordRequest(domain, subdomain, recordType, value string) *CreateRecordRequest

NewCreateRecordRequest returns a request for creating a DNS record.

type CreateRecordResponse

type CreateRecordResponse struct {
	BasicResponse
	Record RecordResponse `json:"record"`
}

CreateRecordResponse is a response of creating a DNS record.

type DeleteRecordRequest

type DeleteRecordRequest struct {
	BasicRequest
	Domain   string `json:"domain,omitempty"`
	DomainID string `json:"domain_id,omitempty"`
	RecordID string `json:"record_id,omitempty"`
}

DeleteRecordRequest is a request for deleting a DNS record.

func NewDeleteRecordRequest

func NewDeleteRecordRequest(domain, recordID string) *DeleteRecordRequest

NewDeleteRecordRequest returns a request for deleting a DNS record.

type DeleteRecordResponse

type DeleteRecordResponse struct {
	BasicResponse
}

DeleteRecordResponse is the response of deleting a DNS record.

type Provider

type Provider struct {
	*Client
}

Provider is a wrapper of Client that implements RecordAppender, RecordDeleter, RecordGetter and RecordSetter interface.

func (*Provider) AppendRecords

func (p *Provider) AppendRecords(ctx context.Context, zone string, recs []libdns.Record) ([]libdns.Record, error)

AppendRecords creates the requested records in the given zone and returns the populated records that were created. It never changes existing records.

func (*Provider) DeleteRecords

func (p *Provider) DeleteRecords(ctx context.Context, zone string, recs []libdns.Record) ([]libdns.Record, error)

DeleteRecords deletes the given records from the zone if they exist. It returns the records that were deleted.

func (*Provider) GetRecords

func (p *Provider) GetRecords(ctx context.Context, zone string) ([]libdns.Record, error)

GetRecords returns all the records in the DNS zone.

func (*Provider) SetRecords

func (p *Provider) SetRecords(ctx context.Context, zone string, recs []libdns.Record) ([]libdns.Record, error)

SetRecords updates the zone so that the records described in the input are reflected in the output. It may create or overwrite records or -- depending on the record type -- delete records to maintain parity with the input. No other records are affected. It returns the records which were set.

type QueryRecordsRequest

type QueryRecordsRequest struct {
	BasicRequest
	Domain       string `json:"domain,omitempty"`
	DomainID     string `json:"domain_id,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"`
	Offset       string `json:"offset,omitempty"`
	Length       string `json:"length,omitempty"`
	Keyword      string `json:"keyword,omitempty"`
}

QueryRecordsRequest is a request for querying DNS records.

func NewQueryRecordsRequest

func NewQueryRecordsRequest(domain string) *QueryRecordsRequest

NewQueryRecordsRequest returns a request for querying DNS records.

type QueryRecordsResponse

type QueryRecordsResponse struct {
	BasicResponse
	Domain struct {
		ID   string `json:"id"`
		Name string `json:"name"`
	} `json:"domain"`
	Info struct {
		SubDomains  string `json:"sub_domains"`
		RecordTotal string `json:"record_total"`
		RecordsNum  string `json:"records_num"`
	} `json:"info"`
	Records []RecordResponse `json:"records"`
}

QueryRecordsResponse is the response of querying DNS records.

func (QueryRecordsResponse) Error

func (resp QueryRecordsResponse) Error() error

Error returns the error of response.

type RecordResponse

type RecordResponse struct {
	ID      string `json:"id"`
	Type    string `json:"type"`
	Name    string `json:"name"`
	Status  string `json:"status"`
	Line    string `json:"line"`
	LineID  string `json:"line_id"`
	TTL     string `json:"ttl"`
	Value   string `json:"value"`
	Weight  string `json:"weight"`
	MX      string `json:"mx"`
	Enabled string `json:"enabled"`
	Remark  string `json:"remark"`
}

RecordResponse contains the infomation of DNS record field.

type Request

type Request interface {
	// GetEndpoint returns the endpoint of API without the basic URL.
	GetEndpoint() string
	// GetMethod returns the HTTP request method.
	GetMethod() string
}

Request is an interface that should be implemented by all API requests.

type Response

type Response interface {
	// Error returns the error of the status of request.
	Error() error
}

Response is an interface.

type StatusResponse

type StatusResponse struct {
	Code      string `json:"code"`
	Message   string `json:"message"`
	CreatedAt string `json:"created_at"`
}

StatusResponse contains the infomation of status field.

func (StatusResponse) Error

func (resp StatusResponse) Error() error

Error returns the error of the response.

type UpdateRecordRequest

type UpdateRecordRequest struct {
	BasicRequest
	Domain       string `json:"domain,omitempty"`
	DomainID     string `json:"domain_id,omitempty"`
	Subdomain    string `json:"sub_domain,omitempty"`
	RecordID     string `json:"record_id,omitempty"`
	RecordType   string `json:"record_type,omitempty"`
	RecordLine   string `json:"record_line,omitempty"`
	RecordLineID string `json:"record_line_id,omitempty"`
	Value        string `json:"value,omitempty"`
	MX           string `json:"mx,omitempty"`
	TTL          string `json:"ttl,omitempty"`
	Weight       string `json:"weight,omitempty"`
}

UpdateRecordRequest is a request for updating a DNS record.

func NewUpdateRecordRequest

func NewUpdateRecordRequest(domain, recordID, recordType, value string) *UpdateRecordRequest

NewUpdateRecordRequest returns a request for updating a DNS record.

type UpdateRecordResponse

type UpdateRecordResponse struct {
	BasicResponse
	Record struct {
		ID     int    `json:"id"`
		Name   string `json:"name"`
		Value  string `json:"value"`
		Status string `json:"status"`
	} `json:"record"`
}

UpdateRecordResponse is the response of updating a DNS record.

type Values

type Values map[string]string

Values is a shortcut of map[string]string.

func (Values) Del

func (vs Values) Del(key string)

Del deletes the value associated with the given key.

func (Values) Encode

func (vs Values) Encode() string

Encode returns

func (Values) Get

func (vs Values) Get(key string) string

Get returns the value associated with the given key.

func (Values) Set

func (vs Values) Set(key, value string)

Set sets the key to value. It replaces any existing values.

Jump to

Keyboard shortcuts

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