Generate UnmarshalJSON to handle emptyStringInt types
This commit changes the code generator to generate a `UnmarshalJSON` for each struct, so that if unmarshalled it properly handles UniFis varying integer values via the `emptyStringInt` type. Structs not including a field of `int` type will still have the function generated, but it will effectively do nothing. Fixes #18
This commit is contained in:
committed by
Paul Tyng
parent
c5ff8c8593
commit
4aed7d703d
@@ -2,34 +2,9 @@ package unifi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (dst *Network) UnmarshalJSON(b []byte) error {
|
||||
type Alias Network
|
||||
aux := &struct {
|
||||
VLAN emptyStringInt `json:"vlan"`
|
||||
DHCPDLeaseTime emptyStringInt `json:"dhcpd_leasetime"`
|
||||
WANEgressQOS emptyStringInt `json:"wan_egress_qos"`
|
||||
|
||||
*Alias
|
||||
}{
|
||||
Alias: (*Alias)(dst),
|
||||
}
|
||||
|
||||
err := json.Unmarshal(b, &aux)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to unmarshal alias: %w", err)
|
||||
}
|
||||
|
||||
dst.VLAN = int(aux.VLAN)
|
||||
dst.DHCPDLeaseTime = int(aux.DHCPDLeaseTime)
|
||||
dst.WANEgressQOS = int(aux.WANEgressQOS)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) DeleteNetwork(ctx context.Context, site, id, name string) error {
|
||||
err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/networkconf/%s", site, id), struct {
|
||||
Name string `json:"name"`
|
||||
|
||||
Reference in New Issue
Block a user