DNS zones are authoritative containers for domain name records, with support for DNSSEC and SOA configuration.
Create Zone
Create a new DNS zone.
ctx := context.Background()
zone, err := client.DNS.Zones.New(ctx, dns.ZoneNewParams{
Name: gcore.F("example.com"),
Contact: gcore.F("[email protected]"),
Enabled: gcore.F(true),
Ttl: gcore.F(int64(3600)),
Refresh: gcore.F(int64(10800)),
Retry: gcore.F(int64(3600)),
Expiry: gcore.F(int64(604800)),
NxTtl: gcore.F(int64(300)),
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Zone ID: %d\n", zone.ID)
Parameters
Name of the DNS zone (e.g., “example.com”)
Email address of the administrator responsible for this zone
If disabled, zone records will not be resolved on DNS servers
Primary master name server for the zone
Seconds after which secondary name servers should query the master for SOA record to detect zone changes
Seconds after which secondary name servers should retry to request the serial number
Seconds after which secondary name servers should stop answering requests for this zone
Time To Live for negative caching (NXDOMAIN responses)
Serial number for zone version tracking. If not specified, timestamp will be used
Arbitrary metadata in JSON format. Can include:
webhook - URL to receive notifications about zone changes
webhook_method - HTTP method for webhook (default: POST)
Response Fields
Unique identifier for the created zone
Array of warning messages, if any
List Zones
Retrieve a list of DNS zones with filtering and pagination.
ctx := context.Background()
response, err := client.DNS.Zones.List(ctx, dns.ZoneListParams{
Enabled: gcore.F(true),
Limit: gcore.F(int64(50)),
Offset: gcore.F(int64(0)),
OrderBy: gcore.F("name"),
OrderDirection: gcore.F(dns.ZoneListParamsOrderDirectionAsc),
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Total zones: %d\n", response.TotalAmount)
for _, zone := range response.Zones {
fmt.Printf("Zone: %s (ID: %d, Enabled: %v)\n", zone.Name, zone.ID, zone.Enabled)
}
Query Parameters
Maximum number of records to return
Number of records to skip before beginning to return results
Filter by enabled/disabled status
Filter zones with dynamic RRsets
Filter zones with RRsets that have healthchecks enabled
Filter by zone names (can pass multiple values)
Get Zone
Retrieve detailed information about a specific zone.
ctx := context.Background()
zone, err := client.DNS.Zones.Get(ctx, "example.com")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Zone: %s\n", zone.Name)
fmt.Printf("Enabled: %v\n", zone.Enabled)
fmt.Printf("DNSSEC: %v\n", zone.DnssecEnabled)
fmt.Printf("Total records: %d\n", zone.RrsetsAmount.Total)
Path Parameters
Zone name (e.g., “example.com”)
Update Zone
Update zone configuration and SOA record.
ctx := context.Background()
zone, err := client.DNS.Zones.Replace(ctx, "example.com", dns.ZoneReplaceParams{
Name: gcore.F("example.com"),
Contact: gcore.F("[email protected]"),
Enabled: gcore.F(true),
Refresh: gcore.F(int64(7200)),
Retry: gcore.F(int64(1800)),
Expiry: gcore.F(int64(1209600)),
NxTtl: gcore.F(int64(600)),
})
if err != nil {
log.Fatal(err)
}
Path Parameters
Delete Zone
Delete a DNS zone and all its records.
ctx := context.Background()
err := client.DNS.Zones.Delete(ctx, "example.com")
if err != nil {
log.Fatal(err)
}
fmt.Println("Zone deleted successfully")
Path Parameters
Enable/Disable Zone
Enable or disable DNS resolution for a zone.
ctx := context.Background()
err := client.DNS.Zones.Enable(ctx, "example.com")
if err != nil {
log.Fatal(err)
}
Check Delegation Status
Verify if a domain is properly delegated to Gcore name servers. This endpoint is rate-limited.
ctx := context.Background()
status, err := client.DNS.Zones.CheckDelegationStatus(ctx, "example.com")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Zone exists: %v\n", status.ZoneExists)
fmt.Printf("Gcore authorized: %d\n", status.GcoreAuthorizedCount)
fmt.Printf("Non-Gcore authorized: %d\n", status.NonGcoreAuthorizedCount)
fmt.Printf("Whitelabel delegation: %v\n", status.IsWhitelabelDelegation)
Get Zone Statistics
Retrieve DNS query statistics for a zone. Use all as the zone name to get statistics for all zones.
ctx := context.Background()
stats, err := client.DNS.Zones.GetStatistics(ctx, "example.com", dns.ZoneGetStatisticsParams{
From: gcore.F(int64(1709068637)),
To: gcore.F(int64(1709673437)),
Granularity: gcore.F("1h"),
RecordType: gcore.F("A"),
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Total requests: %d\n", stats.Total)
Query Parameters
Beginning of time period (Unix timestamp, UTC)
End of time period (Unix timestamp, UTC)
Time interval granularity (e.g., “5m”, “1h”, “1d”). Valid units: s, m, h
Filter by DNS record type: A, AAAA, NS, CNAME, MX, TXT, SVCB, HTTPS
Statistics are updated in near real-time, typically within 30 minutes.
Import Zone
Import DNS records in BIND9 format.
ctx := context.Background()
bindZoneFile := `
$TTL 3600
@ IN SOA ns1.example.com. admin.example.com. (
2024010101 ; serial
10800 ; refresh
3600 ; retry
604800 ; expire
300 ) ; minimum
IN NS ns1.example.com.
IN NS ns2.example.com.
IN A 192.0.2.1
www IN A 192.0.2.2
`
result, err := client.DNS.Zones.Import(ctx, "example.com", dns.ZoneImportParams{
Body: bindZoneFile,
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Success: %v\n", result.Success)
fmt.Printf("Imported RRsets: %d\n", result.Imported.Rrsets)
fmt.Printf("Resource records: %d\n", result.Imported.ResourceRecords)
Export Zone
Export zone records in BIND9 format.
ctx := context.Background()
export, err := client.DNS.Zones.Export(ctx, "example.com")
if err != nil {
log.Fatal(err)
}
fmt.Println(export.RawZone)
DNSSEC Management
Enable DNSSEC
Enable DNSSEC for a DNS zone and retrieve DS records.
ctx := context.Background()
response, err := client.DNS.Zones.Dnssec.Update(ctx, "example.com", dns.ZoneDnssecUpdateParams{
Enabled: gcore.F(true),
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("DS Record: %s\n", response.Ds)
fmt.Printf("Algorithm: %s\n", response.Algorithm)
fmt.Printf("Key Tag: %d\n", response.KeyTag)
Retrieve DNSSEC DS records for a zone.
ctx := context.Background()
dnssec, err := client.DNS.Zones.Dnssec.Get(ctx, "example.com")
if err != nil {
log.Fatal(err)
}
fmt.Printf("DS Record: %s\n", dnssec.Ds)
Disable DNSSEC
ctx := context.Background()
err := client.DNS.Zones.Dnssec.Update(ctx, "example.com", dns.ZoneDnssecUpdateParams{
Enabled: gcore.F(false),
})
if err != nil {
log.Fatal(err)
}