5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-10 05:10:26 +00:00

Allow JSON output using -json argument

This commit is contained in:
Neil Alexander 2018-05-21 14:29:27 +01:00
parent 61c640dbde
commit cc4ee91279
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944

View File

@ -13,11 +13,12 @@ type admin_info map[string]interface{}
func main() {
server := flag.String("endpoint", "localhost:9001", "Admin socket endpoint")
injson := flag.Bool("json", false, "Output in JSON format")
flag.Parse()
args := flag.Args()
if len(args) == 0 {
fmt.Println("usage:", os.Args[0], "[-endpoint=localhost:9001] command [key=value] [...]")
fmt.Println("usage:", os.Args[0], "[-endpoint=localhost:9001] [-json] command [key=value] [...]")
fmt.Println("example:", os.Args[0], "getPeers")
fmt.Println("example:", os.Args[0], "setTunTap name=auto mtu=1500 tap_mode=false")
fmt.Println("example:", os.Args[0], "-endpoint=localhost:9001 getDHT")
@ -78,6 +79,13 @@ func main() {
req := recv["request"].(map[string]interface{})
res := recv["response"].(map[string]interface{})
if *injson {
if json, err := json.MarshalIndent(res, "", " "); err == nil {
fmt.Println(string(json))
}
os.Exit(0)
}
switch req["request"] {
case "dot":
fmt.Println(res["dot"])