Skip to content
Go library for the Cloudflare v4 API
Go
Branch: master
Clone or download
This branch is 17 commits behind cloudflare:master.

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
cmd/flarectl
vendor
.gitignore
.travis.yml
CODE_OF_CONDUCT.md
LICENSE
README.md
access_application.go
access_application_test.go
access_group.go
access_group_test.go
access_identity_provider.go
access_identity_provider_test.go
access_organization.go
access_organization_test.go
access_policy.go
access_policy_test.go
access_service_tokens.go
access_service_tokens_test.go
account_members.go
account_members_test.go
account_roles.go
account_roles_test.go
accounts.go
accounts_test.go
argo.go
argo_example_test.go
argo_test.go
auditlogs.go
auditlogs_test.go
cloudflare.go
cloudflare_test.go
custom_hostname.go
custom_hostname_test.go
custom_pages.go
custom_pages_test.go
dns.go
dns_example_test.go
duration.go
duration_test.go
errors.go
example_test.go
filter.go
filter_test.go
firewall.go
firewall_example_test.go
firewall_rules.go
firewall_rules_test.go
go.mod
go.sum
healthchecks.go
healthchecks_test.go
ips.go
ips_test.go
keyless.go
load_balancing.go
load_balancing_example_test.go
load_balancing_test.go
lockdown.go
lockdown_example_test.go
logpush.go
logpush_example_test.go
logpush_test.go
options.go
origin_ca.go
origin_ca_test.go
page_rules.go
page_rules_example_test.go
page_rules_test.go
railgun.go
railgun_test.go
rate_limiting.go
rate_limiting_example_test.go
rate_limiting_test.go
registrar.go
registrar_example_test.go
registrar_test.go
renovate.json
spectrum.go
spectrum_test.go
ssl.go
ssl_test.go
universal_ssl.go
universal_ssl_test.go
user.go
user_agent.go
user_agent_example_test.go
user_test.go
virtualdns.go
virtualdns_test.go
waf.go
waf_overrides.go
waf_overrides_test.go
waf_test.go
workers.go
workers_example_test.go
workers_kv.go
workers_kv_example_test.go
workers_kv_test.go
workers_test.go
zone.go
zone_example_test.go
zone_test.go

README.md

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:

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

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.

You can’t perform that action at this time.