func TestController(t *testing.T) { body := controller.GetHosts("https://sandboxapic.cisco.com") fmt.Println(body) if body == nil { t.Errorf("error") } }
func main() { // Use the same library and method we defined before body := controller.GetHosts("https://sandboxapic.cisco.com") // Use the JSON library, jason, to do the heavy lifting of creating go objects v, _ := jason.NewObjectFromBytes(body) // Since the result is an array of objects, we need to use GetObjectArray() r, _ := v.GetObjectArray("response") // Loop over the objects for _, obj := range r { // Use the jason library's GetString() method to get the right elements of the // returned JSON. // // Example JSON // { // "connectedInterfaceId": "30bb14c1-8fb6-45c4-8f6d-5b845a7f448c", // "connectedInterfaceName": "GigabitEthernet2/0/2", // "connectedNetworkDeviceId": "7895a45f-47aa-42ee-9d06-c66d3b784594", // "connectedNetworkDeviceIpAddress": "40.0.2.18", // "hostIp": "40.0.5.12", // "hostMac": "00:50:56:8A:27:A3", // "hostType": "WIRED", // "id": "8f41bef8-698c-4701-af14-471e910ed9ff", // "lastUpdated": "September 29, 2014 1:54:13 PM PDT", // "numUpdates": 1, // "source": 200, // "userStatus": "Active", // "vlanId": "1" // } iFace, err := obj.GetString("connectedInterfaceId") deviceType, err := obj.GetString("hostType") log.Println("id: " + iFace + " type: " + deviceType) if err != nil { log.Println(err) } } }
func main() { body := controller.GetHosts("https://sandboxapic.cisco.com") fmt.Printf("%s\n", string(body)) }