Browse Source

Add removeRecord

master
Steven Polley 3 years ago
parent
commit
400163d63c
  1. 30
      zones.go

30
zones.go

@ -51,22 +51,18 @@ func (client *EasyDNSClient) GetRecordList(domain string) (*RecordList, error) {
if err != nil {
return nil, fmt.Errorf("http request failed to '%s': %v", endpoint, err)
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("expected HTTP status of '200', got '%s'", resp.Status)
}
recordList := &RecordList{}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("failed to read response body to byte slice: %v", err)
}
err = json.Unmarshal(body, recordList)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal response to RecordList: %v", err)
}
return recordList, nil
}
@ -78,9 +74,7 @@ func (client *EasyDNSClient) CreateRecord(domain, host, recordType, rdata, ttl,
Prio: prio,
Type: recordType,
Rdata: rdata}
endpoint := fmt.Sprintf("%s/zones/records/add/%s/%s?_key=%s&_user=%s&format=json", client.BaseURL, domain, recordType, client.ApiKey, client.ApiToken)
body, err := json.Marshal(record)
if err != nil {
return fmt.Errorf("failed to marshal record to struct: %v", err)
@ -89,7 +83,6 @@ func (client *EasyDNSClient) CreateRecord(domain, host, recordType, rdata, ttl,
if err != nil {
return fmt.Errorf("put request failed: %v", err)
}
return nil
}
@ -99,18 +92,35 @@ func (client *EasyDNSClient) ModifyRecord(id, host, recordType, rdata, ttl strin
TTL: ttl,
Type: recordType,
Rdata: rdata}
endpoint := fmt.Sprintf("%s/zones/records/%s?_key=%s&_user=%s&format=json", client.BaseURL, id, client.ApiKey, client.ApiToken)
body, err := json.Marshal(record)
if err != nil {
return fmt.Errorf("failed to marshal record to struct: %v", err)
}
_, err = http.Post(endpoint, "POST", bytes.NewBuffer(body))
if err != nil {
return fmt.Errorf("post request failed: %v", err)
}
return nil
}
func (client *EasyDNSClient) DeleteRecord(domain, id string) error {
endpoint := fmt.Sprintf("%s/zones/records/%s/%s?_key=%s&_user=%s&format=json", client.BaseURL, domain, id, client.ApiKey, client.ApiToken)
httpClient := &http.Client{}
req, err := http.NewRequest(http.MethodDelete, endpoint, nil)
if err != nil {
return fmt.Errorf("failed to create http delete request: %v", err)
}
resp, err := httpClient.Do(req)
if err != nil {
return fmt.Errorf("http delete request failed: %v", err)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("failed to read response body to byte slice: %v", err)
}
fmt.Println(string(body))
return nil
}

Loading…
Cancel
Save