Skip to content

Commit

Permalink
update zone id env
Browse files Browse the repository at this point in the history
  • Loading branch information
orvice committed Aug 16, 2023
1 parent b7d10ba commit fd0227b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions dns/cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,23 @@ func NewCloudFlare(key, email string, logger contract.Logger) (*CloudFlare, erro
func (c *CloudFlare) getZone(ctx context.Context, domain string) (*cloudflare.Zone, error) {
zones, err := c.client.ListZones(ctx)
if err != nil {
slog.Error("list zones error", "err", err)
return nil, err
}

for _, z := range zones {
if strings.Contains(domain, z.Name) {
slog.Info("get zone success", "zone", z.Name, "id", z.ID)
return &z, nil
}
}
return nil, fmt.Errorf("not found zone")
}

func (c *CloudFlare) GetDomainZoneID(domain string) (string, error) {
var domainID = os.Getenv("CF_DOMAIN_ID")
if domainID != "" {
return domainID, nil
var zoneID = os.Getenv("CF_ZONE_ID")
if zoneID != "" {
return zoneID, nil
}
zone, err := c.getZone(context.Background(), domain)
if err != nil {
Expand Down

0 comments on commit fd0227b

Please sign in to comment.