diff options
| author | Shulhan <ms@kilabit.info> | 2022-04-16 01:06:38 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-04-16 18:32:36 +0700 |
| commit | dfc441b32458d204dae6498867f08e7da483c815 (patch) | |
| tree | 5348dbd28424e24719fdc582f8881551c390f3d7 /cmd/resolver | |
| parent | f9338965943247d124174c79392033518dc06a5b (diff) | |
| download | rescached-dfc441b32458d204dae6498867f08e7da483c815.tar.xz | |
cmd/resolver: implement command to fetch and print server environment
The "env" command fetch the current server environment and print as
ini format to stdout.
Diffstat (limited to 'cmd/resolver')
| -rw-r--r-- | cmd/resolver/main.go | 23 | ||||
| -rw-r--r-- | cmd/resolver/resolver.go | 25 |
2 files changed, 47 insertions, 1 deletions
diff --git a/cmd/resolver/main.go b/cmd/resolver/main.go index 90a1686..90fcc68 100644 --- a/cmd/resolver/main.go +++ b/cmd/resolver/main.go @@ -16,6 +16,7 @@ import ( // List of valid commands. const ( cmdCaches = "caches" + cmdEnv = "env" cmdQuery = "query" subCmdSearch = "search" @@ -83,6 +84,9 @@ func main() { os.Exit(2) } + case cmdEnv: + rsol.doCmdEnv() + case cmdQuery: args = args[1:] if len(args) == 0 { @@ -165,6 +169,11 @@ caches remove <string> Remove the domain name from rescached caches. If the parameter is "all", it will remove all caches. +env + + Fetch the current server environment and print it as JSON format to + stdout. + == Examples @@ -197,5 +206,17 @@ Inspect the rescached's caches on server at http://127.0.0.1:5380, Search caches that contains "bit" on the domain name, - $ resolver -server=http://127.0.0.1:5380 caches search bit`) + $ resolver caches search bit + +Remove caches that contains domain name "kilabit.info", + + $ resolver caches remove kilabit.info + +Remove all caches in the server, + + $ resolver caches remove all + +Fetch and print current server environment, + + $ resolver env`) } diff --git a/cmd/resolver/resolver.go b/cmd/resolver/resolver.go index 1985981..b7129cc 100644 --- a/cmd/resolver/resolver.go +++ b/cmd/resolver/resolver.go @@ -4,6 +4,7 @@ package main import ( + "encoding/json" "fmt" "log" "math/rand" @@ -103,6 +104,30 @@ func (rsol *resolver) doCmdCachesSearch(q string) { printMessages(listMsg) } +func (rsol *resolver) doCmdEnv() { + var ( + resc = rsol.newRescachedClient() + + env *rescached.Environment + envJson []byte + err error + ) + + env, err = resc.Env() + if err != nil { + log.Printf("resolver: %s: %s", rsol.cmd, err) + return + } + + envJson, err = json.MarshalIndent(env, "", " ") + if err != nil { + log.Printf("resolver: %s: %s", rsol.cmd, err) + return + } + + fmt.Printf("%s\n", envJson) +} + func (rsol *resolver) doCmdQuery(args []string) { var ( maxAttempts = defAttempts |
