@@ -2,6 +2,7 @@ package cloudflare
22
33import (
44 "encoding/json"
5+ "strings"
56 "time"
67
78 "github.com/libdns/libdns"
@@ -61,7 +62,7 @@ type cfDNSRecord struct {
6162 ZoneName string `json:"zone_name,omitempty"`
6263 CreatedOn time.Time `json:"created_on,omitempty"`
6364 ModifiedOn time.Time `json:"modified_on,omitempty"`
64- Data * struct {
65+ Data struct {
6566 // LOC
6667 LatDegrees int `json:"lat_degrees,omitempty"`
6768 LatMinutes int `json:"lat_minutes,omitempty"`
@@ -80,9 +81,9 @@ type cfDNSRecord struct {
8081 Service string `json:"service,omitempty"`
8182 Proto string `json:"proto,omitempty"`
8283 Name string `json:"name,omitempty"`
83- Priority int `json:"priority,omitempty"`
84- Weight int `json:"weight,omitempty"`
85- Port int `json:"port,omitempty"`
84+ Priority uint `json:"priority,omitempty"`
85+ Weight uint `json:"weight,omitempty"`
86+ Port uint `json:"port,omitempty"`
8687 Target string `json:"target,omitempty"`
8788
8889 // DNSKEY
@@ -109,6 +110,18 @@ type cfDNSRecord struct {
109110}
110111
111112func (r cfDNSRecord ) libdnsRecord (zone string ) libdns.Record {
113+ if r .Type == "SRV" {
114+ srv := libdns.SRV {
115+ Service : strings .TrimPrefix (r .Data .Service , "_" ),
116+ Proto : strings .TrimPrefix (r .Data .Proto , "_" ),
117+ Name : r .Data .Name ,
118+ Priority : r .Data .Priority ,
119+ Weight : r .Data .Weight ,
120+ Port : r .Data .Port ,
121+ Target : r .Data .Target ,
122+ }
123+ return srv .ToRecord ()
124+ }
112125 return libdns.Record {
113126 Type : r .Type ,
114127 Name : libdns .RelativeName (r .Name , zone ),
@@ -118,25 +131,44 @@ func (r cfDNSRecord) libdnsRecord(zone string) libdns.Record {
118131 }
119132}
120133
121- func cloudflareRecord (r libdns.Record ) cfDNSRecord {
122- return cfDNSRecord {
123- ID : r .ID ,
124- Type : r .Type ,
125- Name : r .Name ,
126- Content : r .Value ,
127- TTL : int (r .TTL .Seconds ()),
134+ func cloudflareRecord (r libdns.Record ) (cfDNSRecord , error ) {
135+ rec := cfDNSRecord {
136+ ID : r .ID ,
137+ Type : r .Type ,
138+ TTL : int (r .TTL .Seconds ()),
139+ }
140+ if r .Type == "SRV" {
141+ srv , err := r .ToSRV ()
142+ if err != nil {
143+ return cfDNSRecord {}, err
144+ }
145+ rec .Data .Service = "_" + srv .Service
146+ rec .Data .Priority = srv .Priority
147+ rec .Data .Weight = srv .Weight
148+ rec .Data .Proto = "_" + srv .Proto
149+ rec .Data .Name = srv .Name
150+ rec .Data .Port = srv .Port
151+ rec .Data .Target = srv .Target
152+ } else {
153+ rec .Name = r .Name
154+ rec .Content = r .Value
128155 }
156+ return rec , nil
129157}
130158
131159// All API responses have this structure.
132160type cfResponse struct {
133161 Result json.RawMessage `json:"result,omitempty"`
134162 Success bool `json:"success"`
135163 Errors []struct {
136- Code int `json:"code"`
137- Message string `json:"message"`
164+ Code int `json:"code"`
165+ Message string `json:"message"`
166+ ErrorChain []struct {
167+ Code int `json:"code"`
168+ Message string `json:"message"`
169+ } `json:"error_chain,omitempty"`
138170 } `json:"errors,omitempty"`
139- Messages []interface {} `json:"messages,omitempty"`
171+ Messages []any `json:"messages,omitempty"`
140172 ResultInfo * cfResultInfo `json:"result_info,omitempty"`
141173}
142174
0 commit comments