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:
parent
201701ae4a
commit
ca3e541d3b
@ -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
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user