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

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) {
defer func() {
recover()
r = admin_info{ "tuntap": admin_info{ "none": admin_info{ } } }
r = admin_info{"none": admin_info{}}
e = nil
}()
@ -278,7 +278,7 @@ func (a *admin) handleRequest(conn net.Conn) {
if _, ok := recv[arg]; !ok {
send = admin_info{
"status": "error",
"error": "Expected field missing",
"error": "Expected field missing: " + arg,
"expecting": arg,
}
break handlers

View File

@ -61,7 +61,7 @@ func main() {
if err := decoder.Decode(&recv); err == nil {
if recv["status"] == "error" {
if err, ok := recv["error"]; ok {
fmt.Println(err)
fmt.Println("Error:", err)
} else {
fmt.Println("Unspecified error occured")
}
@ -77,16 +77,11 @@ func main() {
}
req := recv["request"].(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"] {
case "dot":
fmt.Println(res["dot"])
default:
case "help", "getPeers", "getSwitchPeers", "getDHT", "getSessions":
maxWidths := make(map[string]int)
var keyOrder []string
keysOrdered := false
@ -129,7 +124,20 @@ func main() {
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))
}
}
}