list domains

This commit is contained in:
juancwu 2026-01-23 14:56:16 +00:00
commit 8498f6f0a7
4 changed files with 146 additions and 10 deletions

View file

@ -26,6 +26,28 @@ func New(apiKey, secretKey string) *Client {
}
}
// Get all domain names in account. Domains are returned in chunks of 1000.
func (c *Client) DomainListAll(start int, includeLabels bool) (*DomainListAllResponse, error) {
reqBody := DomainListAllRequest{
BaseRequest: BaseRequest{
APIKey: c.APIKey,
SecretAPIKey: c.SecretAPIKey,
},
Start: start,
IncludeLabels: "no",
}
if includeLabels {
reqBody.IncludeLabels = "yes"
}
var resp DomainListAllResponse
err := c.post("/domain/listAll", reqBody, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}
func (c *Client) Ping() (*PingResponse, error) {
reqBody := PingRequest{
BaseRequest: BaseRequest{
@ -43,7 +65,7 @@ func (c *Client) Ping() (*PingResponse, error) {
return &resp, nil
}
func (c *Client) post(endpoint string, body interface{}, target interface{}) error {
func (c *Client) post(endpoint string, body any, target any) error {
jsonBody, err := json.Marshal(body)
if err != nil {
return fmt.Errorf("failed to marshal request body: %w", err)

View file

@ -22,3 +22,37 @@ type PingResponse struct {
BaseResponse
YourIP string `json:"yourIp"`
}
// DomainListAllRequest is used for getting a list of all domains.
type DomainListAllRequest struct {
BaseRequest
Start int `json:"start"`
IncludeLabels string `json:"includeLabels,omitempty"`
}
// DomainListAllResponse is the response from the domain list all endpoint.
type DomainListAllResponse struct {
BaseResponse
Domains []Domain `json:"domains"`
}
// Domain represents a single domain returned by domain endpoints.
type Domain struct {
Domain string `json:"domain"`
Status string `json:"status"`
TLD string `json:"tld"`
CreateDate string `json:"createDate"`
ExpireDate string `json:"expireDate"`
SecurityLock string `json:"securityLock"`
WhoIsPrivacy string `json:"whoisPrivacy"`
AutoRenew any `json:"autoRenew"`
NotLocal any `json:"notLocal"`
Labels []DomainLabel `json:"labels,omitempty"`
}
// DomainLabel represents a label associated with a domain.
type DomainLabel struct {
ID string `json:"id"`
Title string `json:"title"`
Color string `json:"color"`
}