mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-27 12:05:23 +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) {
|
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
|
||||||
|
@ -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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user