Moved handling of string response to int using the existing emptyStringInt method as part of UnmarshalJSON as per Pauls suggestion
This commit is contained in:
@@ -260,14 +260,6 @@ func main() {
|
|||||||
f.OmitEmpty = true
|
f.OmitEmpty = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
case "NetworkConf":
|
|
||||||
resource.FieldProcessor = func(name string, f *FieldInfo) error {
|
|
||||||
switch name {
|
|
||||||
case "WANEgressQOS":
|
|
||||||
f.FieldType = "string"
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
case "SettingUsg":
|
case "SettingUsg":
|
||||||
resource.FieldProcessor = func(name string, f *FieldInfo) error {
|
resource.FieldProcessor = func(name string, f *FieldInfo) error {
|
||||||
if strings.HasSuffix(name, "Timeout") && name != "ArpCacheTimeout" {
|
if strings.HasSuffix(name, "Timeout") && name != "ArpCacheTimeout" {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ func (dst *Network) UnmarshalJSON(b []byte) error {
|
|||||||
aux := &struct {
|
aux := &struct {
|
||||||
VLAN emptyStringInt `json:"vlan"`
|
VLAN emptyStringInt `json:"vlan"`
|
||||||
DHCPDLeaseTime emptyStringInt `json:"dhcpd_leasetime"`
|
DHCPDLeaseTime emptyStringInt `json:"dhcpd_leasetime"`
|
||||||
|
WANEgressQOS emptyStringInt `json:"wan_egress_qos"`
|
||||||
|
|
||||||
*Alias
|
*Alias
|
||||||
}{
|
}{
|
||||||
@@ -24,6 +25,7 @@ func (dst *Network) UnmarshalJSON(b []byte) error {
|
|||||||
|
|
||||||
dst.VLAN = int(aux.VLAN)
|
dst.VLAN = int(aux.VLAN)
|
||||||
dst.DHCPDLeaseTime = int(aux.DHCPDLeaseTime)
|
dst.DHCPDLeaseTime = int(aux.DHCPDLeaseTime)
|
||||||
|
dst.WANEgressQOS = int(aux.WANEgressQOS)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,19 @@ func TestNetworkUnmarshalJSON(t *testing.T) {
|
|||||||
expected: unifi.Network{DHCPDLeaseTime: 0},
|
expected: unifi.Network{DHCPDLeaseTime: 0},
|
||||||
json: `{ "dhcpd_leasetime": "" }`,
|
json: `{ "dhcpd_leasetime": "" }`,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"int wan_egress_qos": {
|
||||||
|
expected: unifi.Network{WANEgressQOS: 1},
|
||||||
|
json: `{ "wan_egress_qos": 1 }`,
|
||||||
|
},
|
||||||
|
"string wan_egress_qos": {
|
||||||
|
expected: unifi.Network{WANEgressQOS: 1},
|
||||||
|
json: `{ "wan_egress_qos": "1" }`,
|
||||||
|
},
|
||||||
|
"empty string wan_egress_qos": {
|
||||||
|
expected: unifi.Network{WANEgressQOS: 0},
|
||||||
|
json: `{ "wan_egress_qos": "" }`,
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(n, func(t *testing.T) {
|
t.Run(n, func(t *testing.T) {
|
||||||
var actual unifi.Network
|
var actual unifi.Network
|
||||||
|
|||||||
Reference in New Issue
Block a user