Documentation
¶
Index ¶
- Constants
- type BasicRequest
- type BasicResponse
- type Client
- func (c *Client) CreateRecord(ctx context.Context, req *CreateRecordRequest) (*CreateRecordResponse, error)
- func (c *Client) DeleteRecord(ctx context.Context, req *DeleteRecordRequest) (*DeleteRecordResponse, error)
- func (c *Client) Do(ctx context.Context, req Request, resp Response) error
- func (c *Client) QueryRecords(ctx context.Context, req *QueryRecordsRequest) (*QueryRecordsResponse, error)
- func (c *Client) UpdateRecord(ctx context.Context, req *UpdateRecordRequest) (*UpdateRecordResponse, error)
- type CreateRecordRequest
- type CreateRecordResponse
- type DeleteRecordRequest
- type DeleteRecordResponse
- type Provider
- func (p *Provider) AppendRecords(ctx context.Context, zone string, recs []libdns.Record) ([]libdns.Record, error)
- func (p *Provider) DeleteRecords(ctx context.Context, zone string, recs []libdns.Record) ([]libdns.Record, error)
- func (p *Provider) GetRecords(ctx context.Context, zone string) ([]libdns.Record, error)
- func (p *Provider) SetRecords(ctx context.Context, zone string, recs []libdns.Record) ([]libdns.Record, error)
- type QueryRecordsRequest
- type QueryRecordsResponse
- type RecordResponse
- type Request
- type Response
- type StatusResponse
- type UpdateRecordRequest
- type UpdateRecordResponse
- type Values
Constants ¶
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 (*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) 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 ¶
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.