Added Set data structure. This caused by fact that two NS may have same domains
This commit is contained in:
@ -132,7 +132,7 @@ func (c *client) UpdateRecord(rec *dns.Record) (error, *dns.Response) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) GetRecords() (error, []*dns.Record) {
|
func (c *client) GetRecords() (error, []*dns.Record) {
|
||||||
var subdomains []*dns.Record
|
var subdomains = CreateSet()
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
result_chan := make(chan []*dns.Record)
|
result_chan := make(chan []*dns.Record)
|
||||||
@ -169,10 +169,12 @@ func (c *client) GetRecords() (error, []*dns.Record) {
|
|||||||
select {
|
select {
|
||||||
case records, ok := <-result_chan:
|
case records, ok := <-result_chan:
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, subdomains
|
return nil, subdomains.List()
|
||||||
}
|
}
|
||||||
|
|
||||||
subdomains = append(subdomains, records...)
|
for record := range records {
|
||||||
|
subdomains.Add(record)
|
||||||
|
}
|
||||||
case _, _ = <-err_chan:
|
case _, _ = <-err_chan:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
33
set.go
Normal file
33
set.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package dnsexit_manager
|
||||||
|
|
||||||
|
|
||||||
|
type Set struct {
|
||||||
|
elements map[interface{}]struct{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateSet() *Set {
|
||||||
|
return &Set{
|
||||||
|
elements: make(map[interface{}]struct{}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (set *Set) Add(value interface{}) {
|
||||||
|
_, found := set.elements[value]
|
||||||
|
|
||||||
|
if !found{
|
||||||
|
set.elements[value] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (set *Set) Delete(value interface{}) {
|
||||||
|
delete(set.elements, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (set *Set) List() []interface{} {
|
||||||
|
keys := make([]interface{}, 0, len(set.elements))
|
||||||
|
for key := range set.elements {
|
||||||
|
keys = append(keys, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
return keys
|
||||||
|
}
|
Reference in New Issue
Block a user