Categorygithub.com/jimdo/cloudflare-go
modulepackage
0.8.4
Repository: https://github.com/jimdo/cloudflare-go.git
Documentation: pkg.go.dev

# README

cloudflare-go

GoDoc Build Status Go Report Card

Note: This library is under active development as we expand it to cover our (expanding!) API. Consider the public API of this package a little unstable as we work towards a v1.0.

A Go library for interacting with Cloudflare's API v4. This library allows you to:

  • Manage and automate changes to your DNS records within Cloudflare
  • Manage and automate changes to your zones (domains) on Cloudflare, including adding new zones to your account
  • List and modify the status of WAF (Web Application Firewall) rules for your zones
  • Fetch Cloudflare's IP ranges for automating your firewall whitelisting

A command-line client, flarectl, is also available as part of this project.

Features

The current feature list includes:

  • DNS Records
  • Zones
  • Web Application Firewall (WAF)
  • Cloudflare IPs
  • User Administration (partial)
  • Virtual DNS Management
  • Custom hostnames
  • Zone Lockdown and User-Agent Block rules
  • Organization Administration
  • Railgun administration
  • Keyless SSL
  • Origin CA
  • Load Balancing
  • Firewall (partial)

Pull Requests are welcome, but please open an issue (or comment in an existing issue) to discuss any non-trivial changes before submitting code.

Installation

You need a working Go environment.

go get github.com/cloudflare/cloudflare-go

Getting Started

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/cloudflare/cloudflare-go"
)

func main() {
	// Construct a new API object
	api, err := cloudflare.New(os.Getenv("CF_API_KEY"), os.Getenv("CF_API_EMAIL"))
	if err != nil {
		log.Fatal(err)
	}

	// Fetch user details on the account
	u, err := api.UserDetails()
	if err != nil {
		log.Fatal(err)
	}
	// Print user details
	fmt.Println(u)

	// Fetch the zone ID
	id, err := api.ZoneIDByName("example.com") // Assuming example.com exists in your Cloudflare account already
	if err != nil {
		log.Fatal(err)
	}

	// Fetch zone details
	zone, err := api.ZoneDetails(id)
	if err != nil {
		log.Fatal(err)
	}
	// Print zone details
	fmt.Println(zone)
}

Also refer to the API documentation for how to use this package in-depth.

License

BSD licensed. See the LICENSE file for details.

# Packages

No description provided by the author

# Functions

Headers allows you to set custom HTTP headers when making API calls (e.g.
HTTPClient accepts a custom *http.Client for making API calls.
IPs gets a list of Cloudflare's IP ranges.
New creates a new Cloudflare v4 API client.
Organization allows you to apply account-level changes (Load Balancing, Railguns) to an organization instead.

# Constants

AuthKeyEmail specifies that we should authenticate with API key and email address.
AuthUserService specifies that we should authenticate with a User-Service key.

# Variables

PageRuleActions maps API action IDs to human-readable strings.

# Structs

AccessRule represents a firewall access rule.
AccessRuleConfiguration represents the configuration of a firewall access rule.
AccessRuleListResponse represents the response from the list access rules endpoint.
AccessRuleResponse represents the response from the firewall access rule endpoint.
AccessRuleScope represents the scope of a firewall access rule.
API holds the configuration for the current API client.
AvailableZoneRatePlansResponse represents the response from the Available Rate Plans endpoint.
CustomHostname represents a custom hostname in a zone.
CustomHostnameListResponse represents a response from the Custom Hostnames endpoints.
CustomHostNameResponse represents a response from the Custom Hostnames endpoints.
CustomHostnameSSL represents the SSL section in a given custom hostname.
CustomPage represents a custom page configuration.
CustomPageResponse represents the response from the custom pages endpoint.
DNSListResponse represents the response from the list DNS records endpoint.
DNSRecord represents a DNS record in a zone.
DNSRecordResponse represents the response from the DNS endpoint.
IPRanges contains lists of IPv4 and IPv6 CIDRs.
IPsResponse is the API response containing a list of IPs.
KeylessSSL represents Keyless SSL configuration.
KeylessSSLResponse represents the response from the Keyless SSL endpoint.
LoadBalancer represents a load balancer's properties.
LoadBalancerMonitor represents a load balancer monitor's properties.
No description provided by the author
LoadBalancerPool represents a load balancer pool's properties.
Organization represents a multi-user organization.
OrganizationDetails represents details of an organization.
OrganizationInvite has details on an invite.
OrganizationMember has details on a member.
OrganizationRole has details on a role.
OriginCACertificate represents a Cloudflare-issued certificate.
OriginCACertificateID represents the ID of the revoked certificate from the Revoke Certificate endpoint.
OriginCACertificateListOptions represents the parameters used to list Cloudflare-issued certificates.
Owner describes the resource owner.
PageRule describes a Page Rule.
PageRuleAction is the action to take when the target is matched.
PageRuleDetailResponse is the API response, containing a single PageRule.
PageRulesResponse is the API response, containing an array of PageRules.
PageRuleTarget is the target to evaluate on a request.
PurgeCacheRequest represents the request format made to the purge endpoint.
PurgeCacheResponse represents the response from the purge endpoint.
Railgun represents a Railgun's properties.
RailgunDiagnosis represents the test results from testing railgun connections to a zone.
RailgunListOptions represents the parameters used to list railguns.
RawResponse keeps the result as JSON form.
Response is a template.
ResponseInfo contains a code and message returned by the API as errors or informational messages inside the response.
ResultInfo contains metadata about the Response.
User describes a user account.
UserAgentRule represents a User-Agent Block.
UserAgentRuleListResponse represents a response from the List Zone Lockdown endpoint.
UserAgentRuleResponse represents a response from the Zone Lockdown endpoint.
UserBillingProfile contains Billing Profile information.
UserError represents a user-generated error.
UserResponse wraps a response containing User accounts.
VirtualDNS represents a Virtual DNS configuration.
VirtualDNSListResponse represents an array of Virtual DNS responses.
VirtualDNSResponse represents a Virtual DNS response.
WAFPackage represents a WAF package configuration.
WAFPackagesResponse represents the response from the WAF packages endpoint.
WAFRule represents a WAF rule.
WAFRulesResponse represents the response from the WAF rule endpoint.
Zone describes a Cloudflare zone.
ZoneAnalytics contains analytics data for a zone.
ZoneAnalyticsColocation contains analytics data by datacenter.
ZoneAnalyticsData contains totals and timeseries analytics data for a zone.
ZoneAnalyticsOptions represents the optional parameters in Zone Analytics endpoint requests.
ZoneCustomSSL represents custom SSL certificate metadata.
ZoneCustomSSLOptions represents the parameters to create or update an existing custom SSL configuration.
ZoneCustomSSLPriority represents a certificate's ID and priority.
ZoneID contains only the zone ID.
ZoneIDResponse represents the response from the Zone endpoint, containing only a zone ID.
ZoneLockdown represents a Zone Lockdown rule.
ZoneLockdownConfig represents a Zone Lockdown config, which comprises a Target ("ip" or "ip_range") and a Value (an IP address or IP+mask, respectively.).
ZoneLockdownListResponse represents a response from the List Zone Lockdown endpoint.
ZoneLockdownResponse represents a response from the Zone Lockdown endpoint.
ZoneMeta describes metadata about a zone.
ZoneOptions is a subset of Zone, for editable options.
ZoneRailgun represents the status of a Railgun on a zone.
ZoneRatePlan contains the plan information for a zone.
ZoneRatePlanResponse represents the response from the Plan Details endpoint.
ZoneResponse represents the response from the Zone endpoint containing a single zone.
ZoneSetting contains settings for a zone.
ZoneSettingResponse represents the response from the Zone Setting endpoint.
ZonesResponse represents the response from the Zone endpoint containing an array of zones.
ZoneSSLSetting contains ssl setting for a zone.
ZoneSettingResponse represents the response from the Zone SSL Setting endpoint.

# Interfaces

Error represents an error returned from this library.

# Type aliases

CustomMetadata defines custom metadata for the hostname.
Option is a functional option for configuring the API client.
UserAgentRuleConfig represents a Zone Lockdown config, which comprises a Target ("ip" or "ip_range") and a Value (an IP address or IP+mask, respectively.).