faghani / cloudflare-go

Go library for the Cloudflare v4 API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


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.


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

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


You need a working Go environment.

go get github.com/cloudflare/cloudflare-go

Getting Started

package main

import (


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

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

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

	// Fetch zone details
	zone, err := api.ZoneDetails(id)
	if err != nil {
	// Print zone details

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


BSD licensed. See the LICENSE file for details.


Go library for the Cloudflare v4 API

License:BSD 3-Clause "New" or "Revised" License


Language:Go 100.0%