Simplify device_list.

This commit is contained in:
Kalle Carlbark 2019-09-11 20:25:49 +02:00
parent b1803645b8
commit 037c44b93f
No known key found for this signature in database
GPG key ID: 3FC0C93C5A5A0670

View file

@ -203,18 +203,15 @@ func (n *NetBox) ListDevices(d *Dcim_Devices_List, f *DeviceFilter) error {
Timeout: timeout,
Transport: transport,
}
deviceurl := n.RootURL + "/api/dcim/devices/"
var request *http.Request
if len(query) > 0 {
request, err = http.NewRequest("GET", n.RootURL+"/api/dcim/devices/"+"?"+query, nil)
deviceurl = deviceurl + query
}
request, err = http.NewRequest("GET", deviceurl, nil)
if err != nil {
return err
}
} else {
request, err = http.NewRequest("GET", n.RootURL+"/api/dcim/devices/", nil)
if err != nil {
return err
}
}
request.Header.Add("Accept", "application/json")
request.Header.Add("Authorization", " Token "+n.Token)
response, err := client.Do(request)
@ -223,7 +220,7 @@ func (n *NetBox) ListDevices(d *Dcim_Devices_List, f *DeviceFilter) error {
}
if response.StatusCode != http.StatusOK {
return errors.Errorf("Error: response was: %d should be %d\n", response.StatusCode, http.StatusOK)
return errors.Errorf("Error: response was: %d should be %d (%s)\n", response.StatusCode, http.StatusOK, deviceurl)
}
data, err := ioutil.ReadAll(response.Body)