Fix device_list when filter struct is empty..

This commit is contained in:
Kalle Carlbark 2019-09-11 20:48:47 +02:00
parent 69e732abcd
commit dcf73c1daf
No known key found for this signature in database
GPG key ID: 3FC0C93C5A5A0670

View file

@ -188,13 +188,6 @@ type DeviceFilter struct {
func (n *NetBox) ListDevices(d *Dcim_Devices_List, f *DeviceFilter) error {
var encoder = schema.NewEncoder()
form := url.Values{}
err := encoder.Encode(f, form)
if err != nil {
return err
}
query := form.Encode()
transport := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: n.InsecureSkipVerify},
}
@ -203,11 +196,18 @@ 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 {
deviceurl := n.RootURL + "/api/devices/"
if (&DeviceFilter{} != f) {
form := url.Values{}
err := encoder.Encode(f, form)
if err != nil {
return err
}
query := form.Encode()
deviceurl = deviceurl + "?" + query
}
var request *http.Request
var err error
request, err = http.NewRequest("GET", deviceurl, nil)
if err != nil {
return err