-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
52 lines (46 loc) · 1.18 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"bufio"
"fmt"
"os"
"regexp"
"strings"
)
func filterRecords(zone *PowerDNSZone, filter string) {
count := 0
for _, rrset := range zone.RRSets {
if filter == "" || matchFilter(rrset.Name, filter) {
for _, record := range rrset.Records {
fmt.Printf("%s (%s): %s\n", rrset.Name, rrset.Type,
record.Content)
count++
}
}
}
fmt.Printf("\nTotal records: %d\n", count)
}
func filterRecordsToDelete(zone *PowerDNSZone, filter string) []RRSet {
var recordsToDelete []RRSet
for _, rrset := range zone.RRSets {
if filter == "" || matchFilter(rrset.Name, filter) {
recordsToDelete = append(recordsToDelete, rrset)
}
}
return filterExcludedRecords(recordsToDelete, config.ExcludePattern)
}
func matchFilter(name, filter string) bool {
if filter == "" {
return true
}
matched, err := regexp.MatchString(filter, name)
if err != nil {
return false
}
return matched
}
func confirmDeletion(recordCount int) bool {
reader := bufio.NewReader(os.Stdin)
fmt.Printf("Are you sure you want to delete these %d records? (yes/no): ", recordCount)
response, _ := reader.ReadString('\n')
return strings.ToLower(strings.TrimSpace(response)) == "yes"
}