diff --git a/pvtz/records.go b/pvtz/records.go index 893e7ce8..b986601a 100644 --- a/pvtz/records.go +++ b/pvtz/records.go @@ -1,8 +1,8 @@ package pvtz import ( + "log" "github.com/denverdino/aliyungo/common" - //"github.com/denverdino/aliyungo/util" ) type RecordStatus string @@ -20,6 +20,7 @@ type DescribeZoneRecordsArgs struct { // type ZoneRecordType struct { + RecordId int64 Rr string Type string Ttl int @@ -63,6 +64,46 @@ func (client *Client) DescribeZoneRecords(args *DescribeZoneRecordsArgs) (record return result, nil } +func (client *Client) DescribeZoneRecordsByRR(zoneId string, rr string) (records []ZoneRecordType, err error) { + records, err = client.DescribeZoneRecords(&DescribeZoneRecordsArgs{ + ZoneId: zoneId, + Keyword: rr, + }) + + if err != nil { + return records, err + } + + result := make([]ZoneRecordType, 0, 0) + for _, record := range records { + if record.Rr == rr { + result = append(result, record) + } + } + return result, err +} + +func (client *Client) DeleteZoneRecordsByRR(zoneId string, rr string) error { + records, err := client.DescribeZoneRecordsByRR(zoneId, rr) + + if err != nil { + return err + } + + for _, record := range records { + if record.Rr == rr { + err := client.DeleteZoneRecord(&DeleteZoneRecordArgs{ + RecordId: record.RecordId, + }) + if err != nil { + log.Printf("failed to delete zone record %d: %v\n", record.RecordId, err) + } + } + } + return nil +} + + type AddZoneRecordArgs struct { ZoneName string Rr string