Created
May 3, 2022 00:30
-
-
Save alexanderturner/f2bd30094998e7d6068d386dbe2fe3ef to your computer and use it in GitHub Desktop.
Cloudflare Bulk Delete Records
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"log" | |
"github.com/cloudflare/cloudflare-go" | |
) | |
func main() { | |
// Construct a new API object using a global API key | |
api, err := cloudflare.New("token", "email") | |
// alternatively, you can use a scoped API token | |
// api, err := cloudflare.NewWithAPIToken(os.Getenv("CLOUDFLARE_API_TOKEN")) | |
if err != nil { | |
log.Fatal(err) | |
} | |
ctx := context.Background() | |
zoneID, err := api.ZoneIDByName("fluidhq.io") | |
if err != nil { | |
log.Fatal(err) | |
} | |
// Fetch all records for a zone | |
recs, err := api.DNSRecords(ctx, zoneID, cloudflare.DNSRecord{}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
for _, r := range recs { | |
err = api.DeleteDNSRecord(ctx, zoneID, r.ID) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Printf("%s: %s\n", r.Name, r.Content) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment