Move yggdrasilctl request switch to separate function

This commit is contained in:
Alex Kotov 2021-07-22 23:24:21 +05:00
parent fa65253e57
commit 215351aefc

View file

@ -195,7 +195,6 @@ func run() int {
fmt.Println("Missing response body (malformed response?)")
return 1
}
req := recv["request"].(map[string]interface{})
res := recv["response"].(map[string]interface{})
if *injson {
@ -205,36 +204,7 @@ func run() int {
return 0
}
switch strings.ToLower(req["request"].(string)) {
case "dot":
runDot(res)
case "list", "getpeers", "getswitchpeers", "getdht", "getsessions", "dhtping":
runVariousInfo(res, verbose)
case "gettuntap", "settuntap":
runGetAndSetTunTap(res)
case "getself":
runGetSelf(res, verbose)
case "getswitchqueues":
runGetSwitchQueues(res)
case "addpeer", "removepeer", "addallowedencryptionpublickey", "removeallowedencryptionpublickey", "addsourcesubnet", "addroute", "removesourcesubnet", "removeroute":
runAddsAndRemoves(res)
case "getallowedencryptionpublickeys":
runGetAllowedEncryptionPublicKeys(res)
case "getmulticastinterfaces":
runGetMulticastInterfaces(res)
case "getsourcesubnets":
runGetSourceSubnets(res)
case "getroutes":
runGetRoutes(res)
case "settunnelrouting":
fallthrough
case "gettunnelrouting":
runGetTunnelRouting(res)
default:
if json, err := json.MarshalIndent(recv["response"], "", " "); err == nil {
fmt.Println(string(json))
}
}
runAll(recv, verbose)
} else {
logger.Println("Error receiving response:", err)
}
@ -245,6 +215,42 @@ func run() int {
return 0
}
func runAll(recv map[string]interface{}, verbose *bool) {
req := recv["request"].(map[string]interface{})
res := recv["response"].(map[string]interface{})
switch strings.ToLower(req["request"].(string)) {
case "dot":
runDot(res)
case "list", "getpeers", "getswitchpeers", "getdht", "getsessions", "dhtping":
runVariousInfo(res, verbose)
case "gettuntap", "settuntap":
runGetAndSetTunTap(res)
case "getself":
runGetSelf(res, verbose)
case "getswitchqueues":
runGetSwitchQueues(res)
case "addpeer", "removepeer", "addallowedencryptionpublickey", "removeallowedencryptionpublickey", "addsourcesubnet", "addroute", "removesourcesubnet", "removeroute":
runAddsAndRemoves(res)
case "getallowedencryptionpublickeys":
runGetAllowedEncryptionPublicKeys(res)
case "getmulticastinterfaces":
runGetMulticastInterfaces(res)
case "getsourcesubnets":
runGetSourceSubnets(res)
case "getroutes":
runGetRoutes(res)
case "settunnelrouting":
fallthrough
case "gettunnelrouting":
runGetTunnelRouting(res)
default:
if json, err := json.MarshalIndent(recv["response"], "", " "); err == nil {
fmt.Println(string(json))
}
}
}
func runDot(res map[string]interface{}) {
fmt.Println(res["dot"])
}