Fix DNS record JSON parsing for MCNS response format

MCNS returns records wrapped in {"records": [...]} envelope with
uppercase field names (ID, Name, Type, Value), not bare arrays
with lowercase fields.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-27 15:12:43 -07:00
parent 76247978c2
commit 2bda7fc138
2 changed files with 18 additions and 16 deletions

View File

@@ -28,11 +28,11 @@ type DNSRegistrar struct {
// dnsRecord is the JSON representation of an MCNS record.
type dnsRecord struct {
ID int `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Value string `json:"value"`
TTL int `json:"ttl"`
ID int `json:"ID"`
Name string `json:"Name"`
Type string `json:"Type"`
Value string `json:"Value"`
TTL int `json:"TTL"`
}
// NewDNSRegistrar creates a DNSRegistrar. Returns (nil, nil) if
@@ -157,11 +157,13 @@ func (d *DNSRegistrar) listRecords(ctx context.Context, serviceName string) ([]d
return nil, fmt.Errorf("list records: mcns returned %d: %s", resp.StatusCode, string(body))
}
var records []dnsRecord
if err := json.Unmarshal(body, &records); err != nil {
var envelope struct {
Records []dnsRecord `json:"records"`
}
if err := json.Unmarshal(body, &envelope); err != nil {
return nil, fmt.Errorf("parse list response: %w", err)
}
return records, nil
return envelope.Records, nil
}
// createRecord creates an A record in the zone.