Simplify device_list.
This commit is contained in:
parent
b1803645b8
commit
037c44b93f
1 changed files with 7 additions and 10 deletions
|
@ -203,17 +203,14 @@ 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)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
request, err = http.NewRequest("GET", n.RootURL+"/api/dcim/devices/", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
deviceurl = deviceurl + query
|
||||
}
|
||||
request, err = http.NewRequest("GET", deviceurl, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
request.Header.Add("Accept", "application/json")
|
||||
request.Header.Add("Authorization", " Token "+n.Token)
|
||||
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue