DNS resource record sets (RRsets) define individual DNS records such as A, AAAA, CNAME, MX, and TXT with TTL, geo-balancing, and failover settings.
Supported Record Types
- A - IPv4 address records
- AAAA - IPv6 address records
- CNAME - Canonical name (alias) records
- MX - Mail exchange records
- TXT - Text records
- SRV - Service locator records
- NS - Name server records
- SOA - Start of authority (managed automatically)
Create Record
Add a new DNS record to a zone. Records can be static or dynamic with advanced routing.
Simple A Record
ctx := context.Background()
record, err := client.DNS.Zones.Rrsets.New(ctx, "A", dns.ZoneRrsetNewParams{
ZoneName: "example.com",
RrsetName: "www",
Ttl: gcore.F(int64(3600)),
ResourceRecords: gcore.F([]dns.ZoneRrsetNewParamsResourceRecord{
{
Content: []any{"192.0.2.1"},
Enabled: gcore.F(true),
},
}),
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Record created: %s\n", record.Name)
Parameters
Record name (use ”@” for zone apex)
Record type: A, AAAA, CNAME, MX, TXT, SRV, NS
Array of resource records
Record content. Format varies by type:
- A:
["192.0.2.1"]
- AAAA:
["2001:db8::1"]
- CNAME:
["target.example.com"]
- MX:
[10, "mail.example.com"]
- TXT:
["v=spf1 include:_spf.example.com ~all"]
- SRV:
[100, 1, 5061, "sip.example.com"]
Whether this record is active
Metadata for geo-routing and load balancing (see Dynamic Records section)
Record Type Examples
record, err := client.DNS.Zones.Rrsets.New(ctx, "AAAA", dns.ZoneRrsetNewParams{
ZoneName: "example.com",
RrsetName: "www",
Ttl: gcore.F(int64(3600)),
ResourceRecords: gcore.F([]dns.ZoneRrsetNewParamsResourceRecord{
{
Content: []any{"2001:db8::1"},
Enabled: gcore.F(true),
},
}),
})
Dynamic Records with Geo-Routing
Dynamic RRsets enable advanced traffic routing based on user location, ASN, health checks, and weighted distribution.
Geo-Distance Routing
Route users to the nearest server based on geographic coordinates.
ctx := context.Background()
record, err := client.DNS.Zones.Rrsets.New(ctx, "A", dns.ZoneRrsetNewParams{
ZoneName: "example.com",
RrsetName: "www",
Ttl: gcore.F(int64(300)),
ResourceRecords: gcore.F([]dns.ZoneRrsetNewParamsResourceRecord{
{
Content: []any{"192.0.2.1"},
Enabled: gcore.F(true),
Meta: map[string]any{
"latlong": []float64{37.7749, -122.4194}, // San Francisco
"notes": "US West Coast server",
},
},
{
Content: []any{"192.0.2.2"},
Enabled: gcore.F(true),
Meta: map[string]any{
"latlong": []float64{40.7128, -74.0060}, // New York
"notes": "US East Coast server",
},
},
{
Content: []any{"192.0.2.3"},
Enabled: gcore.F(true),
Meta: map[string]any{
"latlong": []float64{51.5074, -0.1278}, // London
"notes": "EU server",
},
},
}),
Pickers: gcore.F([]dns.ZoneRrsetNewParamsPicker{
{
Type: "geodistance",
},
{
Type: "first_n",
Limit: gcore.F(int64(1)),
},
}),
})
Country-Based Routing
Route traffic based on user’s country.
record, err := client.DNS.Zones.Rrsets.New(ctx, "A", dns.ZoneRrsetNewParams{
ZoneName: "example.com",
RrsetName: "www",
Ttl: gcore.F(int64(300)),
ResourceRecords: gcore.F([]dns.ZoneRrsetNewParamsResourceRecord{
{
Content: []any{"192.0.2.1"},
Meta: map[string]any{
"countries": []string{"us", "ca", "mx"},
},
},
{
Content: []any{"192.0.2.2"},
Meta: map[string]any{
"countries": []string{"de", "fr", "gb"},
},
},
{
Content: []any{"192.0.2.3"},
Meta: map[string]any{
"default": true, // Fallback for other countries
},
},
}),
Pickers: gcore.F([]dns.ZoneRrsetNewParamsPicker{
{
Type: "geodns",
Strict: gcore.F(false),
},
}),
})
Weighted Load Balancing
Distribute traffic based on weights.
record, err := client.DNS.Zones.Rrsets.New(ctx, "A", dns.ZoneRrsetNewParams{
ZoneName: "example.com",
RrsetName: "www",
Ttl: gcore.F(int64(300)),
ResourceRecords: gcore.F([]dns.ZoneRrsetNewParamsResourceRecord{
{
Content: []any{"192.0.2.1"},
Meta: map[string]any{
"weight": 70, // 70% of traffic
},
},
{
Content: []any{"192.0.2.2"},
Meta: map[string]any{
"weight": 30, // 30% of traffic
},
},
}),
Pickers: gcore.F([]dns.ZoneRrsetNewParamsPicker{
{
Type: "weighted_shuffle",
},
{
Type: "first_n",
Limit: gcore.F(int64(2)),
},
}),
})
Picker Types
Pickers are applied in order to determine which records are returned.
Selectors
Filter records by IP, ASN, region, country, or continent
strict: true - Return no answers if no match found
strict: false - Return all records if no match found
Select records matching requestor’s ASN
Select records matching requestor’s country
Select records matching requestor’s continent
Select records matching requestor’s region (e.g., “fr-nor” for France/Normandy)
Select records matching requestor’s IP subnet (max 100 subnets per record)
Select records marked with "default": true in metadata
Mutators
Sort records by distance from requestor (requires latlong metadata)
Randomize records based on weight metadata (default weight: 50)
Filters
Return only the first N records
limit: 1 - Return only first record
limit: 0 - Return all records (no limit)
Health Checks and Failover
Configure health checks to automatically failover to backup servers.
record, err := client.DNS.Zones.Rrsets.New(ctx, "A", dns.ZoneRrsetNewParams{
ZoneName: "example.com",
RrsetName: "www",
Ttl: gcore.F(int64(60)),
ResourceRecords: gcore.F([]dns.ZoneRrsetNewParamsResourceRecord{
{
Content: []any{"192.0.2.1"},
Enabled: gcore.F(true),
},
{
Content: []any{"192.0.2.2"},
Enabled: gcore.F(true),
Meta: map[string]any{
"backup": true,
},
},
}),
Meta: map[string]any{
"failover": map[string]any{
"protocol": "HTTP",
"port": 443,
"frequency": 30,
"timeout": 5,
"method": "GET",
"url": "/health",
"tls": true,
"http_status_code": 200,
"host": "www.example.com",
},
},
})
Failover Configuration
Health check protocol: HTTP, TCP, UDP, ICMP
Check frequency in seconds (10-3600)
Timeout in seconds (1-10)
HTTP method (only for HTTP protocol)
URL path to check (only for HTTP protocol)
Use HTTPS (only for HTTP protocol)
Host header (only for HTTP protocol)
failover.http_status_code
Expected HTTP status code (only for HTTP protocol)
Regular expression to match in response (non-ICMP protocols)
Bytes to send (only for TCP/UDP protocols)
List Records
Retrieve all records in a zone.
ctx := context.Background()
response, err := client.DNS.Zones.Rrsets.List(ctx, "example.com", dns.ZoneRrsetListParams{
Limit: gcore.F(int64(50)),
Offset: gcore.F(int64(0)),
OrderBy: gcore.F("name"),
OrderDirection: gcore.F(dns.ZoneRrsetListParamsOrderDirectionAsc),
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Total records: %d\n", response.TotalAmount)
for _, rrset := range response.Rrsets {
fmt.Printf("%s %s %d\n", rrset.Name, rrset.Type, rrset.Ttl)
}
Get Record
Retrieve a specific DNS record.
ctx := context.Background()
record, err := client.DNS.Zones.Rrsets.Get(ctx, "A", dns.ZoneRrsetGetParams{
ZoneName: "example.com",
RrsetName: "www",
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s %s TTL=%d\n", record.Name, record.Type, record.Ttl)
for _, rr := range record.ResourceRecords {
fmt.Printf(" Content: %v\n", rr.Content)
}
Update Record
Update an existing DNS record. This replaces all resource records.
ctx := context.Background()
record, err := client.DNS.Zones.Rrsets.Replace(ctx, "A", dns.ZoneRrsetReplaceParams{
ZoneName: "example.com",
RrsetName: "www",
Ttl: gcore.F(int64(1800)),
ResourceRecords: gcore.F([]dns.ZoneRrsetReplaceParamsResourceRecord{
{
Content: []any{"192.0.2.10"},
Enabled: gcore.F(true),
},
{
Content: []any{"192.0.2.11"},
Enabled: gcore.F(true),
},
}),
})
if err != nil {
log.Fatal(err)
}
Delete Record
Delete a DNS record from a zone.
ctx := context.Background()
err := client.DNS.Zones.Rrsets.Delete(ctx, "A", dns.ZoneRrsetDeleteParams{
ZoneName: "example.com",
RrsetName: "www",
})
if err != nil {
log.Fatal(err)
}
fmt.Println("Record deleted successfully")
Get Failover History
Retrieve the failover event log for a record with health checks.
ctx := context.Background()
logs, err := client.DNS.Zones.Rrsets.GetFailoverLogs(ctx, "A", dns.ZoneRrsetGetFailoverLogsParams{
ZoneName: "example.com",
RrsetName: "www",
Limit: gcore.F(int64(100)),
Offset: gcore.F(int64(0)),
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Total events: %d\n", logs.TotalAmount)
for _, event := range logs.Log {
timestamp := time.Unix(event.Time, 0)
fmt.Printf("%s: %s - %s\n", timestamp, event.Address, event.Action)
}
Use these metadata fields on individual resource records for advanced routing:
Array of autonomous system numbers (e.g., [1234, 5678])
Array of continent codes: af, an, eu, as, na, sa, oc
Array of ISO country codes (e.g., ["us", "ca", "mx"])
Array of region codes (e.g., ["de-bw", "de-by"])
Array of CIDR ranges (e.g., ["192.168.15.0/24", "2003:de:2016::/48"])
Coordinates as [latitude, longitude] (e.g., [52.520008, 13.404954])
Weight for weighted_shuffle picker (0-100)
Mark as default/fallback record
Mark as backup record for failover
Human-readable notes about the record
Complete Example
Complex geo-routed record with health checks and failover:
ctx := context.Background()
record, err := client.DNS.Zones.Rrsets.New(ctx, "A", dns.ZoneRrsetNewParams{
ZoneName: "example.com",
RrsetName: "api",
Ttl: gcore.F(int64(60)),
ResourceRecords: gcore.F([]dns.ZoneRrsetNewParamsResourceRecord{
{
Content: []any{"192.0.2.1"},
Enabled: gcore.F(true),
Meta: map[string]any{
"countries": []string{"us", "ca"},
"latlong": []float64{37.7749, -122.4194},
"weight": 70,
"notes": "US West primary",
},
},
{
Content: []any{"192.0.2.2"},
Enabled: gcore.F(true),
Meta: map[string]any{
"countries": []string{"us", "ca"},
"latlong": []float64{37.7749, -122.4194},
"weight": 30,
"notes": "US West secondary",
},
},
{
Content: []any{"192.0.2.3"},
Enabled: gcore.F(true),
Meta: map[string]any{
"countries": []string{"de", "fr", "gb"},
"latlong": []float64{51.5074, -0.1278},
"notes": "EU primary",
},
},
{
Content: []any{"192.0.2.4"},
Enabled: gcore.F(true),
Meta: map[string]any{
"default": true,
"backup": true,
"notes": "Global fallback",
},
},
}),
Pickers: gcore.F([]dns.ZoneRrsetNewParamsPicker{
{
Type: "geodns",
Strict: gcore.F(false),
},
{
Type: "geodistance",
},
{
Type: "weighted_shuffle",
},
{
Type: "first_n",
Limit: gcore.F(int64(2)),
},
}),
Meta: map[string]any{
"failover": map[string]any{
"protocol": "HTTPS",
"port": 443,
"frequency": 30,
"timeout": 5,
"method": "GET",
"url": "/health",
"tls": true,
"http_status_code": 200,
},
},
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Created dynamic record: %s\n", record.Name)
This example:
- Filters by country (geodns)
- Sorts by distance to user (geodistance)
- Randomly distributes based on weights (weighted_shuffle)
- Returns 2 closest servers (first_n)
- Monitors health and automatically fails over unhealthy servers