func (d *Client) DeleteRecord(record *DNSRecord) error {
	body, err := json.Marshal(record)
	if err != nil {
		return fmt.Errorf("failed to marshal request body: %w", err)
	}
	resource := fmt.Sprintf("/v1/zones/%d/records/%d", record.ZoneID, record.ID)
	resp, err := d.do(http.MethodDelete, resource, bytes.NewReader(body))
	if err != nil {
		return err
	}
	defer func() { _ = resp.Body.Close() }()
	if resp.StatusCode != http.StatusOK {
		bodyBytes, _ := io.ReadAll(resp.Body)
		var errResp errorResponse
		err = json.Unmarshal(bodyBytes, &errResp)
		if err == nil {
			return fmt.Errorf("could not delete record %v: Status=%d: %w",
				string(body), resp.StatusCode, errResp)
		}
		return fmt.Errorf("could not delete record %v: Status=%d: %s",
			string(body), resp.StatusCode, string(bodyBytes))
	}
	return nil
}
DeleteRecord deletes a record.
https://luadns.com/api.html#delete-a-record
package internal
import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)
const defaultBaseURL = "https://api.luadns.com"
type Client struct {
	HTTPClient *http.Client
	BaseURL    string
	apiUsername string
	apiToken    string
}
func NewClient(apiUsername, apiToken string) *Client {
	return &Client{
		HTTPClient:  http.DefaultClient,
		BaseURL:     defaultBaseURL,
		apiUsername: apiUsername,
		apiToken:    apiToken,
	}
}
func (d *Client) ListZones() ([]DNSZone, error) {
	resp, err := d.do(http.MethodGet, "/v1/zones", nil)
	if err != nil {
		return nil, err
	}
	defer func() { _ = resp.Body.Close() }()
	if resp.StatusCode != http.StatusOK {
		bodyBytes, _ := io.ReadAll(resp.Body)
		var errResp errorResponse
		err = json.Unmarshal(bodyBytes, &errResp)
		if err == nil {
			return nil, fmt.Errorf("api call error: Status=%v: %w", resp.StatusCode, errResp)
		}
		return nil, fmt.Errorf("api call error: Status=%d: %s", resp.StatusCode, string(bodyBytes))
	}
	var zones []DNSZone
	err = json.NewDecoder(resp.Body).Decode(&zones)
	if err != nil {
		return nil, fmt.Errorf("failed to unmarshal response body: %w", err)
	}
	return zones, nil
}
func (d *Client) CreateRecord(zone DNSZone, newRecord DNSRecord) (*DNSRecord, error) {
	body, err := json.Marshal(newRecord)
	if err != nil {
		return nil, fmt.Errorf("failed to marshal request body: %w", err)
	}
	resource := fmt.Sprintf("/v1/zones/%d/records", zone.ID)
	resp, err := d.do(http.MethodPost, resource, bytes.NewReader(body))
	if err != nil {
		return nil, err
	}
	defer func() { _ = resp.Body.Close() }()
	if resp.StatusCode != http.StatusOK {
		bodyBytes, _ := io.ReadAll(resp.Body)
		var errResp errorResponse
		err = json.Unmarshal(bodyBytes, &errResp)
		if err == nil {
			return nil, fmt.Errorf("could not create record %v: Status=%d: %w",
				string(body), resp.StatusCode, errResp)
		}
		return nil, fmt.Errorf("could not create record %v: Status=%d: %s",
			string(body), resp.StatusCode, string(bodyBytes))
	}
	var record *DNSRecord
	err = json.NewDecoder(resp.Body).Decode(&record)
	if err != nil {
		return nil, fmt.Errorf("failed to unmarshal response body: %w", err)
	}
	return record, nil
}