Skip to content

Commit

Permalink
Add few helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
denverdino committed Feb 17, 2018
1 parent 724ac7f commit 0d997d2
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion pvtz/records.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package pvtz

import (
"log"
"github.com/denverdino/aliyungo/common"
//"github.com/denverdino/aliyungo/util"
)

type RecordStatus string
Expand All @@ -20,6 +20,7 @@ type DescribeZoneRecordsArgs struct {

//
type ZoneRecordType struct {
RecordId int64
Rr string
Type string
Ttl int
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0d997d2

Please sign in to comment.