feat: add mode selecting #15

Merged
t.behrendt merged 5 commits from fix-main-loop into main 2024-12-23 14:17:47 +01:00
Showing only changes of commit 9478149a20 - Show all commits

View File

@@ -83,6 +83,8 @@ func (i *IonosAPIImpl) HttpCall(method string, url string, body io.Reader) (*htt
} }
req.Header.Add("X-API-Key", i.APIKey) req.Header.Add("X-API-Key", i.APIKey)
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Accept", "application/json")
return i.HTTPClient.Do(req) return i.HTTPClient.Do(req)
} }
@@ -121,10 +123,10 @@ func (i *IonosAPIImpl) GetRecordId(zoneId string, tld string, subdomain string,
json.Unmarshal(responseBody, &zone) json.Unmarshal(responseBody, &zone)
var domain string var domain string
if subdomain != "" { if subdomain == "@" || subdomain == "" {
domain = subdomain + "." + tld
} else {
domain = tld domain = tld
} else {
domain = subdomain + "." + tld
} }
for _, record := range zone.Records { for _, record := range zone.Records {
@@ -162,12 +164,14 @@ func (i *IonosAPIImpl) SetARecord(tld string, subdomain string, ip net.IP, ttl i
return nil, err return nil, err
} }
responseBody := make([]byte, res.ContentLength)
res.Body.Read(responseBody)
if res.StatusCode != 200 { if res.StatusCode != 200 {
return nil, errors.New("error updating record") return nil, errors.New("error updating record")
} }
responseBody := make([]byte, res.ContentLength)
res.Body.Read(responseBody)
changeRecord := ChangeRecord{} changeRecord := ChangeRecord{}
json.Unmarshal(responseBody, &changeRecord) json.Unmarshal(responseBody, &changeRecord)