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:
Hendrik "T4cC0re" Meyer
2021-01-02 09:40:52 +01:00
committed by Paul Tyng
parent c5ff8c8593
commit 4aed7d703d
67 changed files with 2298 additions and 155 deletions

View File

@@ -2,28 +2,8 @@ package unifi
import (
"context"
"encoding/json"
)
func (n *WLAN) UnmarshalJSON(b []byte) error {
type Alias WLAN
aux := &struct {
VLAN emptyStringInt `json:"vlan"`
*Alias
}{
Alias: (*Alias)(n),
}
err := json.Unmarshal(b, &aux)
if err != nil {
return err
}
n.VLAN = int(aux.VLAN)
return nil
}
func (c *Client) CreateWLAN(ctx context.Context, site string, d *WLAN) (*WLAN, error) {
if d.Schedule == nil {
d.Schedule = []string{}