Skip to content

Commit

Permalink
Fix unmarshaling of dhcpd_leasetime
Browse files Browse the repository at this point in the history
Issue #2
  • Loading branch information
paultyng committed Feb 10, 2020
1 parent 95a2437 commit 3fb1d0b
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions unifi/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,39 @@ import (
"fmt"
)

func (n *Network) UnmarshalJSON(b []byte) error {
func (dst *Network) UnmarshalJSON(b []byte) error {
type Alias Network
aux := &struct {
VLAN json.Number `json:"vlan"`
VLAN json.Number `json:"vlan"`
DHCPDLeaseTime json.Number `json:"dhcpd_leasetime"`

*Alias
}{
Alias: (*Alias)(n),
Alias: (*Alias)(dst),
}
err := json.Unmarshal(b, &aux)
if err != nil {
return err
}
n.VLAN = 0

dst.VLAN = 0
if aux.VLAN.String() != "" {
vlan, err := aux.VLAN.Int64()
n, err := aux.VLAN.Int64()
if err != nil {
return err
}
dst.VLAN = int(n)
}

dst.DHCPDLeaseTime = 0
if aux.DHCPDLeaseTime.String() != "" {
n, err := aux.DHCPDLeaseTime.Int64()
if err != nil {
return err
}
n.VLAN = int(vlan)
dst.DHCPDLeaseTime = int(n)
}

return nil
}

Expand Down

0 comments on commit 3fb1d0b

Please sign in to comment.