Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetDNSRecords ¶
func GetDNSRecords(cf Cloudflare) error
GetDNSRecords retrieves the DNS records from Cloudflare for a specified zone ID using the provided Cloudflare credentials. It makes a GET request to the Cloudflare API, reads the response, and prints the 'name' and 'content' fields of each DNS record.
**Parameters:**
cf: A Cloudflare struct containing the necessary credentials (email, API key) and the zone ID for which the DNS records should be retrieved.
**Returns:**
error: An error if any issue occurs while trying to get the DNS records.
Example ¶
// Mocked HTTP client
mockClient := &MockHTTPClient{}
cf := cloudflare.Cloudflare{
CFApiKey: "your-api-key",
CFEmail: "your-email@example.com",
CFZoneID: "your-zone-id",
Client: mockClient,
}
// We have to replace the standard output temporarily to capture it.
old := os.Stdout
r, w, err := os.Pipe()
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
os.Stdout = w
if err := cloudflare.GetDNSRecords(cf); err != nil {
fmt.Fprintln(os.Stderr, err)
}
// Close the Pipe Writer to let the ReadString finish properly.
w.Close()
// Restore the standard output.
os.Stdout = old
out, err := io.ReadAll(r)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
// Display the result we've captured.
fmt.Print(string(out))
Output: name: your-dns-name content: your-dns-content
Types ¶
type Cloudflare ¶
type Cloudflare struct {
CFApiKey string
CFEmail string
CFZoneID string
Email string
Endpoint string
Client HTTPClient
}
Cloudflare represents information needed to interface with the Cloudflare API.
**Attributes:**
CFApiKey: Cloudflare API key. CFEmail: Email associated with the Cloudflare account. CFZoneID: Zone ID of the domain on Cloudflare. Email: Email address for notifications. Endpoint: API endpoint for Cloudflare. Client: HTTP client for making requests.