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
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package unifi
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
)
|
|
|
|
func (dst *Account) MarshalJSON() ([]byte, error) {
|
|
type Alias Account
|
|
aux := &struct {
|
|
*Alias
|
|
|
|
TunnelType emptyStringInt `json:"tunnel_type"`
|
|
TunnelMediumType emptyStringInt `json:"tunnel_medium_type"`
|
|
VLAN emptyStringInt `json:"vlan"`
|
|
}{
|
|
Alias: (*Alias)(dst),
|
|
}
|
|
|
|
aux.TunnelType = emptyStringInt(dst.TunnelType)
|
|
aux.TunnelMediumType = emptyStringInt(dst.TunnelMediumType)
|
|
aux.VLAN = emptyStringInt(dst.VLAN)
|
|
|
|
b, err := json.Marshal(aux)
|
|
return b, err
|
|
}
|
|
|
|
func (c *Client) ListAccount(ctx context.Context, site string) ([]Account, error) {
|
|
return c.listAccount(ctx, site)
|
|
}
|
|
|
|
func (c *Client) GetAccount(ctx context.Context, site, id string) (*Account, error) {
|
|
return c.getAccount(ctx, site, id)
|
|
}
|
|
|
|
func (c *Client) DeleteAccount(ctx context.Context, site, id string) error {
|
|
return c.deleteAccount(ctx, site, id)
|
|
}
|
|
|
|
func (c *Client) CreateAccount(ctx context.Context, site string, d *Account) (*Account, error) {
|
|
return c.createAccount(ctx, site, d)
|
|
}
|
|
|
|
func (c *Client) UpdateAccount(ctx context.Context, site string, d *Account) (*Account, error) {
|
|
return c.updateAccount(ctx, site, d)
|
|
}
|