Skip to content

boekkooi-lengoo/cloudflare-go

This branch is 2717 commits behind cloudflare/cloudflare-go:master.

Folders and files

NameName
Last commit message
Last commit date
Feb 25, 2022
Jan 10, 2022
Jan 19, 2022
Sep 1, 2020
Jan 9, 2022
Nov 22, 2018
Jan 10, 2022
Feb 9, 2022
Jan 19, 2022
Dec 23, 2021
May 6, 2021
Mar 1, 2021
May 14, 2021
Feb 28, 2021
Jul 1, 2021
Jan 9, 2022
Jul 1, 2021
Jul 1, 2021
Jul 1, 2021
Sep 14, 2021
Sep 14, 2021
Feb 28, 2021
Jul 1, 2021
Feb 28, 2021
Jul 1, 2021
Sep 29, 2021
Sep 29, 2021
May 17, 2021
Jul 1, 2021
Jan 24, 2022
Jan 24, 2022
Sep 29, 2021
Sep 29, 2021
Dec 11, 2021
May 14, 2021
May 6, 2021
Jul 1, 2021
Jan 2, 2022
May 14, 2021
Jan 9, 2022
Mar 1, 2021
May 14, 2021
May 6, 2021
May 14, 2021
Jan 9, 2022
Jan 28, 2020
May 6, 2021
May 17, 2021
May 17, 2021
May 6, 2021
Mar 1, 2021
Mar 1, 2021
Feb 2, 2022
Jul 29, 2021
Jan 10, 2022
Jan 9, 2022
Jan 9, 2022
Feb 2, 2022
Feb 2, 2022
Feb 28, 2021
May 14, 2021
Feb 16, 2022
Dec 21, 2021
Feb 25, 2022
Feb 25, 2022
May 6, 2021
May 14, 2021
Jan 19, 2022
Mar 1, 2021
Jan 9, 2022
Dec 21, 2021
Jan 10, 2022
Mar 22, 2019
Mar 22, 2019
Jan 9, 2022
Aug 1, 2021
Mar 1, 2021
Jan 19, 2022
Jan 9, 2022
Aug 1, 2021
May 14, 2021
May 19, 2021
Mar 1, 2021
May 6, 2021
May 14, 2021
Jan 9, 2022
Jan 19, 2022
Jan 19, 2022
May 6, 2021
May 14, 2021
Jan 9, 2022
Jan 10, 2022
Jan 9, 2022
May 14, 2021
Jan 9, 2022
Jan 9, 2022
Jan 9, 2022
Feb 22, 2021
May 10, 2021
Jul 1, 2021
Feb 6, 2022
Mar 1, 2021
Feb 5, 2022
May 19, 2021
Mar 1, 2021
Jan 9, 2022
May 6, 2021
May 14, 2021
Jan 9, 2022
Dec 14, 2021
Dec 14, 2021
Jan 9, 2022
Jan 9, 2022
Feb 2, 2022
Feb 2, 2022
Jan 23, 2022
Jan 23, 2022
Jan 9, 2022
Jun 3, 2021
Jan 9, 2022
Jan 9, 2022
Jan 9, 2022
Jan 9, 2022
Jul 30, 2021
May 6, 2021
Mar 1, 2021
May 14, 2021
Feb 6, 2022
Feb 6, 2022
May 6, 2021
May 14, 2021
Jan 9, 2022
Mar 1, 2021
Jan 9, 2022
Jan 9, 2022
Aug 1, 2021
Aug 1, 2021
Feb 18, 2022
Aug 27, 2021
Mar 14, 2021
May 14, 2021
Mar 16, 2021
May 14, 2021
Mar 14, 2021
May 14, 2021
Jan 19, 2022
May 14, 2021
Sep 21, 2021
Sep 21, 2021
Feb 2, 2022
Mar 1, 2021
Jan 13, 2022
Jan 13, 2022
Feb 7, 2022
Feb 7, 2022
May 13, 2021
Jul 1, 2021
Aug 6, 2021
Jan 9, 2022
Feb 17, 2022
Feb 16, 2022
Feb 2, 2022
Feb 2, 2022
Mar 2, 2021
May 6, 2021
Mar 1, 2021
Mar 1, 2021
Dec 21, 2021
Dec 21, 2021
May 6, 2021
May 6, 2021
Jul 1, 2021
Jul 1, 2021
Feb 25, 2022
Feb 25, 2022
Jan 30, 2022
Feb 28, 2021
May 14, 2021
Mar 1, 2021
Jan 9, 2022
Jan 9, 2022
Aug 1, 2021
Jan 9, 2022
Aug 1, 2021
Dec 30, 2021
Jan 19, 2022
Feb 9, 2022
Feb 10, 2022
Mar 2, 2021
Jan 9, 2022

cloudflare-go

Go Reference Test 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 Firewall
  • DNS Records
  • Firewall (partial)
  • Gateway Locations
  • Keyless SSL
  • Load Balancing
  • Logpush Jobs
  • Magic Transit / Magic WAN
  • Notifications
  • Organization Administration
  • Origin CA
  • Railgun administration
  • Rate Limiting
  • User Administration (partial)
  • Web Application Firewall (WAF)
  • Workers KV
  • Zone cache settings
  • 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. We officially support only currently supported Go versions according to Go project's release policy.

go get github.com/cloudflare/cloudflare-go

Getting Started

package main

import (
	"context"
	"fmt"
	"log"
	"os"

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

func main() {
	// Construct a new API object using a global API key
	api, err := cloudflare.New(os.Getenv("CLOUDFLARE_API_KEY"), os.Getenv("CLOUDFLARE_API_EMAIL"))
	// alternatively, you can use a scoped API token
	// api, err := cloudflare.NewWithAPIToken(os.Getenv("CLOUDFLARE_API_TOKEN"))
	if err != nil {
		log.Fatal(err)
	}

	// Most API calls require a Context
	ctx := context.Background()

	// Fetch user details on the account
	u, err := api.UserDetails(ctx)
	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(ctx, 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.

About

Go library for the Cloudflare v4 API

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%