add get zone func

This commit is contained in:
Jay 2019-05-02 21:51:30 +08:00
parent 99a0f794cb
commit 8a536a37d0

View File

@ -22,6 +22,7 @@ var client *AWSClient
// Error messages // Error messages
var ( var (
ErrNoClient = errors.New("client not init") ErrNoClient = errors.New("client not init")
ErrNoZone = errors.New("no hosted zones")
) )
// NewAWS - // NewAWS -
@ -56,7 +57,65 @@ type ZoneData struct {
} }
// QueryDomain - // QueryDomain -
func QueryDomain() (*ZoneData, error) { func QueryDomain(name []string) ([]*ZoneData, error) {
if client == nil {
return nil, ErrNoClient
}
domains := make([]string, 0, len(name))
if len(name) == 0 {
return nil, errors.New("no input domain name")
}
for _, n := range name {
if len(n) > 0 {
if n[len(n)-1:] != "." {
n += "."
}
domains = append(domains, n)
}
}
if len(domains) == 0 {
return nil, errors.New("no input domain name")
}
input := &route53.ListHostedZonesInput{}
zoneOut, err := client.R53.ListHostedZones(input)
if err != nil {
return nil, err
}
if len(zoneOut.HostedZones) == 0 {
return nil, ErrNoZone
}
zones := make([]*ZoneData, 0)
for _, it := range zoneOut.HostedZones {
for _, domain := range domains {
if *it.Name == domain {
zone := &ZoneData{
ID: it.Id,
Name: domain,
}
zones = append(zones, zone)
}
}
}
return zones, nil
}
// GetRecord -
func GetRecord(id *string, names []string) (*[]route53.ResourceRecordSet, error) {
if id == nil {
return nil, errors.New("no id input")
}
if len(names) == 0 {
return nil, errors.New("no record names")
}
input := &route53.ListResourceRecordSetsInput{}
input.SetHostedZoneId(*id)
resOut, err := client.R53.ListResourceRecordSets(input)
if err != nil {
return nil, err
}
return nil, nil return nil, nil
} }