aboutsummaryrefslogtreecommitdiff
path: root/cmd/resolver
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-04-15 01:52:25 +0700
committerShulhan <ms@kilabit.info>2022-04-15 01:52:25 +0700
commit618ffca939c176b2faea4d18de756d58f1110639 (patch)
tree7cc43c0c9a3d7140fe1008775c75b22f4d68f94c /cmd/resolver
parent4d3ab7f49410eb2b774a7c9e25ba10a1efbd1413 (diff)
downloadrescached-618ffca939c176b2faea4d18de756d58f1110639.tar.xz
all: implement sub command to remove caches by domain name
The "caches" command accept second sub command "remove" that accept single domain name to be removed from caches. This changes affect the HTTP API for caches delete to return the removed answer on the response data.
Diffstat (limited to 'cmd/resolver')
-rw-r--r--cmd/resolver/main.go16
-rw-r--r--cmd/resolver/resolver.go22
2 files changed, 38 insertions, 0 deletions
diff --git a/cmd/resolver/main.go b/cmd/resolver/main.go
index 322ef85..0be5375 100644
--- a/cmd/resolver/main.go
+++ b/cmd/resolver/main.go
@@ -19,6 +19,7 @@ const (
cmdQuery = "query"
subCmdSearch = "search"
+ subCmdRemove = "remove"
)
func main() {
@@ -63,12 +64,23 @@ func main() {
subCmd = strings.ToLower(args[0])
switch subCmd {
+ case subCmdRemove:
+ args = args[1:]
+ if len(args) == 0 {
+ log.Fatalf("resolver: %s %s: missing argument", rsol.cmd, subCmd)
+ }
+ rsol.doCmdCachesRemove(args[0])
+
case subCmdSearch:
args = args[1:]
if len(args) == 0 {
log.Fatalf("resolver: %s %s: missing argument", rsol.cmd, subCmd)
}
rsol.doCmdCachesSearch(args[0])
+
+ default:
+ log.Printf("resolver: %s: unknown sub command: %s", rsol.cmd, subCmd)
+ os.Exit(2)
}
case cmdQuery:
@@ -148,6 +160,10 @@ caches search <string>
This command can also be used to inspect each DNS message on the
caches.
+caches remove <string>
+
+ Remove the domain name from rescached caches.
+
== Examples
diff --git a/cmd/resolver/resolver.go b/cmd/resolver/resolver.go
index 5ba632f..8804851 100644
--- a/cmd/resolver/resolver.go
+++ b/cmd/resolver/resolver.go
@@ -61,6 +61,28 @@ func (rsol *resolver) doCmdCaches() {
printAnswers(answers)
}
+// doCmdCachesRemove remove an answer from caches by domain name.
+func (rsol *resolver) doCmdCachesRemove(q string) {
+ var (
+ resc = rsol.newRescachedClient()
+
+ listAnswer []*dns.Answer
+ err error
+ )
+
+ listAnswer, err = resc.CachesRemove(q)
+ if err != nil {
+ log.Printf("resolver: caches: %s", err)
+ return
+ }
+
+ fmt.Printf("Total answer removed: %d\n", len(listAnswer))
+ if len(listAnswer) == 0 {
+ return
+ }
+ printAnswers(listAnswer)
+}
+
// doCmdCachesSearch call the rescached HTTP API to search the caches by
// domain name.
func (rsol *resolver) doCmdCachesSearch(q string) {