package mydp import ( "encoding/json" "fmt" "net/url" "strconv" ) type ( // defines a single IP entry in the IPFromDevice payload IPObject struct { Address string `json:"address" bson:"address"` AddressObj map[string]string `json:"address_obj" bson:"address_obj"` // empty string field name IID string `json:"i_id" bson:"i_id"` IInsideAddressMax string `json:"i_inside_address_max" bson:"i_inside_address_max"` IInsideAddressMin string `json:"i_inside_address_min" bson:"i_inside_address_min"` IOutsideAddressMax string `json:"i_outside_address_max" bson:"i_outside_address_max"` IOutsideAddressMin string `json:"i_outside_address_min" bson:"i_outside_address_min"` ID string `json:"id" bson:"id"` IPsID string `json:"ips_id" bson:"ips_id"` IPsNote string `json:"ips_note" bson:"ips_note"` IPsSubnet string `json:"ips_subnet" bson:"ips_subnet"` // CIDR Notation IPsSubnetObj map[string]string `json:"ips_subnet_obj" bson:"ips_subnet_obj"` // empty string field name Note string `json:"note" bson:"note"` OID string `json:"o_id" bson:"o_id"` OInsideAddressMax string `json:"o_inside_address_max" bson:"o_inside_address_max"` OInsideAddressMin string `json:"o_inside_address_min" bson:"o_inside_address_min"` OOutsideAddressMax string `json:"o_outside_address_max" bson:"o_outside_address_max"` OOutsideAddressMin string `json:"o_outside_address_min" bson:"o_outside_address_min"` Status string `json:"status" bson:"status"` } SummaryObject struct { Address IPObject `json:"address" bson:"address"` Count int `json:"count" bson:"count"` MaxAddress IPObject `json:"max_address" bson:"max_address"` MaxIPObj map[string]int `json:"max_ip_obj" bson:"max_ip_obj"` // empty string field name MinIPObj map[string]int `json:"min_ip_obj" bson:"min_ip_obj"` // empty string field name } IPFromDevice struct { IP []IPObject `json:"ip" bson:"ip"` IPCount int `json:"ip_count" bson:"ip_count"` Summary map[string]SummaryObject `json:"summary" bson:"summary"` // map key is CIDR value } ) // DeviceByDeviceID method uses the *mydp.Client to invoke a JSON call to get list of IPs by DeviceID func (c *Client) IPFromDeviceID(deviceID int) (*IPFromDevice, error) { response := new(IPFromDevice) res, err := c.get("json/IPfromDeviceID.php", url.Values{"DeviceID": []string{strconv.Itoa(deviceID)}}) if err != nil { return response, err } if res != nil { defer func() { if defErr := res.Body.Close(); defErr != nil { err = fmt.Errorf("%s::%s", err, defErr) } }() } err = json.NewDecoder(res.Body).Decode(response) return response, err }