Skip to content
Go library for the Cloudflare v4 API
Go
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Create stale.yml May 10, 2019
cmd/flarectl Add 'zone delete' command to flarectl (#345) Sep 16, 2019
vendor Update module urfave/cli to v1.22.1 (#344) Sep 13, 2019
.gitignore fixed error description (#319) Jun 25, 2019
.travis.yml fix: golang.org/x/time pseudo version. (#334) Aug 13, 2019
CODE_OF_CONDUCT.md Adding code of conduct (#254) Nov 22, 2018
LICENSE Back to the future Aug 8, 2019
README.md Add Logpush Jobs methods, it solves #274 (#275) Mar 28, 2019
access_application.go Fix error message (#244) Nov 7, 2018
access_application_test.go Fix error message (#244) Nov 7, 2018
access_identity_provider.go Add support for Access Identity Providers (#340) Aug 22, 2019
access_identity_provider_test.go Add support for Access Identity Providers (#340) Aug 22, 2019
access_organization.go Add support for Access Organization (#338) Aug 21, 2019
access_organization_test.go
access_policy.go
access_policy_test.go Add support Cloudflare Access (#233) Oct 24, 2018
access_service_tokens.go Add support for Access Service Tokens (#339) Aug 21, 2019
access_service_tokens_test.go Add support for Access Service Tokens (#339) Aug 21, 2019
account_members.go
account_members_test.go account_member: Validate presence of accountID (#283) Mar 26, 2019
account_roles.go Add account role endpoints Jun 28, 2018
account_roles_test.go Add account role endpoints Jun 28, 2018
accounts.go Make `ZoneIDByName` safer to use for ambiguous zone names (#236) Nov 7, 2018
accounts_test.go Make `ZoneIDByName` safer to use for ambiguous zone names (#236) Nov 7, 2018
argo.go argo: Add smart routing and tired caching support (#289) Apr 19, 2019
argo_example_test.go argo: Add smart routing and tired caching support (#289) Apr 19, 2019
argo_test.go
auditlogs.go Add support for audit log apis to cloudflare-go (#245) Nov 13, 2018
auditlogs_test.go Add support for audit log apis to cloudflare-go (#245) Nov 13, 2018
cloudflare.go
cloudflare_test.go Deprecate use of `Organization` (#315) Jul 25, 2019
custom_hostname.go CUSTOM_ORIGIN_SERVER Adding custom_origin_server to CustomHostname st… ( Aug 22, 2019
custom_hostname_test.go CUSTOM_ORIGIN_SERVER Adding custom_origin_server to CustomHostname st… ( Aug 22, 2019
custom_pages.go Add support for managing Custom Pages (#240) Oct 24, 2018
custom_pages_test.go Add support for managing Custom Pages (#240) Oct 24, 2018
dns.go Always serialize Proxied and Priority fields Aug 10, 2018
dns_example_test.go feat(docs): add examples Feb 16, 2017
duration.go add Duration method comments to satisfy linter Mar 22, 2019
duration_test.go implement JSON encoding for time.Duration Mar 22, 2019
errors.go Add support for the new API Tokens (beta) auth scheme (#326) Jul 15, 2019
example_test.go [breaking] Fix create page rule to return the page rule object (#169) Feb 26, 2018
filter.go Update documentation links (#232) Oct 23, 2018
filter_test.go Run gofmt (#238) Oct 23, 2018
firewall.go Deprecate use of `Organization` (#315) Jul 25, 2019
firewall_example_test.go [feat] Support Firewall access rules (#144) Sep 28, 2017
firewall_rules.go Update documentation links (#232) Oct 23, 2018
firewall_rules_test.go
go.mod Update module urfave/cli to v1.22.1 (#344) Sep 13, 2019
go.sum Update module urfave/cli to v1.22.1 (#344) Sep 13, 2019
ips.go feat(docs): Standardise and improve declaration comments Feb 16, 2017
ips_test.go Rename TestClient_Auth to TestClient_IPs and mock properly (#231) Nov 13, 2018
keyless.go feat(docs): Standardise and improve declaration comments Feb 16, 2017
load_balancing.go add enabled to LoadBalancer struct (#273) Mar 26, 2019
load_balancing_example_test.go Add an example load balancing test Mar 22, 2019
load_balancing_test.go Added ProbeZone to LoadBalancerMonitor to support new API field for l… Mar 26, 2019
lockdown.go Added Priority field to ZoneLockdown type (#266) Jun 13, 2019
lockdown_example_test.go Added Priority field to ZoneLockdown type (#266) Jun 13, 2019
logpush.go Omit ownership_challenge when empty Apr 9, 2019
logpush_example_test.go Add UpdateLogpushJob test Apr 8, 2019
logpush_test.go Add UpdateLogpushJob test Apr 8, 2019
options.go Deprecate use of `Organization` (#315) Jul 25, 2019
origin_ca.go
origin_ca_test.go OriginCACertificate.RequestValidity should be an int Jun 14, 2017
page_rules.go page_rules: Add `minify` support (#297) Apr 29, 2019
page_rules_example_test.go
page_rules_test.go [breaking] Fix create page rule to return the page rule object (#169) Feb 26, 2018
railgun.go
railgun_test.go Update time fields to use time.Time instead of string Jun 26, 2016
rate_limiting.go Make rate limiting `correlate` optional (#281) Mar 26, 2019
rate_limiting_example_test.go Make rate limiting `correlate` optional (#281) Mar 26, 2019
rate_limiting_test.go Make rate limiting `correlate` optional (#281) Mar 26, 2019
registrar.go
registrar_example_test.go registrar: Add support for updating a domain Mar 24, 2019
registrar_test.go registrar: Add support for updating a domain Mar 24, 2019
renovate.json Add renovate.json (#299) May 10, 2019
spectrum.go Fixes #252 support origin_dns (#253) Nov 21, 2018
spectrum_test.go Fixes #252 support origin_dns (#253) Nov 21, 2018
ssl.go
ssl_test.go update tests Jul 17, 2019
universal_ssl.go Add universal ssl verification details. (#330) Aug 8, 2019
universal_ssl_test.go Add universal ssl verification details. (#330) Aug 8, 2019
user.go Deprecate use of `Organization` (#315) Jul 25, 2019
user_agent.go [flarectl] Adds User-Agent blocking to flarectl (#145) Oct 6, 2017
user_agent_example_test.go [feat] Zone Lockdowns & User-Agent Blocks (#141) Jul 27, 2017
user_test.go Implement UserBillingProfile Dec 30, 2016
virtualdns.go Add comment on VirtualDNSUserAnalyticsOptions struct and VirtualDNSUs… Nov 14, 2018
virtualdns_test.go Add partial support for VirtualDNS analytics (#183) Nov 14, 2018
waf.go get and edit WAF rule groups (#329) Aug 22, 2019
waf_test.go get and edit WAF rule groups (#329) Aug 22, 2019
workers.go Deprecate use of `Organization` (#315) Jul 25, 2019
workers_example_test.go Deprecate use of `Organization` (#315) Jul 25, 2019
workers_kv.go Deprecate use of `Organization` (#315) Jul 25, 2019
workers_kv_example_test.go Deprecate use of `Organization` (#315) Jul 25, 2019
workers_kv_test.go Deprecate use of `Organization` (#315) Jul 25, 2019
workers_test.go
zone.go Support setting fallback origin on a zone (#337) Aug 22, 2019
zone_example_test.go zone: Paginate `ListZones` for all zones (#288) Mar 28, 2019
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

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.