added JSON response for IPTables
This commit is contained in:
44
Bindings/Client.go
Normal file
44
Bindings/Client.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package Bindings
|
||||||
|
|
||||||
|
import "C"
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/Akilan1999/p2p-rendering-computation/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The Client package where data-types
|
||||||
|
// are manually converted to the
|
||||||
|
// to a string so that it can
|
||||||
|
// be export
|
||||||
|
|
||||||
|
//export StartContainer
|
||||||
|
func StartContainer(IP string, NumPorts int, GPU bool, ContainerName string, baseImage string) (output string) {
|
||||||
|
container, err := client.StartContainer(IP, NumPorts, GPU, ContainerName, baseImage)
|
||||||
|
if err != nil {
|
||||||
|
return err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonBytes, err := json.Marshal(container)
|
||||||
|
if err != nil {
|
||||||
|
return err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert the JSON bytes to a string
|
||||||
|
return string(jsonBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
//export GetSpecs
|
||||||
|
func GetSpecs(IP string) (output string) {
|
||||||
|
specs, err := client.GetSpecs(IP)
|
||||||
|
if err != nil {
|
||||||
|
return err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonBytes, err := json.Marshal(specs)
|
||||||
|
if err != nil {
|
||||||
|
return err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert the JSON bytes to a string
|
||||||
|
return string(jsonBytes)
|
||||||
|
}
|
||||||
@@ -118,17 +118,17 @@ func (i *IpAddresses) WriteIpTable() error {
|
|||||||
// PrintIpTable Print Ip table data for Cli
|
// PrintIpTable Print Ip table data for Cli
|
||||||
func PrintIpTable() error {
|
func PrintIpTable() error {
|
||||||
table, err := ReadIpTable()
|
table, err := ReadIpTable()
|
||||||
|
//
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
//
|
||||||
for i := 0; i < len(table.IpAddress); i++ {
|
//for i := 0; i < len(table.IpAddress); i++ {
|
||||||
fmt.Printf("\nMachine Name: %s\nIP Address: %s\nIPV6: %s\nLatency: %s\nServerPort: %s\nbehindNAT: %s\nEscapeImplementation: %s\n-----------"+
|
// fmt.Printf("\nMachine Name: %s\nIP Address: %s\nIPV6: %s\nLatency: %s\nServerPort: %s\nbehindNAT: %s\nEscapeImplementation: %s\n-----------"+
|
||||||
"-----------------\n", table.IpAddress[i].Name, table.IpAddress[i].Ipv4, table.IpAddress[i].Ipv6,
|
// "-----------------\n", table.IpAddress[i].Name, table.IpAddress[i].Ipv4, table.IpAddress[i].Ipv6,
|
||||||
table.IpAddress[i].Latency, table.IpAddress[i].ServerPort, table.IpAddress[i].NAT, table.IpAddress[i].EscapeImplementation)
|
// table.IpAddress[i].Latency, table.IpAddress[i].ServerPort, table.IpAddress[i].NAT, table.IpAddress[i].EscapeImplementation)
|
||||||
}
|
//}
|
||||||
//PrettyPrint(table)
|
PrettyPrint(table)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -255,13 +255,13 @@ func Ip4or6(s string) string {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//func PrettyPrint(data interface{}) {
|
func PrettyPrint(data interface{}) {
|
||||||
// var p []byte
|
var p []byte
|
||||||
// // var err := error
|
// var err := error
|
||||||
// p, err := json.MarshalIndent(data, "", "\t")
|
p, err := json.MarshalIndent(data, "", "\t")
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// fmt.Println(err)
|
fmt.Println(err)
|
||||||
// return
|
return
|
||||||
// }
|
}
|
||||||
// fmt.Printf("%s \n", p)
|
fmt.Printf("%s \n", p)
|
||||||
//}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user