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,17 +203,14 @@ func (n *NetBox) ListDevices(d *Dcim_Devices_List, f *DeviceFilter) error {
Timeout: timeout, Timeout: timeout,
Transport: transport, Transport: transport,
} }
deviceurl := n.RootURL + "/api/dcim/devices/"
var request *http.Request var request *http.Request
if len(query) > 0 { if len(query) > 0 {
request, err = http.NewRequest("GET", n.RootURL+"/api/dcim/devices/"+"?"+query, nil) deviceurl = deviceurl + query
if err != nil { }
return err request, err = http.NewRequest("GET", deviceurl, nil)
} if err != nil {
} else { return err
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("Accept", "application/json")
request.Header.Add("Authorization", " Token "+n.Token) 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 { 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) data, err := ioutil.ReadAll(response.Body)