cloudflare

package
v2.2.5 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 4 Imported by: 0

README

goutils/v2/cloudflare

The cloudflare package is a collection of utility functions designed to simplify common cloudflare tasks.


Table of contents


Functions

GetDNSRecords(Cloudflare)
GetDNSRecords(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.


Installation

To use the goutils/v2/cloudflare package, you first need to install it. Follow the steps below to install via go get.

go get github.com/l50/goutils/v2/cloudflare

Usage

After installation, you can import the package in your Go project using the following import statement:

import "github.com/l50/goutils/v2/cloudflare"

Tests

To ensure the package is working correctly, run the following command to execute the tests for goutils/v2/cloudflare:

go test -v

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.


License

This project is licensed under the MIT License - see the LICENSE file for details.

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.

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient defines the behavior of an HTTP client.

**Attributes:**

Do: Sends an HTTP request and returns the HTTP response or an error.

Jump to

Keyboard shortcuts

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