Friendly formats for getDHT, getSessions, setTunTap etc

This commit is contained in:
Neil Alexander 2018-05-21 14:14:57 +01:00
parent 201701ae4a
commit ca3e541d3b
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
2 changed files with 25 additions and 17 deletions

View File

@ -136,7 +136,7 @@ func (a *admin) init(c *Core, listenaddr string) {
a.addHandler("getTunTap", []string{}, func(in admin_info) (r admin_info, e error) { a.addHandler("getTunTap", []string{}, func(in admin_info) (r admin_info, e error) {
defer func() { defer func() {
recover() recover()
r = admin_info{ "tuntap": admin_info{ "none": admin_info{ } } } r = admin_info{"none": admin_info{}}
e = nil e = nil
}() }()
@ -278,7 +278,7 @@ func (a *admin) handleRequest(conn net.Conn) {
if _, ok := recv[arg]; !ok { if _, ok := recv[arg]; !ok {
send = admin_info{ send = admin_info{
"status": "error", "status": "error",
"error": "Expected field missing", "error": "Expected field missing: " + arg,
"expecting": arg, "expecting": arg,
} }
break handlers break handlers

View File

@ -61,7 +61,7 @@ func main() {
if err := decoder.Decode(&recv); err == nil { if err := decoder.Decode(&recv); err == nil {
if recv["status"] == "error" { if recv["status"] == "error" {
if err, ok := recv["error"]; ok { if err, ok := recv["error"]; ok {
fmt.Println(err) fmt.Println("Error:", err)
} else { } else {
fmt.Println("Unspecified error occured") fmt.Println("Unspecified error occured")
} }
@ -77,16 +77,11 @@ func main() {
} }
req := recv["request"].(map[string]interface{}) req := recv["request"].(map[string]interface{})
res := recv["response"].(map[string]interface{}) res := recv["response"].(map[string]interface{})
defer func() {
recover()
if json, err := json.MarshalIndent(recv["response"], "", " "); err == nil {
fmt.Println(string(json))
}
}()
switch req["request"] { switch req["request"] {
case "dot": case "dot":
fmt.Println(res["dot"]) fmt.Println(res["dot"])
default: case "help", "getPeers", "getSwitchPeers", "getDHT", "getSessions":
maxWidths := make(map[string]int) maxWidths := make(map[string]int)
var keyOrder []string var keyOrder []string
keysOrdered := false keysOrdered := false
@ -129,7 +124,20 @@ func main() {
fmt.Println() fmt.Println()
} }
} }
case "getTunTap", "setTunTap":
for k, v := range res {
fmt.Println("Interface name:", k)
if mtu, ok := v.(map[string]interface{})["mtu"].(float64); ok {
fmt.Println("Interface MTU:", mtu)
}
if tap_mode, ok := v.(map[string]interface{})["tap_mode"].(bool); ok {
fmt.Println("TAP mode:", tap_mode)
}
}
default:
if json, err := json.MarshalIndent(recv["response"], "", " "); err == nil {
fmt.Println(string(json))
}
} }
} }