gocloudflare

ZoneIDByName() no longer available in cloudflare-go/v4


I'm updating an old Golang application that used the Cloudflare-go sdk to update dns records.

I decided to switch to v4 of the API, but some functions are no longer available, and I can't figure out what the new method is supposed to be.

Previous code was something like this:

import "github.com/cloudflare/cloudflare-go"
...
id, err := api.ZoneIDByName(domain)

So I replaced github.com/cloudflare/cloudflare-go with github.com/cloudflare/cloudflare-go/v4, but it seems ZoneIDByName() is no longer available. I'm going through the docs at https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/zones, but I don't see any function that has "ByName" in the name.

How am I supposed to find the id of a zone now?


Solution

  • Try ZoneService.List :

        res, err := client.Zones.List(context.TODO(), zones.ZoneListParams{
            Name: cloudflare.F(domain),
        })
    

    match equal is the default.