Skip to content

Commit

Permalink
Moved handling of string response to int using the existing emptyStri…
Browse files Browse the repository at this point in the history
…ngInt method as part of UnmarshalJSON as per Pauls suggestion
  • Loading branch information
JalfResi authored and paultyng committed Oct 9, 2020
1 parent e7f9c5e commit df93701
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
8 changes: 0 additions & 8 deletions fields/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,6 @@ func main() {
f.OmitEmpty = true
return nil
}
case "NetworkConf":
resource.FieldProcessor = func(name string, f *FieldInfo) error {
switch name {
case "WANEgressQOS":
f.FieldType = "string"
}
return nil
}
case "SettingUsg":
resource.FieldProcessor = func(name string, f *FieldInfo) error {
if strings.HasSuffix(name, "Timeout") && name != "ArpCacheTimeout" {
Expand Down
2 changes: 2 additions & 0 deletions unifi/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func (dst *Network) UnmarshalJSON(b []byte) error {
aux := &struct {
VLAN emptyStringInt `json:"vlan"`
DHCPDLeaseTime emptyStringInt `json:"dhcpd_leasetime"`
WANEgressQOS emptyStringInt `json:"wan_egress_qos"`

*Alias
}{
Expand All @@ -24,6 +25,7 @@ func (dst *Network) UnmarshalJSON(b []byte) error {

dst.VLAN = int(aux.VLAN)
dst.DHCPDLeaseTime = int(aux.DHCPDLeaseTime)
dst.WANEgressQOS = int(aux.WANEgressQOS)

return nil
}
Expand Down
13 changes: 13 additions & 0 deletions unifi/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ func TestNetworkUnmarshalJSON(t *testing.T) {
expected: unifi.Network{DHCPDLeaseTime: 0},
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) {
var actual unifi.Network
Expand Down

0 comments on commit df93701

Please sign in to comment.