netbox-community / go-netbox

The official Go API client for Netbox IPAM and DCIM service.
Other
195 stars 146 forks source link

WritableDeviceInterface Enabled is not added to query #54

Closed clienthax closed 3 years ago

clienthax commented 4 years ago
    params := models.WritableDeviceInterface{
        Name:        &swInterface.name,
        MacAddress:  &swInterface.info.IfaceObj.Mac,
        Device:      &parentDeviceID,
        Enabled:     false,
        FormFactor:  formFactor,
        TaggedVlans: []int64{},
        Tags:        []string{},
        Mtu:         &mtu64,
    }

Setting Enabled to false will result in it not being added to the query, however setting it to true will add it when using the update/create interface functions.

clienthax commented 4 years ago

Looking into this further this seems to be an issue with how omitempty functions

package main

import (
    "encoding/json"
    "fmt"
)

type TestData struct {
    Enabled bool `json:"enabled,omitempty"`
}

func main() {
    d := TestData {
        Enabled: false,
    }
    b, _ := json.Marshal(d)
    fmt.Println(string(b))
}

if the value is false it is treated as 0, and doesn't get marshaled https://www.sohamkamani.com/blog/golang/2018-07-19-golang-omitempty/

clienthax commented 4 years ago

https://github.com/golang/go/issues/13284

kobayashi commented 4 years ago

@clienthax, Thaks to open this issue. I am looking for a solution for this though, is there any way to generate bool to *bool with go-swagger? Or better solution?

clienthax commented 4 years ago

@clienthax, Thaks to open this issue. I am looking for a solution for this though, is there any way to generate bool to *bool with go-swagger? Or better solution?

I am fairly new to Go and this is actually being used in one of my first projects, So I don't have any good solutions here

abhide commented 4 years ago

@kobayashi running into omitempty issue with https://github.com/netbox-community/go-netbox/issues/86 as well.