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