diff --git a/fields/api.go.tmpl b/fields/api.go.tmpl index 58ff32d..09ec6df 100644 --- a/fields/api.go.tmpl +++ b/fields/api.go.tmpl @@ -2,6 +2,18 @@ {{ define "field" }} {{ .FieldName }} {{ if .IsArray }}[]{{end}}{{ .FieldType }} `json:"{{ .JSONName }}{{ if .OmitEmpty }},omitempty{{ end }}"` {{ if .FieldValidation }}// {{ .FieldValidation }}{{ end }} {{- end }} +{{ define "field-emptyStringInt" }} + {{- if ne .FieldType "int" }}{{else}} + {{ .FieldName }} {{ if .IsArray }}[]{{end}}emptyStringInt `json:"{{ .JSONName }}{{ if .OmitEmpty }}{{ end }}"`{{ end }} {{- end }} +{{ define "typecast" }} + {{- if eq .FieldType "int" }}{{- if .IsArray }} + dst.{{ .FieldName }}= make([]int, len(aux.{{ .FieldName }})) + for i, v := range aux.{{ .FieldName }} { + dst.{{ .FieldName }}[i] = int(v) + } + {{- else }} + dst.{{ .FieldName }} = int(aux.{{ .FieldName }}) + {{- end }}{{- end }}{{- end }} {{ define "field-embed" }} {{ .FieldName }} {{ if .IsArray }}[]{{end}}{{ if not .Fields }}{{ .FieldType }}{{ else }}struct { {{ range $fk, $fv := .Fields }}{{ if not $fv }} @@ -14,13 +26,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) {{ if embedTypes -}} @@ -36,6 +50,28 @@ type {{ $k }} struct { {{ range $fk, $fv := $v.Fields }}{{ if not $fv }} {{ else }}{{- template "field" $fv }}{{ end }}{{ end }} } + +func (dst *{{ $k }}) UnmarshalJSON(b []byte) error { + type Alias {{ $k }} + aux := &struct { + {{- range $fk, $fv := $v.Fields }}{{ if not $fv }} + {{- else }}{{- template "field-emptyStringInt" $fv }}{{ end }}{{- end }} + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + {{- range $fk, $fv := $v.Fields }}{{ if not $fv }} + {{- else }}{{- template "typecast" $fv }}{{ end }}{{ end }} + + return nil +} {{ end }} {{- end -}} diff --git a/unifi/account.generated.go b/unifi/account.generated.go index 6419fe8..a15782e 100644 --- a/unifi/account.generated.go +++ b/unifi/account.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type Account struct { @@ -32,6 +34,29 @@ type Account struct { XPassword string `json:"x_password,omitempty"` } +func (dst *Account) UnmarshalJSON(b []byte) error { + type Alias Account + aux := &struct { + TunnelMediumType emptyStringInt `json:"tunnel_medium_type"` + TunnelType emptyStringInt `json:"tunnel_type"` + VLAN emptyStringInt `json:"vlan"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.TunnelMediumType = int(aux.TunnelMediumType) + dst.TunnelType = int(aux.TunnelType) + dst.VLAN = int(aux.VLAN) + + return nil +} + func (c *Client) listAccount(ctx context.Context, site string) ([]Account, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/account.go b/unifi/account.go index 73a76b0..d955e2b 100644 --- a/unifi/account.go +++ b/unifi/account.go @@ -3,33 +3,8 @@ package unifi import ( "context" "encoding/json" - "fmt" ) -func (dst *Account) UnmarshalJSON(b []byte) error { - type Alias Account - aux := &struct { - TunnelType emptyStringInt `json:"tunnel_type"` - TunnelMediumType emptyStringInt `json:"tunnel_medium_type"` - VLAN emptyStringInt `json:"vlan"` - - *Alias - }{ - Alias: (*Alias)(dst), - } - - err := json.Unmarshal(b, &aux) - if err != nil { - return fmt.Errorf("unable to unmarshal alias: %w", err) - } - - dst.TunnelType = int(aux.TunnelType) - dst.TunnelMediumType = int(aux.TunnelMediumType) - dst.VLAN = int(aux.VLAN) - - return nil -} - func (dst *Account) MarshalJSON() ([]byte, error) { type Alias Account aux := &struct { diff --git a/unifi/broadcast_group.generated.go b/unifi/broadcast_group.generated.go index dfe1c34..643a818 100644 --- a/unifi/broadcast_group.generated.go +++ b/unifi/broadcast_group.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type BroadcastGroup struct { @@ -27,6 +29,22 @@ type BroadcastGroup struct { Name string `json:"name,omitempty"` } +func (dst *BroadcastGroup) UnmarshalJSON(b []byte) error { + type Alias BroadcastGroup + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) listBroadcastGroup(ctx context.Context, site string) ([]BroadcastGroup, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/channel_plan.generated.go b/unifi/channel_plan.generated.go index 3e9386f..4efac56 100644 --- a/unifi/channel_plan.generated.go +++ b/unifi/channel_plan.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type ChannelPlan struct { @@ -36,18 +38,74 @@ type ChannelPlan struct { SiteBlacklistedChannels []ChannelPlanSiteBlacklistedChannels `json:"site_blacklisted_channels,omitempty"` } +func (dst *ChannelPlan) UnmarshalJSON(b []byte) error { + type Alias ChannelPlan + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + type ChannelPlanApBlacklistedChannels struct { Channel int `json:"channel,omitempty"` // 36|38|40|42|44|46|48|52|56|60|64|100|104|108|112|116|120|124|128|132|136|140|144|149|153|157|161|165|183|184|185|187|188|189|192|196 MAC string `json:"mac,omitempty"` // ^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})$ Timestamp int `json:"timestamp,omitempty"` // [1-9][0-9]{12} } +func (dst *ChannelPlanApBlacklistedChannels) UnmarshalJSON(b []byte) error { + type Alias ChannelPlanApBlacklistedChannels + aux := &struct { + Channel emptyStringInt `json:"channel"` + Timestamp emptyStringInt `json:"timestamp"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.Channel = int(aux.Channel) + dst.Timestamp = int(aux.Timestamp) + + return nil +} + type ChannelPlanCoupling struct { Rssi int `json:"rssi,omitempty"` Source string `json:"source,omitempty"` // ^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2}).*$ Target string `json:"target,omitempty"` // ^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2}).*$ } +func (dst *ChannelPlanCoupling) UnmarshalJSON(b []byte) error { + type Alias ChannelPlanCoupling + aux := &struct { + Rssi emptyStringInt `json:"rssi"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.Rssi = int(aux.Rssi) + + return nil +} + type ChannelPlanRadioTable struct { BackupChannel string `json:"backup_channel,omitempty"` // [0-9]|[1][0-4]|16|34|36|38|40|42|44|46|48|52|56|60|64|100|104|108|112|116|120|124|128|132|136|140|144|149|153|157|161|165|183|184|185|187|188|189|192|196|auto Channel string `json:"channel,omitempty"` // [0-9]|[1][0-4]|16|34|36|38|40|42|44|46|48|52|56|60|64|100|104|108|112|116|120|124|128|132|136|140|144|149|153|157|161|165|183|184|185|187|188|189|192|196|auto @@ -58,16 +116,72 @@ type ChannelPlanRadioTable struct { Width int `json:"width,omitempty"` // 20|40|80|160 } +func (dst *ChannelPlanRadioTable) UnmarshalJSON(b []byte) error { + type Alias ChannelPlanRadioTable + aux := &struct { + Width emptyStringInt `json:"width"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.Width = int(aux.Width) + + return nil +} + type ChannelPlanSatisfactionTable struct { DeviceMAC string `json:"device_mac,omitempty"` // ^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})$ Satisfaction float64 `json:"satisfaction,omitempty"` } +func (dst *ChannelPlanSatisfactionTable) UnmarshalJSON(b []byte) error { + type Alias ChannelPlanSatisfactionTable + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + type ChannelPlanSiteBlacklistedChannels struct { Channel int `json:"channel,omitempty"` // 36|38|40|42|44|46|48|52|56|60|64|100|104|108|112|116|120|124|128|132|136|140|144|149|153|157|161|165|183|184|185|187|188|189|192|196 Timestamp int `json:"timestamp,omitempty"` // [1-9][0-9]{12} } +func (dst *ChannelPlanSiteBlacklistedChannels) UnmarshalJSON(b []byte) error { + type Alias ChannelPlanSiteBlacklistedChannels + aux := &struct { + Channel emptyStringInt `json:"channel"` + Timestamp emptyStringInt `json:"timestamp"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.Channel = int(aux.Channel) + dst.Timestamp = int(aux.Timestamp) + + return nil +} + func (c *Client) listChannelPlan(ctx context.Context, site string) ([]ChannelPlan, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/dashboard.generated.go b/unifi/dashboard.generated.go index bcb5ee2..f8270a6 100644 --- a/unifi/dashboard.generated.go +++ b/unifi/dashboard.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type Dashboard struct { @@ -30,6 +32,22 @@ type Dashboard struct { Name string `json:"name,omitempty"` } +func (dst *Dashboard) UnmarshalJSON(b []byte) error { + type Alias Dashboard + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + type DashboardModules struct { Config string `json:"config,omitempty"` ID string `json:"id"` @@ -37,6 +55,22 @@ type DashboardModules struct { Restrictions string `json:"restrictions,omitempty"` } +func (dst *DashboardModules) UnmarshalJSON(b []byte) error { + type Alias DashboardModules + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) listDashboard(ctx context.Context, site string) ([]Dashboard, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/device.generated.go b/unifi/device.generated.go index 051cbed..64688de 100644 --- a/unifi/device.generated.go +++ b/unifi/device.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type Device struct { @@ -81,6 +83,35 @@ type Device struct { Y float64 `json:"y,omitempty"` } +func (dst *Device) UnmarshalJSON(b []byte) error { + type Alias Device + aux := &struct { + LcmBrightness emptyStringInt `json:"lcm_brightness"` + LcmIDleTimeout emptyStringInt `json:"lcm_idle_timeout"` + LedOverrideColorBrightness emptyStringInt `json:"led_override_color_brightness"` + LteSimPin emptyStringInt `json:"lte_sim_pin"` + LteSoftLimit emptyStringInt `json:"lte_soft_limit"` + Volume emptyStringInt `json:"volume"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.LcmBrightness = int(aux.LcmBrightness) + dst.LcmIDleTimeout = int(aux.LcmIDleTimeout) + dst.LedOverrideColorBrightness = int(aux.LedOverrideColorBrightness) + dst.LteSimPin = int(aux.LteSimPin) + dst.LteSoftLimit = int(aux.LteSoftLimit) + dst.Volume = int(aux.Volume) + + return nil +} + type DeviceConfigNetwork struct { BondingEnabled bool `json:"bonding_enabled,omitempty"` DNS1 string `json:"dns1,omitempty"` // ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$|^$ @@ -92,11 +123,43 @@ type DeviceConfigNetwork struct { Type string `json:"type,omitempty"` // dhcp|static } +func (dst *DeviceConfigNetwork) UnmarshalJSON(b []byte) error { + type Alias DeviceConfigNetwork + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + type DeviceEthernetOverrides struct { Ifname string `json:"ifname,omitempty"` // eth[0-9]{1,2} NetworkGroup string `json:"networkgroup,omitempty"` // LAN[2-8]?|WAN[2]? } +func (dst *DeviceEthernetOverrides) UnmarshalJSON(b []byte) error { + type Alias DeviceEthernetOverrides + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + type DeviceOutletOverrides struct { CycleEnabled bool `json:"cycle_enabled,omitempty"` Index int `json:"index,omitempty"` @@ -104,6 +167,25 @@ type DeviceOutletOverrides struct { RelayState bool `json:"relay_state,omitempty"` } +func (dst *DeviceOutletOverrides) UnmarshalJSON(b []byte) error { + type Alias DeviceOutletOverrides + aux := &struct { + Index emptyStringInt `json:"index"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.Index = int(aux.Index) + + return nil +} + type DevicePortOverrides struct { AggregateNumPorts int `json:"aggregate_num_ports,omitempty"` // [2-6] Autoneg bool `json:"autoneg,omitempty"` @@ -141,6 +223,55 @@ type DevicePortOverrides struct { StpPortMode bool `json:"stp_port_mode,omitempty"` } +func (dst *DevicePortOverrides) UnmarshalJSON(b []byte) error { + type Alias DevicePortOverrides + aux := &struct { + AggregateNumPorts emptyStringInt `json:"aggregate_num_ports"` + Dot1XIDleTimeout emptyStringInt `json:"dot1x_idle_timeout"` + EgressRateLimitKbps emptyStringInt `json:"egress_rate_limit_kbps"` + MirrorPortIDX emptyStringInt `json:"mirror_port_idx"` + PortIDX emptyStringInt `json:"port_idx"` + PriorityQueue1Level emptyStringInt `json:"priority_queue1_level"` + PriorityQueue2Level emptyStringInt `json:"priority_queue2_level"` + PriorityQueue3Level emptyStringInt `json:"priority_queue3_level"` + PriorityQueue4Level emptyStringInt `json:"priority_queue4_level"` + Speed emptyStringInt `json:"speed"` + StormctrlBroadcastastLevel emptyStringInt `json:"stormctrl_bcast_level"` + StormctrlBroadcastastRate emptyStringInt `json:"stormctrl_bcast_rate"` + StormctrlMcastLevel emptyStringInt `json:"stormctrl_mcast_level"` + StormctrlMcastRate emptyStringInt `json:"stormctrl_mcast_rate"` + StormctrlUcastLevel emptyStringInt `json:"stormctrl_ucast_level"` + StormctrlUcastRate emptyStringInt `json:"stormctrl_ucast_rate"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.AggregateNumPorts = int(aux.AggregateNumPorts) + dst.Dot1XIDleTimeout = int(aux.Dot1XIDleTimeout) + dst.EgressRateLimitKbps = int(aux.EgressRateLimitKbps) + dst.MirrorPortIDX = int(aux.MirrorPortIDX) + dst.PortIDX = int(aux.PortIDX) + dst.PriorityQueue1Level = int(aux.PriorityQueue1Level) + dst.PriorityQueue2Level = int(aux.PriorityQueue2Level) + dst.PriorityQueue3Level = int(aux.PriorityQueue3Level) + dst.PriorityQueue4Level = int(aux.PriorityQueue4Level) + dst.Speed = int(aux.Speed) + dst.StormctrlBroadcastastLevel = int(aux.StormctrlBroadcastastLevel) + dst.StormctrlBroadcastastRate = int(aux.StormctrlBroadcastastRate) + dst.StormctrlMcastLevel = int(aux.StormctrlMcastLevel) + dst.StormctrlMcastRate = int(aux.StormctrlMcastRate) + dst.StormctrlUcastLevel = int(aux.StormctrlUcastLevel) + dst.StormctrlUcastRate = int(aux.StormctrlUcastRate) + + return nil +} + type DeviceRadioTable struct { AntennaGain int `json:"antenna_gain,omitempty"` // ^-?([0-9]|[1-9][0-9]) AntennaID int `json:"antenna_id,omitempty"` // -1|[0-9] @@ -161,17 +292,85 @@ type DeviceRadioTable struct { VwireEnabled bool `json:"vwire_enabled,omitempty"` } +func (dst *DeviceRadioTable) UnmarshalJSON(b []byte) error { + type Alias DeviceRadioTable + aux := &struct { + AntennaGain emptyStringInt `json:"antenna_gain"` + AntennaID emptyStringInt `json:"antenna_id"` + BackupChannel emptyStringInt `json:"backup_channel"` + Channel emptyStringInt `json:"channel"` + Maxsta emptyStringInt `json:"maxsta"` + MinRssi emptyStringInt `json:"min_rssi"` + SensLevel emptyStringInt `json:"sens_level"` + TxPower emptyStringInt `json:"tx_power"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.AntennaGain = int(aux.AntennaGain) + dst.AntennaID = int(aux.AntennaID) + dst.BackupChannel = int(aux.BackupChannel) + dst.Channel = int(aux.Channel) + dst.Maxsta = int(aux.Maxsta) + dst.MinRssi = int(aux.MinRssi) + dst.SensLevel = int(aux.SensLevel) + dst.TxPower = int(aux.TxPower) + + return nil +} + type DeviceRpsOverride struct { PowerManagementMode string `json:"power_management_mode,omitempty"` // dynamic|static RpsPortTable []DeviceRpsPortTable `json:"rps_port_table,omitempty"` } +func (dst *DeviceRpsOverride) UnmarshalJSON(b []byte) error { + type Alias DeviceRpsOverride + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + type DeviceRpsPortTable struct { Name string `json:"name,omitempty"` // .{0,32} PortIDX int `json:"port_idx,omitempty"` // [1-6] PortMode string `json:"port_mode,omitempty"` // auto|force_active|manual|disabled } +func (dst *DeviceRpsPortTable) UnmarshalJSON(b []byte) error { + type Alias DeviceRpsPortTable + aux := &struct { + PortIDX emptyStringInt `json:"port_idx"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.PortIDX = int(aux.PortIDX) + + return nil +} + type DeviceWLANOverrides struct { Enabled bool `json:"enabled,omitempty"` Name string `json:"name,omitempty"` // .{1,32} @@ -185,6 +384,25 @@ type DeviceWLANOverrides struct { XPassphrase string `json:"x_passphrase,omitempty"` // [\x20-\x7E]{8,63}|[0-9a-fA-F]{64} } +func (dst *DeviceWLANOverrides) UnmarshalJSON(b []byte) error { + type Alias DeviceWLANOverrides + aux := &struct { + VLAN emptyStringInt `json:"vlan"` + + *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) + + return nil +} + func (c *Client) listDevice(ctx context.Context, site string) ([]Device, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/dhcp_option.generated.go b/unifi/dhcp_option.generated.go index c8191de..329012e 100644 --- a/unifi/dhcp_option.generated.go +++ b/unifi/dhcp_option.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type DHCPOption struct { @@ -30,6 +32,25 @@ type DHCPOption struct { Width int `json:"width,omitempty"` // ^(8|16|32)$ } +func (dst *DHCPOption) UnmarshalJSON(b []byte) error { + type Alias DHCPOption + aux := &struct { + Width emptyStringInt `json:"width"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.Width = int(aux.Width) + + return nil +} + func (c *Client) listDHCPOption(ctx context.Context, site string) ([]DHCPOption, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/dpi_app.generated.go b/unifi/dpi_app.generated.go index caba619..518a4d6 100644 --- a/unifi/dpi_app.generated.go +++ b/unifi/dpi_app.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type DpiApp struct { @@ -33,6 +35,37 @@ type DpiApp struct { QOSRateMaxUp int `json:"qos_rate_max_up,omitempty"` // -1|[2-9]|[1-9][0-9]{1,4}|100000|10[0-1][0-9]{3}|102[0-3][0-9]{2}|102400 } +func (dst *DpiApp) UnmarshalJSON(b []byte) error { + type Alias DpiApp + aux := &struct { + Apps []emptyStringInt `json:"apps"` + Cats []emptyStringInt `json:"cats"` + QOSRateMaxDown emptyStringInt `json:"qos_rate_max_down"` + QOSRateMaxUp emptyStringInt `json:"qos_rate_max_up"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.Apps = make([]int, len(aux.Apps)) + for i, v := range aux.Apps { + dst.Apps[i] = int(v) + } + dst.Cats = make([]int, len(aux.Cats)) + for i, v := range aux.Cats { + dst.Cats[i] = int(v) + } + dst.QOSRateMaxDown = int(aux.QOSRateMaxDown) + dst.QOSRateMaxUp = int(aux.QOSRateMaxUp) + + return nil +} + func (c *Client) listDpiApp(ctx context.Context, site string) ([]DpiApp, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/dpi_group.generated.go b/unifi/dpi_group.generated.go index 1089482..ee1e345 100644 --- a/unifi/dpi_group.generated.go +++ b/unifi/dpi_group.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type DpiGroup struct { @@ -28,6 +30,22 @@ type DpiGroup struct { Name string `json:"name,omitempty"` // .{1,128} } +func (dst *DpiGroup) UnmarshalJSON(b []byte) error { + type Alias DpiGroup + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) listDpiGroup(ctx context.Context, site string) ([]DpiGroup, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/dynamic_dns.generated.go b/unifi/dynamic_dns.generated.go index a86e8cc..1e66ccf 100644 --- a/unifi/dynamic_dns.generated.go +++ b/unifi/dynamic_dns.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type DynamicDNS struct { @@ -33,6 +35,22 @@ type DynamicDNS struct { XPassword string `json:"x_password,omitempty"` // ^[^"' ]+$ } +func (dst *DynamicDNS) UnmarshalJSON(b []byte) error { + type Alias DynamicDNS + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) listDynamicDNS(ctx context.Context, site string) ([]DynamicDNS, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/firewall_group.generated.go b/unifi/firewall_group.generated.go index 8f667c3..e3d24b5 100644 --- a/unifi/firewall_group.generated.go +++ b/unifi/firewall_group.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type FirewallGroup struct { @@ -28,6 +30,22 @@ type FirewallGroup struct { Name string `json:"name,omitempty"` // .{1,64} } +func (dst *FirewallGroup) UnmarshalJSON(b []byte) error { + type Alias FirewallGroup + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) listFirewallGroup(ctx context.Context, site string) ([]FirewallGroup, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/firewall_rule.generated.go b/unifi/firewall_rule.generated.go index 04bf00d..2a9170e 100644 --- a/unifi/firewall_rule.generated.go +++ b/unifi/firewall_rule.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type FirewallRule struct { @@ -64,6 +66,25 @@ type FirewallRule struct { WeekdaysNegate bool `json:"weekdays_negate"` } +func (dst *FirewallRule) UnmarshalJSON(b []byte) error { + type Alias FirewallRule + aux := &struct { + RuleIndex emptyStringInt `json:"rule_index"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.RuleIndex = int(aux.RuleIndex) + + return nil +} + func (c *Client) listFirewallRule(ctx context.Context, site string) ([]FirewallRule, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/firewall_rule.go b/unifi/firewall_rule.go index 6855a5b..361ed88 100644 --- a/unifi/firewall_rule.go +++ b/unifi/firewall_rule.go @@ -2,30 +2,8 @@ package unifi import ( "context" - "encoding/json" - "fmt" ) -func (dst *FirewallRule) UnmarshalJSON(b []byte) error { - type Alias FirewallRule - aux := &struct { - RuleIndex emptyStringInt `json:"rule_index"` - - *Alias - }{ - Alias: (*Alias)(dst), - } - - err := json.Unmarshal(b, &aux) - if err != nil { - return fmt.Errorf("unable to unmarshal alias: %w", err) - } - - dst.RuleIndex = int(aux.RuleIndex) - - return nil -} - func (c *Client) ListFirewallRule(ctx context.Context, site string) ([]FirewallRule, error) { return c.listFirewallRule(ctx, site) } diff --git a/unifi/heat_map.generated.go b/unifi/heat_map.generated.go index 4367643..431d998 100644 --- a/unifi/heat_map.generated.go +++ b/unifi/heat_map.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type HeatMap struct { @@ -29,6 +31,22 @@ type HeatMap struct { Type string `json:"type,omitempty"` // download|upload } +func (dst *HeatMap) UnmarshalJSON(b []byte) error { + type Alias HeatMap + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) listHeatMap(ctx context.Context, site string) ([]HeatMap, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/heat_map_point.generated.go b/unifi/heat_map_point.generated.go index ca130ba..cebaa0c 100644 --- a/unifi/heat_map_point.generated.go +++ b/unifi/heat_map_point.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type HeatMapPoint struct { @@ -30,6 +32,22 @@ type HeatMapPoint struct { Y float64 `json:"y,omitempty"` } +func (dst *HeatMapPoint) UnmarshalJSON(b []byte) error { + type Alias HeatMapPoint + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) listHeatMapPoint(ctx context.Context, site string) ([]HeatMapPoint, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/hotspot_2_conf.generated.go b/unifi/hotspot_2_conf.generated.go index 3037751..661583d 100644 --- a/unifi/hotspot_2_conf.generated.go +++ b/unifi/hotspot_2_conf.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type Hotspot2Conf struct { @@ -75,32 +77,169 @@ type Hotspot2Conf struct { VenueType int `json:"venue_type,omitempty"` // 0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15 } +func (dst *Hotspot2Conf) UnmarshalJSON(b []byte) error { + type Alias Hotspot2Conf + aux := &struct { + AnqpDomainID emptyStringInt `json:"anqp_domain_id"` + DeauthReqTimeout emptyStringInt `json:"deauth_req_timeout"` + GasComebackDelay emptyStringInt `json:"gas_comeback_delay"` + GasFragLimit emptyStringInt `json:"gas_frag_limit"` + IPaddrTypeAvailV4 emptyStringInt `json:"ipaddr_type_avail_v4"` + IPaddrTypeAvailV6 emptyStringInt `json:"ipaddr_type_avail_v6"` + MetricsDownlinkLoad emptyStringInt `json:"metrics_downlink_load"` + MetricsDownlinkSpeed emptyStringInt `json:"metrics_downlink_speed"` + MetricsMeasurement emptyStringInt `json:"metrics_measurement"` + MetricsUplinkLoad emptyStringInt `json:"metrics_uplink_load"` + MetricsUplinkSpeed emptyStringInt `json:"metrics_uplink_speed"` + NetworkAuthType emptyStringInt `json:"network_auth_type"` + NetworkType emptyStringInt `json:"network_type"` + TCTimestamp emptyStringInt `json:"t_c_timestamp"` + VenueGroup emptyStringInt `json:"venue_group"` + VenueType emptyStringInt `json:"venue_type"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.AnqpDomainID = int(aux.AnqpDomainID) + dst.DeauthReqTimeout = int(aux.DeauthReqTimeout) + dst.GasComebackDelay = int(aux.GasComebackDelay) + dst.GasFragLimit = int(aux.GasFragLimit) + dst.IPaddrTypeAvailV4 = int(aux.IPaddrTypeAvailV4) + dst.IPaddrTypeAvailV6 = int(aux.IPaddrTypeAvailV6) + dst.MetricsDownlinkLoad = int(aux.MetricsDownlinkLoad) + dst.MetricsDownlinkSpeed = int(aux.MetricsDownlinkSpeed) + dst.MetricsMeasurement = int(aux.MetricsMeasurement) + dst.MetricsUplinkLoad = int(aux.MetricsUplinkLoad) + dst.MetricsUplinkSpeed = int(aux.MetricsUplinkSpeed) + dst.NetworkAuthType = int(aux.NetworkAuthType) + dst.NetworkType = int(aux.NetworkType) + dst.TCTimestamp = int(aux.TCTimestamp) + dst.VenueGroup = int(aux.VenueGroup) + dst.VenueType = int(aux.VenueType) + + return nil +} + type Hotspot2ConfCapab struct { Port int `json:"port,omitempty"` // ^(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])|$ Protocol string `json:"protocol,omitempty"` // icmp|tcp_udp|tcp|udp|esp Status string `json:"status,omitempty"` // closed|open|unknown } +func (dst *Hotspot2ConfCapab) UnmarshalJSON(b []byte) error { + type Alias Hotspot2ConfCapab + aux := &struct { + Port emptyStringInt `json:"port"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.Port = int(aux.Port) + + return nil +} + type Hotspot2ConfCellularNetworkList struct { Mcc int `json:"mcc,omitempty"` Mnc int `json:"mnc,omitempty"` Name string `json:"name,omitempty"` // .{1,128} } +func (dst *Hotspot2ConfCellularNetworkList) UnmarshalJSON(b []byte) error { + type Alias Hotspot2ConfCellularNetworkList + aux := &struct { + Mcc emptyStringInt `json:"mcc"` + Mnc emptyStringInt `json:"mnc"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.Mcc = int(aux.Mcc) + dst.Mnc = int(aux.Mnc) + + return nil +} + type Hotspot2ConfDescription struct { Language string `json:"language,omitempty"` // [a-z]{3} Text string `json:"text,omitempty"` // .{1,128} } +func (dst *Hotspot2ConfDescription) UnmarshalJSON(b []byte) error { + type Alias Hotspot2ConfDescription + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + type Hotspot2ConfFriendlyName struct { Language string `json:"language,omitempty"` // [a-z]{3} Text string `json:"text,omitempty"` // .{1,128} } +func (dst *Hotspot2ConfFriendlyName) UnmarshalJSON(b []byte) error { + type Alias Hotspot2ConfFriendlyName + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + type Hotspot2ConfIcon struct { Name string `json:"name,omitempty"` // .{1,128} } +func (dst *Hotspot2ConfIcon) UnmarshalJSON(b []byte) error { + type Alias Hotspot2ConfIcon + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + type Hotspot2ConfIcons struct { Data string `json:"data,omitempty"` Filename string `json:"filename,omitempty"` // .{1,256} @@ -112,6 +251,29 @@ type Hotspot2ConfIcons struct { Width int `json:"width,omitempty"` } +func (dst *Hotspot2ConfIcons) UnmarshalJSON(b []byte) error { + type Alias Hotspot2ConfIcons + aux := &struct { + Height emptyStringInt `json:"height"` + Size emptyStringInt `json:"size"` + Width emptyStringInt `json:"width"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.Height = int(aux.Height) + dst.Size = int(aux.Size) + dst.Width = int(aux.Width) + + return nil +} + type Hotspot2ConfNaiRealmList struct { AuthIDs string `json:"auth_ids,omitempty"` AuthVals string `json:"auth_vals,omitempty"` @@ -121,6 +283,27 @@ type Hotspot2ConfNaiRealmList struct { Status bool `json:"status"` } +func (dst *Hotspot2ConfNaiRealmList) UnmarshalJSON(b []byte) error { + type Alias Hotspot2ConfNaiRealmList + aux := &struct { + EapMethod emptyStringInt `json:"eap_method"` + Encoding emptyStringInt `json:"encoding"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.EapMethod = int(aux.EapMethod) + dst.Encoding = int(aux.Encoding) + + return nil +} + type Hotspot2ConfOsu struct { Description []Hotspot2ConfDescription `json:"description,omitempty"` FriendlyName []Hotspot2ConfFriendlyName `json:"friendly_name,omitempty"` @@ -133,27 +316,117 @@ type Hotspot2ConfOsu struct { ServerUri string `json:"server_uri,omitempty"` } +func (dst *Hotspot2ConfOsu) UnmarshalJSON(b []byte) error { + type Alias Hotspot2ConfOsu + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + type Hotspot2ConfQOSMapDcsp struct { High int `json:"high,omitempty"` Low int `json:"low,omitempty"` } +func (dst *Hotspot2ConfQOSMapDcsp) UnmarshalJSON(b []byte) error { + type Alias Hotspot2ConfQOSMapDcsp + aux := &struct { + High emptyStringInt `json:"high"` + Low emptyStringInt `json:"low"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.High = int(aux.High) + dst.Low = int(aux.Low) + + return nil +} + type Hotspot2ConfQOSMapExceptions struct { Dcsp int `json:"dcsp,omitempty"` Up int `json:"up,omitempty"` // [0-7] } +func (dst *Hotspot2ConfQOSMapExceptions) UnmarshalJSON(b []byte) error { + type Alias Hotspot2ConfQOSMapExceptions + aux := &struct { + Dcsp emptyStringInt `json:"dcsp"` + Up emptyStringInt `json:"up"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.Dcsp = int(aux.Dcsp) + dst.Up = int(aux.Up) + + return nil +} + type Hotspot2ConfRoamingConsortiumList struct { Name string `json:"name,omitempty"` // .{1,128} Oid string `json:"oid,omitempty"` // .{1,128} } +func (dst *Hotspot2ConfRoamingConsortiumList) UnmarshalJSON(b []byte) error { + type Alias Hotspot2ConfRoamingConsortiumList + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + type Hotspot2ConfVenueName struct { Language string `json:"language,omitempty"` // [a-z]{3} Name string `json:"name,omitempty"` Url string `json:"url,omitempty"` } +func (dst *Hotspot2ConfVenueName) UnmarshalJSON(b []byte) error { + type Alias Hotspot2ConfVenueName + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) listHotspot2Conf(ctx context.Context, site string) ([]Hotspot2Conf, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/hotspot_op.generated.go b/unifi/hotspot_op.generated.go index f3236e3..83cfa1f 100644 --- a/unifi/hotspot_op.generated.go +++ b/unifi/hotspot_op.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type HotspotOp struct { @@ -28,6 +30,22 @@ type HotspotOp struct { XPassword string `json:"x_password,omitempty"` // .{1,256} } +func (dst *HotspotOp) UnmarshalJSON(b []byte) error { + type Alias HotspotOp + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) listHotspotOp(ctx context.Context, site string) ([]HotspotOp, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/hotspot_package.generated.go b/unifi/hotspot_package.generated.go index 5f5af6f..59ec6a6 100644 --- a/unifi/hotspot_package.generated.go +++ b/unifi/hotspot_package.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type HotspotPackage struct { @@ -54,6 +56,35 @@ type HotspotPackage struct { TrialReset float64 `json:"trial_reset,omitempty"` } +func (dst *HotspotPackage) UnmarshalJSON(b []byte) error { + type Alias HotspotPackage + aux := &struct { + Hours emptyStringInt `json:"hours"` + Index emptyStringInt `json:"index"` + LimitDown emptyStringInt `json:"limit_down"` + LimitQuota emptyStringInt `json:"limit_quota"` + LimitUp emptyStringInt `json:"limit_up"` + TrialDurationMinutes emptyStringInt `json:"trial_duration_minutes"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.Hours = int(aux.Hours) + dst.Index = int(aux.Index) + dst.LimitDown = int(aux.LimitDown) + dst.LimitQuota = int(aux.LimitQuota) + dst.LimitUp = int(aux.LimitUp) + dst.TrialDurationMinutes = int(aux.TrialDurationMinutes) + + return nil +} + func (c *Client) listHotspotPackage(ctx context.Context, site string) ([]HotspotPackage, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/map.generated.go b/unifi/map.generated.go index ba02405..329093a 100644 --- a/unifi/map.generated.go +++ b/unifi/map.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type Map struct { @@ -38,6 +40,27 @@ type Map struct { Zoom int `json:"zoom,omitempty"` } +func (dst *Map) UnmarshalJSON(b []byte) error { + type Alias Map + aux := &struct { + Tilt emptyStringInt `json:"tilt"` + Zoom emptyStringInt `json:"zoom"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.Tilt = int(aux.Tilt) + dst.Zoom = int(aux.Zoom) + + return nil +} + func (c *Client) listMap(ctx context.Context, site string) ([]Map, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/media_file.generated.go b/unifi/media_file.generated.go index c2ad8a5..0cf4117 100644 --- a/unifi/media_file.generated.go +++ b/unifi/media_file.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type MediaFile struct { @@ -26,6 +28,22 @@ type MediaFile struct { Name string `json:"name,omitempty"` } +func (dst *MediaFile) UnmarshalJSON(b []byte) error { + type Alias MediaFile + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) listMediaFile(ctx context.Context, site string) ([]MediaFile, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/network.generated.go b/unifi/network.generated.go index f153706..415785e 100644 --- a/unifi/network.generated.go +++ b/unifi/network.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type Network struct { @@ -166,16 +168,116 @@ type Network struct { XWANPassword string `json:"x_wan_password,omitempty"` // [^"' ]+ } +func (dst *Network) UnmarshalJSON(b []byte) error { + type Alias Network + aux := &struct { + DHCPDLeaseTime emptyStringInt `json:"dhcpd_leasetime"` + DHCPDTimeOffset emptyStringInt `json:"dhcpd_time_offset"` + DHCPDV6LeaseTime emptyStringInt `json:"dhcpdv6_leasetime"` + IGMPGroupmembership emptyStringInt `json:"igmp_groupmembership"` + IGMPMaxresponse emptyStringInt `json:"igmp_maxresponse"` + IGMPMcrtrexpiretime emptyStringInt `json:"igmp_mcrtrexpiretime"` + IPSecDhGroup emptyStringInt `json:"ipsec_dh_group"` + IPSecEspDhGroup emptyStringInt `json:"ipsec_esp_dh_group"` + IPSecIkeDhGroup emptyStringInt `json:"ipsec_ike_dh_group"` + IPV6RaPreferredLifetime emptyStringInt `json:"ipv6_ra_preferred_lifetime"` + IPV6RaValidLifetime emptyStringInt `json:"ipv6_ra_valid_lifetime"` + OpenVPNLocalPort emptyStringInt `json:"openvpn_local_port"` + OpenVPNRemotePort emptyStringInt `json:"openvpn_remote_port"` + PptpcRouteDistance emptyStringInt `json:"pptpc_route_distance"` + Priority emptyStringInt `json:"priority"` + RouteDistance emptyStringInt `json:"route_distance"` + VLAN emptyStringInt `json:"vlan"` + WANDHCPv6PDSize emptyStringInt `json:"wan_dhcpv6_pd_size"` + WANEgressQOS emptyStringInt `json:"wan_egress_qos"` + WANLoadBalanceWeight emptyStringInt `json:"wan_load_balance_weight"` + WANPrefixlen emptyStringInt `json:"wan_prefixlen"` + WANSmartqDownRate emptyStringInt `json:"wan_smartq_down_rate"` + WANSmartqUpRate emptyStringInt `json:"wan_smartq_up_rate"` + WANVLAN emptyStringInt `json:"wan_vlan"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.DHCPDLeaseTime = int(aux.DHCPDLeaseTime) + dst.DHCPDTimeOffset = int(aux.DHCPDTimeOffset) + dst.DHCPDV6LeaseTime = int(aux.DHCPDV6LeaseTime) + dst.IGMPGroupmembership = int(aux.IGMPGroupmembership) + dst.IGMPMaxresponse = int(aux.IGMPMaxresponse) + dst.IGMPMcrtrexpiretime = int(aux.IGMPMcrtrexpiretime) + dst.IPSecDhGroup = int(aux.IPSecDhGroup) + dst.IPSecEspDhGroup = int(aux.IPSecEspDhGroup) + dst.IPSecIkeDhGroup = int(aux.IPSecIkeDhGroup) + dst.IPV6RaPreferredLifetime = int(aux.IPV6RaPreferredLifetime) + dst.IPV6RaValidLifetime = int(aux.IPV6RaValidLifetime) + dst.OpenVPNLocalPort = int(aux.OpenVPNLocalPort) + dst.OpenVPNRemotePort = int(aux.OpenVPNRemotePort) + dst.PptpcRouteDistance = int(aux.PptpcRouteDistance) + dst.Priority = int(aux.Priority) + dst.RouteDistance = int(aux.RouteDistance) + dst.VLAN = int(aux.VLAN) + dst.WANDHCPv6PDSize = int(aux.WANDHCPv6PDSize) + dst.WANEgressQOS = int(aux.WANEgressQOS) + dst.WANLoadBalanceWeight = int(aux.WANLoadBalanceWeight) + dst.WANPrefixlen = int(aux.WANPrefixlen) + dst.WANSmartqDownRate = int(aux.WANSmartqDownRate) + dst.WANSmartqUpRate = int(aux.WANSmartqUpRate) + dst.WANVLAN = int(aux.WANVLAN) + + return nil +} + type NetworkNATOutboundIPAddresses struct { IPAddress string `json:"ip_address"` // ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^$ WANNetworkGroup string `json:"wan_network_group,omitempty"` // WAN|WAN2 } +func (dst *NetworkNATOutboundIPAddresses) UnmarshalJSON(b []byte) error { + type Alias NetworkNATOutboundIPAddresses + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + type NetworkWANDHCPOptions struct { OptionNumber int `json:"optionNumber,omitempty"` // ([1-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-4]) Value string `json:"value,omitempty"` } +func (dst *NetworkWANDHCPOptions) UnmarshalJSON(b []byte) error { + type Alias NetworkWANDHCPOptions + aux := &struct { + OptionNumber emptyStringInt `json:"optionNumber"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.OptionNumber = int(aux.OptionNumber) + + return nil +} + func (c *Client) listNetwork(ctx context.Context, site string) ([]Network, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/network.go b/unifi/network.go index 8c99dae..5bccab9 100644 --- a/unifi/network.go +++ b/unifi/network.go @@ -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"` diff --git a/unifi/network_test.go b/unifi/network_test.go index 588d219..93d1f38 100644 --- a/unifi/network_test.go +++ b/unifi/network_test.go @@ -51,6 +51,19 @@ func TestNetworkUnmarshalJSON(t *testing.T) { expected: unifi.Network{WANEgressQOS: 0}, json: `{ "wan_egress_qos": "" }`, }, + + "int wan_vlan": { + expected: unifi.Network{WANVLAN: 1}, + json: `{ "wan_vlan": 1 }`, + }, + "string wan_vlan": { + expected: unifi.Network{WANVLAN: 1}, + json: `{ "wan_vlan": "1" }`, + }, + "empty wan_vlan vlan": { + expected: unifi.Network{WANVLAN: 0}, + json: `{ "wan_vlan": "" }`, + }, } { t.Run(n, func(t *testing.T) { var actual unifi.Network diff --git a/unifi/port_forward.generated.go b/unifi/port_forward.generated.go index 1629005..6517260 100644 --- a/unifi/port_forward.generated.go +++ b/unifi/port_forward.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type PortForward struct { @@ -35,6 +37,22 @@ type PortForward struct { Src string `json:"src,omitempty"` // ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])-(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])/([0-9]|[1-2][0-9]|3[0-2])$|^!(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^!(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])-(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^!(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])/([0-9]|[1-2][0-9]|3[0-2])$|^any$ } +func (dst *PortForward) UnmarshalJSON(b []byte) error { + type Alias PortForward + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) listPortForward(ctx context.Context, site string) ([]PortForward, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/port_profile.generated.go b/unifi/port_profile.generated.go index 514d123..4bb62ef 100644 --- a/unifi/port_profile.generated.go +++ b/unifi/port_profile.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type PortProfile struct { @@ -59,6 +61,49 @@ type PortProfile struct { VoiceNetworkID string `json:"voice_networkconf_id"` } +func (dst *PortProfile) UnmarshalJSON(b []byte) error { + type Alias PortProfile + aux := &struct { + Dot1XIDleTimeout emptyStringInt `json:"dot1x_idle_timeout"` + EgressRateLimitKbps emptyStringInt `json:"egress_rate_limit_kbps"` + PriorityQueue1Level emptyStringInt `json:"priority_queue1_level"` + PriorityQueue2Level emptyStringInt `json:"priority_queue2_level"` + PriorityQueue3Level emptyStringInt `json:"priority_queue3_level"` + PriorityQueue4Level emptyStringInt `json:"priority_queue4_level"` + Speed emptyStringInt `json:"speed"` + StormctrlBroadcastastLevel emptyStringInt `json:"stormctrl_bcast_level"` + StormctrlBroadcastastRate emptyStringInt `json:"stormctrl_bcast_rate"` + StormctrlMcastLevel emptyStringInt `json:"stormctrl_mcast_level"` + StormctrlMcastRate emptyStringInt `json:"stormctrl_mcast_rate"` + StormctrlUcastLevel emptyStringInt `json:"stormctrl_ucast_level"` + StormctrlUcastRate emptyStringInt `json:"stormctrl_ucast_rate"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.Dot1XIDleTimeout = int(aux.Dot1XIDleTimeout) + dst.EgressRateLimitKbps = int(aux.EgressRateLimitKbps) + dst.PriorityQueue1Level = int(aux.PriorityQueue1Level) + dst.PriorityQueue2Level = int(aux.PriorityQueue2Level) + dst.PriorityQueue3Level = int(aux.PriorityQueue3Level) + dst.PriorityQueue4Level = int(aux.PriorityQueue4Level) + dst.Speed = int(aux.Speed) + dst.StormctrlBroadcastastLevel = int(aux.StormctrlBroadcastastLevel) + dst.StormctrlBroadcastastRate = int(aux.StormctrlBroadcastastRate) + dst.StormctrlMcastLevel = int(aux.StormctrlMcastLevel) + dst.StormctrlMcastRate = int(aux.StormctrlMcastRate) + dst.StormctrlUcastLevel = int(aux.StormctrlUcastLevel) + dst.StormctrlUcastRate = int(aux.StormctrlUcastRate) + + return nil +} + func (c *Client) listPortProfile(ctx context.Context, site string) ([]PortProfile, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/radius_profile.generated.go b/unifi/radius_profile.generated.go index a953381..f90dd74 100644 --- a/unifi/radius_profile.generated.go +++ b/unifi/radius_profile.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type RADIUSProfile struct { @@ -35,18 +37,75 @@ type RADIUSProfile struct { VLANWLANMode string `json:"vlan_wlan_mode,omitempty"` // disabled|optional|required } +func (dst *RADIUSProfile) UnmarshalJSON(b []byte) error { + type Alias RADIUSProfile + aux := &struct { + InterimUpdateInterval emptyStringInt `json:"interim_update_interval"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.InterimUpdateInterval = int(aux.InterimUpdateInterval) + + return nil +} + type RADIUSProfileAcctServers struct { IP string `json:"ip,omitempty"` // ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$ Port int `json:"port,omitempty"` // ^([1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-4][0-9]{2}|[6][5][5][0-2][0-9]|[6][5][5][3][0-5])$|^$ XSecret string `json:"x_secret,omitempty"` } +func (dst *RADIUSProfileAcctServers) UnmarshalJSON(b []byte) error { + type Alias RADIUSProfileAcctServers + aux := &struct { + Port emptyStringInt `json:"port"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.Port = int(aux.Port) + + return nil +} + type RADIUSProfileAuthServers struct { IP string `json:"ip,omitempty"` // ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$ Port int `json:"port,omitempty"` // ^([1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-4][0-9]{2}|[6][5][5][0-2][0-9]|[6][5][5][3][0-5])$|^$ XSecret string `json:"x_secret,omitempty"` } +func (dst *RADIUSProfileAuthServers) UnmarshalJSON(b []byte) error { + type Alias RADIUSProfileAuthServers + aux := &struct { + Port emptyStringInt `json:"port"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.Port = int(aux.Port) + + return nil +} + func (c *Client) listRADIUSProfile(ctx context.Context, site string) ([]RADIUSProfile, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/routing.generated.go b/unifi/routing.generated.go index f779758..58dd01d 100644 --- a/unifi/routing.generated.go +++ b/unifi/routing.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type Routing struct { @@ -33,6 +35,25 @@ type Routing struct { Type string `json:"type,omitempty"` // static-route } +func (dst *Routing) UnmarshalJSON(b []byte) error { + type Alias Routing + aux := &struct { + StaticRouteDistance emptyStringInt `json:"static-route_distance"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.StaticRouteDistance = int(aux.StaticRouteDistance) + + return nil +} + func (c *Client) listRouting(ctx context.Context, site string) ([]Routing, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/schedule_task.generated.go b/unifi/schedule_task.generated.go index d4ba0b3..5e2e261 100644 --- a/unifi/schedule_task.generated.go +++ b/unifi/schedule_task.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type ScheduleTask struct { @@ -35,10 +37,42 @@ type ScheduleTask struct { UpgradeTargets []ScheduleTaskUpgradeTargets `json:"upgrade_targets,omitempty"` } +func (dst *ScheduleTask) UnmarshalJSON(b []byte) error { + type Alias ScheduleTask + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + type ScheduleTaskUpgradeTargets struct { MAC string `json:"mac,omitempty"` // ^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})$ } +func (dst *ScheduleTaskUpgradeTargets) UnmarshalJSON(b []byte) error { + type Alias ScheduleTaskUpgradeTargets + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) listScheduleTask(ctx context.Context, site string) ([]ScheduleTask, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_auto_speedtest.generated.go b/unifi/setting_auto_speedtest.generated.go index d3ebe22..64a89e8 100644 --- a/unifi/setting_auto_speedtest.generated.go +++ b/unifi/setting_auto_speedtest.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingAutoSpeedtest struct { @@ -29,6 +31,25 @@ type SettingAutoSpeedtest struct { Interval int `json:"interval,omitempty"` // ^(1[2-9]|[2-9][0-9]|[1-9][0-9]{2,3})$ } +func (dst *SettingAutoSpeedtest) UnmarshalJSON(b []byte) error { + type Alias SettingAutoSpeedtest + aux := &struct { + Interval emptyStringInt `json:"interval"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.Interval = int(aux.Interval) + + return nil +} + func (c *Client) getSettingAutoSpeedtest(ctx context.Context, site string) (*SettingAutoSpeedtest, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_baresip.generated.go b/unifi/setting_baresip.generated.go index 15de448..e4968da 100644 --- a/unifi/setting_baresip.generated.go +++ b/unifi/setting_baresip.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingBaresip struct { @@ -31,6 +33,22 @@ type SettingBaresip struct { Server string `json:"server,omitempty"` } +func (dst *SettingBaresip) UnmarshalJSON(b []byte) error { + type Alias SettingBaresip + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) getSettingBaresip(ctx context.Context, site string) (*SettingBaresip, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_broadcast.generated.go b/unifi/setting_broadcast.generated.go index 3e559eb..8b44781 100644 --- a/unifi/setting_broadcast.generated.go +++ b/unifi/setting_broadcast.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingBroadcast struct { @@ -33,6 +35,22 @@ type SettingBroadcast struct { SoundBeforeType string `json:"sound_before_type,omitempty"` // sample|media } +func (dst *SettingBroadcast) UnmarshalJSON(b []byte) error { + type Alias SettingBroadcast + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) getSettingBroadcast(ctx context.Context, site string) (*SettingBroadcast, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_connectivity.generated.go b/unifi/setting_connectivity.generated.go index dfdde3d..cf06e88 100644 --- a/unifi/setting_connectivity.generated.go +++ b/unifi/setting_connectivity.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingConnectivity struct { @@ -33,6 +35,22 @@ type SettingConnectivity struct { XMeshPsk string `json:"x_mesh_psk,omitempty"` } +func (dst *SettingConnectivity) UnmarshalJSON(b []byte) error { + type Alias SettingConnectivity + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) getSettingConnectivity(ctx context.Context, site string) (*SettingConnectivity, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_country.generated.go b/unifi/setting_country.generated.go index 8031553..f91fa6e 100644 --- a/unifi/setting_country.generated.go +++ b/unifi/setting_country.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingCountry struct { @@ -28,6 +30,25 @@ type SettingCountry struct { Code int `json:"code,omitempty"` } +func (dst *SettingCountry) UnmarshalJSON(b []byte) error { + type Alias SettingCountry + aux := &struct { + Code emptyStringInt `json:"code"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.Code = int(aux.Code) + + return nil +} + func (c *Client) getSettingCountry(ctx context.Context, site string) (*SettingCountry, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_dpi.generated.go b/unifi/setting_dpi.generated.go index 284a5dd..0a5abde 100644 --- a/unifi/setting_dpi.generated.go +++ b/unifi/setting_dpi.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingDpi struct { @@ -29,6 +31,22 @@ type SettingDpi struct { FingerprintingEnabled bool `json:"fingerprintingEnabled"` } +func (dst *SettingDpi) UnmarshalJSON(b []byte) error { + type Alias SettingDpi + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) getSettingDpi(ctx context.Context, site string) (*SettingDpi, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_element_adopt.generated.go b/unifi/setting_element_adopt.generated.go index 6ecda5c..c4bb492 100644 --- a/unifi/setting_element_adopt.generated.go +++ b/unifi/setting_element_adopt.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingElementAdopt struct { @@ -30,6 +32,22 @@ type SettingElementAdopt struct { XElementPsk string `json:"x_element_psk,omitempty"` } +func (dst *SettingElementAdopt) UnmarshalJSON(b []byte) error { + type Alias SettingElementAdopt + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) getSettingElementAdopt(ctx context.Context, site string) (*SettingElementAdopt, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_guest_access.generated.go b/unifi/setting_guest_access.generated.go index 96c9252..3c41527 100644 --- a/unifi/setting_guest_access.generated.go +++ b/unifi/setting_guest_access.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingGuestAccess struct { @@ -116,6 +118,31 @@ type SettingGuestAccess struct { XWechatSecretKey string `json:"x_wechat_secret_key,omitempty"` } +func (dst *SettingGuestAccess) UnmarshalJSON(b []byte) error { + type Alias SettingGuestAccess + aux := &struct { + ExpireNumber emptyStringInt `json:"expire_number"` + ExpireUnit emptyStringInt `json:"expire_unit"` + PortalCustomizedBoxOpacity emptyStringInt `json:"portal_customized_box_opacity"` + RADIUSDisconnectPort emptyStringInt `json:"radius_disconnect_port"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.ExpireNumber = int(aux.ExpireNumber) + dst.ExpireUnit = int(aux.ExpireUnit) + dst.PortalCustomizedBoxOpacity = int(aux.PortalCustomizedBoxOpacity) + dst.RADIUSDisconnectPort = int(aux.RADIUSDisconnectPort) + + return nil +} + func (c *Client) getSettingGuestAccess(ctx context.Context, site string) (*SettingGuestAccess, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_ips.generated.go b/unifi/setting_ips.generated.go index 934846e..0faac49 100644 --- a/unifi/setting_ips.generated.go +++ b/unifi/setting_ips.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingIps struct { @@ -38,6 +40,22 @@ type SettingIps struct { Suppression SettingIpsSuppression `json:"suppression,omitempty"` } +func (dst *SettingIps) UnmarshalJSON(b []byte) error { + type Alias SettingIps + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + type SettingIpsAlerts struct { Category string `json:"category,omitempty"` Gid int `json:"gid,omitempty"` @@ -47,6 +65,27 @@ type SettingIpsAlerts struct { Type string `json:"type,omitempty"` // all|track } +func (dst *SettingIpsAlerts) UnmarshalJSON(b []byte) error { + type Alias SettingIpsAlerts + aux := &struct { + Gid emptyStringInt `json:"gid"` + ID emptyStringInt `json:"id"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.Gid = int(aux.Gid) + dst.ID = int(aux.ID) + + return nil +} + type SettingIpsDNSFilters struct { AllowedSites []string `json:"allowed_sites,omitempty"` // ^[a-zA-Z0-9.-]+$|^$ BlockedSites []string `json:"blocked_sites,omitempty"` // ^[a-zA-Z0-9.-]+$|^$ @@ -58,29 +97,109 @@ type SettingIpsDNSFilters struct { Version string `json:"version,omitempty"` // v4|v6 } +func (dst *SettingIpsDNSFilters) UnmarshalJSON(b []byte) error { + type Alias SettingIpsDNSFilters + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + type SettingIpsHoneypot struct { IPAddress string `json:"ip_address,omitempty"` NetworkID string `json:"network_id"` Version string `json:"version,omitempty"` // v4|v6 } +func (dst *SettingIpsHoneypot) UnmarshalJSON(b []byte) error { + type Alias SettingIpsHoneypot + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + type SettingIpsSuppression struct { Alerts []SettingIpsAlerts `json:"alerts,omitempty"` Whitelist []SettingIpsWhitelist `json:"whitelist,omitempty"` } +func (dst *SettingIpsSuppression) UnmarshalJSON(b []byte) error { + type Alias SettingIpsSuppression + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + type SettingIpsTracking struct { Direction string `json:"direction,omitempty"` // both|src|dest Mode string `json:"mode,omitempty"` // ip|subnet|network Value string `json:"value,omitempty"` } +func (dst *SettingIpsTracking) UnmarshalJSON(b []byte) error { + type Alias SettingIpsTracking + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + type SettingIpsWhitelist struct { Direction string `json:"direction,omitempty"` // both|src|dest Mode string `json:"mode,omitempty"` // ip|subnet|network Value string `json:"value,omitempty"` } +func (dst *SettingIpsWhitelist) UnmarshalJSON(b []byte) error { + type Alias SettingIpsWhitelist + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) getSettingIps(ctx context.Context, site string) (*SettingIps, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_lcm.generated.go b/unifi/setting_lcm.generated.go index 9203acc..2886c29 100644 --- a/unifi/setting_lcm.generated.go +++ b/unifi/setting_lcm.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingLcm struct { @@ -32,6 +34,27 @@ type SettingLcm struct { TouchEvent bool `json:"touch_event"` } +func (dst *SettingLcm) UnmarshalJSON(b []byte) error { + type Alias SettingLcm + aux := &struct { + Brightness emptyStringInt `json:"brightness"` + IDleTimeout emptyStringInt `json:"idle_timeout"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.Brightness = int(aux.Brightness) + dst.IDleTimeout = int(aux.IDleTimeout) + + return nil +} + func (c *Client) getSettingLcm(ctx context.Context, site string) (*SettingLcm, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_locale.generated.go b/unifi/setting_locale.generated.go index 95a2084..d7723bf 100644 --- a/unifi/setting_locale.generated.go +++ b/unifi/setting_locale.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingLocale struct { @@ -28,6 +30,22 @@ type SettingLocale struct { Timezone string `json:"timezone,omitempty"` } +func (dst *SettingLocale) UnmarshalJSON(b []byte) error { + type Alias SettingLocale + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) getSettingLocale(ctx context.Context, site string) (*SettingLocale, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_mgmt.generated.go b/unifi/setting_mgmt.generated.go index b6a1b71..381ef67 100644 --- a/unifi/setting_mgmt.generated.go +++ b/unifi/setting_mgmt.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingMgmt struct { @@ -44,6 +46,22 @@ type SettingMgmt struct { XSshUsername string `json:"x_ssh_username,omitempty"` // ^[_A-Za-z0-9][-_.A-Za-z0-9]{0,29}$ } +func (dst *SettingMgmt) UnmarshalJSON(b []byte) error { + type Alias SettingMgmt + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) getSettingMgmt(ctx context.Context, site string) (*SettingMgmt, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_network_optimization.generated.go b/unifi/setting_network_optimization.generated.go index 3016f5e..993ab20 100644 --- a/unifi/setting_network_optimization.generated.go +++ b/unifi/setting_network_optimization.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingNetworkOptimization struct { @@ -28,6 +30,22 @@ type SettingNetworkOptimization struct { Enabled bool `json:"enabled"` } +func (dst *SettingNetworkOptimization) UnmarshalJSON(b []byte) error { + type Alias SettingNetworkOptimization + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) getSettingNetworkOptimization(ctx context.Context, site string) (*SettingNetworkOptimization, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_ntp.generated.go b/unifi/setting_ntp.generated.go index 9c7e504..af7a36a 100644 --- a/unifi/setting_ntp.generated.go +++ b/unifi/setting_ntp.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingNtp struct { @@ -31,6 +33,22 @@ type SettingNtp struct { NtpServer4 string `json:"ntp_server_4,omitempty"` } +func (dst *SettingNtp) UnmarshalJSON(b []byte) error { + type Alias SettingNtp + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) getSettingNtp(ctx context.Context, site string) (*SettingNtp, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_porta.generated.go b/unifi/setting_porta.generated.go index cc3a967..fd2eae6 100644 --- a/unifi/setting_porta.generated.go +++ b/unifi/setting_porta.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingPorta struct { @@ -28,6 +30,22 @@ type SettingPorta struct { Ugw3WAN2Enabled bool `json:"ugw3_wan2_enabled"` } +func (dst *SettingPorta) UnmarshalJSON(b []byte) error { + type Alias SettingPorta + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) getSettingPorta(ctx context.Context, site string) (*SettingPorta, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_provider_capabilities.generated.go b/unifi/setting_provider_capabilities.generated.go index dc859a3..ef128ce 100644 --- a/unifi/setting_provider_capabilities.generated.go +++ b/unifi/setting_provider_capabilities.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingProviderCapabilities struct { @@ -30,6 +32,27 @@ type SettingProviderCapabilities struct { Upload int `json:"upload,omitempty"` // ^[1-9][0-9]*$ } +func (dst *SettingProviderCapabilities) UnmarshalJSON(b []byte) error { + type Alias SettingProviderCapabilities + aux := &struct { + Download emptyStringInt `json:"download"` + Upload emptyStringInt `json:"upload"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.Download = int(aux.Download) + dst.Upload = int(aux.Upload) + + return nil +} + func (c *Client) getSettingProviderCapabilities(ctx context.Context, site string) (*SettingProviderCapabilities, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_radio_ai.generated.go b/unifi/setting_radio_ai.generated.go index 94dd6ed..3662378 100644 --- a/unifi/setting_radio_ai.generated.go +++ b/unifi/setting_radio_ai.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingRadioAi struct { @@ -38,6 +40,43 @@ type SettingRadioAi struct { UseXY bool `json:"useXY"` } +func (dst *SettingRadioAi) UnmarshalJSON(b []byte) error { + type Alias SettingRadioAi + aux := &struct { + ChannelsNa []emptyStringInt `json:"channels_na"` + ChannelsNg []emptyStringInt `json:"channels_ng"` + HtModesNa []emptyStringInt `json:"ht_modes_na"` + HtModesNg []emptyStringInt `json:"ht_modes_ng"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.ChannelsNa = make([]int, len(aux.ChannelsNa)) + for i, v := range aux.ChannelsNa { + dst.ChannelsNa[i] = int(v) + } + dst.ChannelsNg = make([]int, len(aux.ChannelsNg)) + for i, v := range aux.ChannelsNg { + dst.ChannelsNg[i] = int(v) + } + dst.HtModesNa = make([]int, len(aux.HtModesNa)) + for i, v := range aux.HtModesNa { + dst.HtModesNa[i] = int(v) + } + dst.HtModesNg = make([]int, len(aux.HtModesNg)) + for i, v := range aux.HtModesNg { + dst.HtModesNg[i] = int(v) + } + + return nil +} + func (c *Client) getSettingRadioAi(ctx context.Context, site string) (*SettingRadioAi, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_radius.generated.go b/unifi/setting_radius.generated.go index 45ca18c..3c1c46c 100644 --- a/unifi/setting_radius.generated.go +++ b/unifi/setting_radius.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingRadius struct { @@ -35,6 +37,29 @@ type SettingRadius struct { XSecret string `json:"x_secret,omitempty"` // [^\"\' ]{1,48} } +func (dst *SettingRadius) UnmarshalJSON(b []byte) error { + type Alias SettingRadius + aux := &struct { + AcctPort emptyStringInt `json:"acct_port"` + AuthPort emptyStringInt `json:"auth_port"` + InterimUpdateInterval emptyStringInt `json:"interim_update_interval"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.AcctPort = int(aux.AcctPort) + dst.AuthPort = int(aux.AuthPort) + dst.InterimUpdateInterval = int(aux.InterimUpdateInterval) + + return nil +} + func (c *Client) getSettingRadius(ctx context.Context, site string) (*SettingRadius, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_rsyslogd.generated.go b/unifi/setting_rsyslogd.generated.go index ce8ebd4..9a6cc60 100644 --- a/unifi/setting_rsyslogd.generated.go +++ b/unifi/setting_rsyslogd.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingRsyslogd struct { @@ -36,6 +38,27 @@ type SettingRsyslogd struct { ThisControllerEncryptedOnly bool `json:"this_controller_encrypted_only"` } +func (dst *SettingRsyslogd) UnmarshalJSON(b []byte) error { + type Alias SettingRsyslogd + aux := &struct { + NetconsolePort emptyStringInt `json:"netconsole_port"` + Port emptyStringInt `json:"port"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.NetconsolePort = int(aux.NetconsolePort) + dst.Port = int(aux.Port) + + return nil +} + func (c *Client) getSettingRsyslogd(ctx context.Context, site string) (*SettingRsyslogd, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_snmp.generated.go b/unifi/setting_snmp.generated.go index 3910629..0398a5f 100644 --- a/unifi/setting_snmp.generated.go +++ b/unifi/setting_snmp.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingSnmp struct { @@ -32,6 +34,22 @@ type SettingSnmp struct { XPassword string `json:"x_password,omitempty"` // [^'"]{8,32} } +func (dst *SettingSnmp) UnmarshalJSON(b []byte) error { + type Alias SettingSnmp + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) getSettingSnmp(ctx context.Context, site string) (*SettingSnmp, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_super_cloudaccess.generated.go b/unifi/setting_super_cloudaccess.generated.go index 24fc67d..c137051 100644 --- a/unifi/setting_super_cloudaccess.generated.go +++ b/unifi/setting_super_cloudaccess.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingSuperCloudaccess struct { @@ -34,6 +36,22 @@ type SettingSuperCloudaccess struct { XPrivateKey string `json:"x_private_key,omitempty"` } +func (dst *SettingSuperCloudaccess) UnmarshalJSON(b []byte) error { + type Alias SettingSuperCloudaccess + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) getSettingSuperCloudaccess(ctx context.Context, site string) (*SettingSuperCloudaccess, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_super_events.generated.go b/unifi/setting_super_events.generated.go index 75ef0db..bf24e0c 100644 --- a/unifi/setting_super_events.generated.go +++ b/unifi/setting_super_events.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingSuperEvents struct { @@ -28,6 +30,22 @@ type SettingSuperEvents struct { Ignored string `json:"_ignored,omitempty"` } +func (dst *SettingSuperEvents) UnmarshalJSON(b []byte) error { + type Alias SettingSuperEvents + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) getSettingSuperEvents(ctx context.Context, site string) (*SettingSuperEvents, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_super_fwupdate.generated.go b/unifi/setting_super_fwupdate.generated.go index df1a222..f1dd6d6 100644 --- a/unifi/setting_super_fwupdate.generated.go +++ b/unifi/setting_super_fwupdate.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingSuperFwupdate struct { @@ -30,6 +32,22 @@ type SettingSuperFwupdate struct { SsoEnabled bool `json:"sso_enabled"` } +func (dst *SettingSuperFwupdate) UnmarshalJSON(b []byte) error { + type Alias SettingSuperFwupdate + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) getSettingSuperFwupdate(ctx context.Context, site string) (*SettingSuperFwupdate, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_super_identity.generated.go b/unifi/setting_super_identity.generated.go index 3c6b5ee..8510e72 100644 --- a/unifi/setting_super_identity.generated.go +++ b/unifi/setting_super_identity.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingSuperIdentity struct { @@ -29,6 +31,22 @@ type SettingSuperIdentity struct { Name string `json:"name,omitempty"` } +func (dst *SettingSuperIdentity) UnmarshalJSON(b []byte) error { + type Alias SettingSuperIdentity + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) getSettingSuperIdentity(ctx context.Context, site string) (*SettingSuperIdentity, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_super_mail.generated.go b/unifi/setting_super_mail.generated.go index cd69697..9b7ce4f 100644 --- a/unifi/setting_super_mail.generated.go +++ b/unifi/setting_super_mail.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingSuperMail struct { @@ -28,6 +30,22 @@ type SettingSuperMail struct { Provider string `json:"provider,omitempty"` // smtp|cloud|disabled } +func (dst *SettingSuperMail) UnmarshalJSON(b []byte) error { + type Alias SettingSuperMail + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) getSettingSuperMail(ctx context.Context, site string) (*SettingSuperMail, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_super_mgmt.generated.go b/unifi/setting_super_mgmt.generated.go index 39aca69..9c41b11 100644 --- a/unifi/setting_super_mgmt.generated.go +++ b/unifi/setting_super_mgmt.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingSuperMgmt struct { @@ -50,7 +52,7 @@ type SettingSuperMgmt struct { ContactInfoState string `json:"contact_info_state,omitempty"` ContactInfoZip string `json:"contact_info_zip,omitempty"` DataRetentionTimeEnabled bool `json:"data_retention_time_enabled"` - DataRetentionTimeInHoursFor5minutesScale int `json:"data_retention_time_in_hours_for_5minutes_scale,omitempty"` + DataRetentionTimeInHoursFor5MinutesScale int `json:"data_retention_time_in_hours_for_5minutes_scale,omitempty"` DataRetentionTimeInHoursForDailyScale int `json:"data_retention_time_in_hours_for_daily_scale,omitempty"` DataRetentionTimeInHoursForHourlyScale int `json:"data_retention_time_in_hours_for_hourly_scale,omitempty"` DataRetentionTimeInHoursForMonthlyScale int `json:"data_retention_time_in_hours_for_monthly_scale,omitempty"` @@ -72,6 +74,41 @@ type SettingSuperMgmt struct { XSshUsername string `json:"x_ssh_username,omitempty"` } +func (dst *SettingSuperMgmt) UnmarshalJSON(b []byte) error { + type Alias SettingSuperMgmt + aux := &struct { + AutobackupDays emptyStringInt `json:"autobackup_days"` + AutobackupMaxFiles emptyStringInt `json:"autobackup_max_files"` + DataRetentionTimeInHoursFor5MinutesScale emptyStringInt `json:"data_retention_time_in_hours_for_5minutes_scale"` + DataRetentionTimeInHoursForDailyScale emptyStringInt `json:"data_retention_time_in_hours_for_daily_scale"` + DataRetentionTimeInHoursForHourlyScale emptyStringInt `json:"data_retention_time_in_hours_for_hourly_scale"` + DataRetentionTimeInHoursForMonthlyScale emptyStringInt `json:"data_retention_time_in_hours_for_monthly_scale"` + DataRetentionTimeInHoursForOthers emptyStringInt `json:"data_retention_time_in_hours_for_others"` + MinimumUsableHdSpace emptyStringInt `json:"minimum_usable_hd_space"` + MinimumUsableSdSpace emptyStringInt `json:"minimum_usable_sd_space"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.AutobackupDays = int(aux.AutobackupDays) + dst.AutobackupMaxFiles = int(aux.AutobackupMaxFiles) + dst.DataRetentionTimeInHoursFor5MinutesScale = int(aux.DataRetentionTimeInHoursFor5MinutesScale) + dst.DataRetentionTimeInHoursForDailyScale = int(aux.DataRetentionTimeInHoursForDailyScale) + dst.DataRetentionTimeInHoursForHourlyScale = int(aux.DataRetentionTimeInHoursForHourlyScale) + dst.DataRetentionTimeInHoursForMonthlyScale = int(aux.DataRetentionTimeInHoursForMonthlyScale) + dst.DataRetentionTimeInHoursForOthers = int(aux.DataRetentionTimeInHoursForOthers) + dst.MinimumUsableHdSpace = int(aux.MinimumUsableHdSpace) + dst.MinimumUsableSdSpace = int(aux.MinimumUsableSdSpace) + + return nil +} + func (c *Client) getSettingSuperMgmt(ctx context.Context, site string) (*SettingSuperMgmt, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_super_sdn.generated.go b/unifi/setting_super_sdn.generated.go index e9f81c4..47f9b7d 100644 --- a/unifi/setting_super_sdn.generated.go +++ b/unifi/setting_super_sdn.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingSuperSdn struct { @@ -37,6 +39,22 @@ type SettingSuperSdn struct { XOauthAppSecret string `json:"x_oauth_app_secret,omitempty"` } +func (dst *SettingSuperSdn) UnmarshalJSON(b []byte) error { + type Alias SettingSuperSdn + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) getSettingSuperSdn(ctx context.Context, site string) (*SettingSuperSdn, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_super_smtp.generated.go b/unifi/setting_super_smtp.generated.go index fbf5729..381c141 100644 --- a/unifi/setting_super_smtp.generated.go +++ b/unifi/setting_super_smtp.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingSuperSmtp struct { @@ -36,6 +38,25 @@ type SettingSuperSmtp struct { XPassword string `json:"x_password,omitempty"` } +func (dst *SettingSuperSmtp) UnmarshalJSON(b []byte) error { + type Alias SettingSuperSmtp + aux := &struct { + Port emptyStringInt `json:"port"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.Port = int(aux.Port) + + return nil +} + func (c *Client) getSettingSuperSmtp(ctx context.Context, site string) (*SettingSuperSmtp, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_usg.generated.go b/unifi/setting_usg.generated.go index 9599193..84c81be 100644 --- a/unifi/setting_usg.generated.go +++ b/unifi/setting_usg.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingUsg struct { @@ -82,6 +84,57 @@ type SettingUsg struct { UpnpWANInterface string `json:"upnp_wan_interface,omitempty"` // WAN|WAN2 } +func (dst *SettingUsg) UnmarshalJSON(b []byte) error { + type Alias SettingUsg + aux := &struct { + ArpCacheBaseReachable emptyStringInt `json:"arp_cache_base_reachable"` + DHCPRelayHopCount emptyStringInt `json:"dhcp_relay_hop_count"` + DHCPRelayMaxSize emptyStringInt `json:"dhcp_relay_max_size"` + DHCPRelayPort emptyStringInt `json:"dhcp_relay_port"` + ICMPTimeout emptyStringInt `json:"icmp_timeout"` + MssClampMss emptyStringInt `json:"mss_clamp_mss"` + OtherTimeout emptyStringInt `json:"other_timeout"` + TCPCloseTimeout emptyStringInt `json:"tcp_close_timeout"` + TCPCloseWaitTimeout emptyStringInt `json:"tcp_close_wait_timeout"` + TCPEstablishedTimeout emptyStringInt `json:"tcp_established_timeout"` + TCPFinWaitTimeout emptyStringInt `json:"tcp_fin_wait_timeout"` + TCPLastAckTimeout emptyStringInt `json:"tcp_last_ack_timeout"` + TCPSynRecvTimeout emptyStringInt `json:"tcp_syn_recv_timeout"` + TCPSynSentTimeout emptyStringInt `json:"tcp_syn_sent_timeout"` + TCPTimeWaitTimeout emptyStringInt `json:"tcp_time_wait_timeout"` + UDPOtherTimeout emptyStringInt `json:"udp_other_timeout"` + UDPStreamTimeout emptyStringInt `json:"udp_stream_timeout"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.ArpCacheBaseReachable = int(aux.ArpCacheBaseReachable) + dst.DHCPRelayHopCount = int(aux.DHCPRelayHopCount) + dst.DHCPRelayMaxSize = int(aux.DHCPRelayMaxSize) + dst.DHCPRelayPort = int(aux.DHCPRelayPort) + dst.ICMPTimeout = int(aux.ICMPTimeout) + dst.MssClampMss = int(aux.MssClampMss) + dst.OtherTimeout = int(aux.OtherTimeout) + dst.TCPCloseTimeout = int(aux.TCPCloseTimeout) + dst.TCPCloseWaitTimeout = int(aux.TCPCloseWaitTimeout) + dst.TCPEstablishedTimeout = int(aux.TCPEstablishedTimeout) + dst.TCPFinWaitTimeout = int(aux.TCPFinWaitTimeout) + dst.TCPLastAckTimeout = int(aux.TCPLastAckTimeout) + dst.TCPSynRecvTimeout = int(aux.TCPSynRecvTimeout) + dst.TCPSynSentTimeout = int(aux.TCPSynSentTimeout) + dst.TCPTimeWaitTimeout = int(aux.TCPTimeWaitTimeout) + dst.UDPOtherTimeout = int(aux.UDPOtherTimeout) + dst.UDPStreamTimeout = int(aux.UDPStreamTimeout) + + return nil +} + func (c *Client) getSettingUsg(ctx context.Context, site string) (*SettingUsg, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/setting_usw.generated.go b/unifi/setting_usw.generated.go index 8d90a08..bfb801a 100644 --- a/unifi/setting_usw.generated.go +++ b/unifi/setting_usw.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SettingUsw struct { @@ -28,6 +30,22 @@ type SettingUsw struct { DHCPSnoop bool `json:"dhcp_snoop"` } +func (dst *SettingUsw) UnmarshalJSON(b []byte) error { + type Alias SettingUsw + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) getSettingUsw(ctx context.Context, site string) (*SettingUsw, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/spatial_record.generated.go b/unifi/spatial_record.generated.go index 6f8ad5d..04f2495 100644 --- a/unifi/spatial_record.generated.go +++ b/unifi/spatial_record.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type SpatialRecord struct { @@ -27,17 +29,65 @@ type SpatialRecord struct { Name string `json:"name,omitempty"` // .{1,128} } +func (dst *SpatialRecord) UnmarshalJSON(b []byte) error { + type Alias SpatialRecord + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + type SpatialRecordDevices struct { MAC string `json:"mac,omitempty"` // ^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})$ Position SpatialRecordPosition `json:"position,omitempty"` } +func (dst *SpatialRecordDevices) UnmarshalJSON(b []byte) error { + type Alias SpatialRecordDevices + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + type SpatialRecordPosition struct { X float64 `json:"x,omitempty"` // (^([-]?[\d]+)$)|(^([-]?[\d]+[.]?[\d]+)$) Y float64 `json:"y,omitempty"` // (^([-]?[\d]+)$)|(^([-]?[\d]+[.]?[\d]+)$) Z float64 `json:"z,omitempty"` // (^([-]?[\d]+)$)|(^([-]?[\d]+[.]?[\d]+)$) } +func (dst *SpatialRecordPosition) UnmarshalJSON(b []byte) error { + type Alias SpatialRecordPosition + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) listSpatialRecord(ctx context.Context, site string) ([]SpatialRecord, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/tag.generated.go b/unifi/tag.generated.go index e42523c..a916dcf 100644 --- a/unifi/tag.generated.go +++ b/unifi/tag.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type Tag struct { @@ -27,6 +29,22 @@ type Tag struct { Name string `json:"name,omitempty"` } +func (dst *Tag) UnmarshalJSON(b []byte) error { + type Alias Tag + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) listTag(ctx context.Context, site string) ([]Tag, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/user.generated.go b/unifi/user.generated.go index f4bf2e3..b119b48 100644 --- a/unifi/user.generated.go +++ b/unifi/user.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type User struct { @@ -37,6 +39,25 @@ type User struct { UserGroupID string `json:"usergroup_id"` } +func (dst *User) UnmarshalJSON(b []byte) error { + type Alias User + aux := &struct { + LastSeen emptyStringInt `json:"last_seen"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.LastSeen = int(aux.LastSeen) + + return nil +} + func (c *Client) listUser(ctx context.Context, site string) ([]User, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/user_group.generated.go b/unifi/user_group.generated.go index 2c85f81..3b843e9 100644 --- a/unifi/user_group.generated.go +++ b/unifi/user_group.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type UserGroup struct { @@ -28,6 +30,27 @@ type UserGroup struct { QOSRateMaxUp int `json:"qos_rate_max_up,omitempty"` // -1|[2-9]|[1-9][0-9]{1,4}|100000 } +func (dst *UserGroup) UnmarshalJSON(b []byte) error { + type Alias UserGroup + aux := &struct { + QOSRateMaxDown emptyStringInt `json:"qos_rate_max_down"` + QOSRateMaxUp emptyStringInt `json:"qos_rate_max_up"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.QOSRateMaxDown = int(aux.QOSRateMaxDown) + dst.QOSRateMaxUp = int(aux.QOSRateMaxUp) + + return nil +} + func (c *Client) listUserGroup(ctx context.Context, site string) ([]UserGroup, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/virtual_device.generated.go b/unifi/virtual_device.generated.go index 57de5dc..2c6e40f 100644 --- a/unifi/virtual_device.generated.go +++ b/unifi/virtual_device.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type VirtualDevice struct { @@ -31,6 +33,22 @@ type VirtualDevice struct { Y string `json:"y,omitempty"` } +func (dst *VirtualDevice) UnmarshalJSON(b []byte) error { + type Alias VirtualDevice + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) listVirtualDevice(ctx context.Context, site string) ([]VirtualDevice, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/wlan.generated.go b/unifi/wlan.generated.go index f9b4371..9862edf 100644 --- a/unifi/wlan.generated.go +++ b/unifi/wlan.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type WLAN struct { @@ -97,6 +99,47 @@ type WLAN struct { XWEP string `json:"x_wep,omitempty"` } +func (dst *WLAN) UnmarshalJSON(b []byte) error { + type Alias WLAN + aux := &struct { + DTIMNa emptyStringInt `json:"dtim_na"` + DTIMNg emptyStringInt `json:"dtim_ng"` + GroupRekey emptyStringInt `json:"group_rekey"` + MinrateNaBeaconRateKbps emptyStringInt `json:"minrate_na_beacon_rate_kbps"` + MinrateNaDataRateKbps emptyStringInt `json:"minrate_na_data_rate_kbps"` + MinrateNaMgmtRateKbps emptyStringInt `json:"minrate_na_mgmt_rate_kbps"` + MinrateNgBeaconRateKbps emptyStringInt `json:"minrate_ng_beacon_rate_kbps"` + MinrateNgDataRateKbps emptyStringInt `json:"minrate_ng_data_rate_kbps"` + MinrateNgMgmtRateKbps emptyStringInt `json:"minrate_ng_mgmt_rate_kbps"` + RoamClusterID emptyStringInt `json:"roam_cluster_id"` + VLAN emptyStringInt `json:"vlan"` + WEPIDX emptyStringInt `json:"wep_idx"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.DTIMNa = int(aux.DTIMNa) + dst.DTIMNg = int(aux.DTIMNg) + dst.GroupRekey = int(aux.GroupRekey) + dst.MinrateNaBeaconRateKbps = int(aux.MinrateNaBeaconRateKbps) + dst.MinrateNaDataRateKbps = int(aux.MinrateNaDataRateKbps) + dst.MinrateNaMgmtRateKbps = int(aux.MinrateNaMgmtRateKbps) + dst.MinrateNgBeaconRateKbps = int(aux.MinrateNgBeaconRateKbps) + dst.MinrateNgDataRateKbps = int(aux.MinrateNgDataRateKbps) + dst.MinrateNgMgmtRateKbps = int(aux.MinrateNgMgmtRateKbps) + dst.RoamClusterID = int(aux.RoamClusterID) + dst.VLAN = int(aux.VLAN) + dst.WEPIDX = int(aux.WEPIDX) + + return nil +} + type WLANScheduleWithDuration struct { DurationMinutes int `json:"duration_minutes,omitempty"` // ^[1-9][0-9]*$ StartDaysOfWeek []string `json:"start_days_of_week,omitempty"` // ^(sun|mon|tue|wed|thu|fri|sat)$ @@ -104,6 +147,29 @@ type WLANScheduleWithDuration struct { StartMinute int `json:"start_minute,omitempty"` // ^[0-5]?[0-9]$ } +func (dst *WLANScheduleWithDuration) UnmarshalJSON(b []byte) error { + type Alias WLANScheduleWithDuration + aux := &struct { + DurationMinutes emptyStringInt `json:"duration_minutes"` + StartHour emptyStringInt `json:"start_hour"` + StartMinute emptyStringInt `json:"start_minute"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + dst.DurationMinutes = int(aux.DurationMinutes) + dst.StartHour = int(aux.StartHour) + dst.StartMinute = int(aux.StartMinute) + + return nil +} + func (c *Client) listWLAN(ctx context.Context, site string) ([]WLAN, error) { var respBody struct { Meta meta `json:"meta"` diff --git a/unifi/wlan.go b/unifi/wlan.go index ac52738..1afca38 100644 --- a/unifi/wlan.go +++ b/unifi/wlan.go @@ -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{} diff --git a/unifi/wlan_group.generated.go b/unifi/wlan_group.generated.go index 2541dcd..52990c5 100644 --- a/unifi/wlan_group.generated.go +++ b/unifi/wlan_group.generated.go @@ -5,13 +5,15 @@ package unifi import ( "context" + "encoding/json" "fmt" ) // just to fix compile issues with the import var ( - _ fmt.Formatter _ context.Context + _ fmt.Formatter + _ json.Marshaler ) type WLANGroup struct { @@ -26,6 +28,22 @@ type WLANGroup struct { Name string `json:"name,omitempty"` // .{1,128} } +func (dst *WLANGroup) UnmarshalJSON(b []byte) error { + type Alias WLANGroup + aux := &struct { + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + return nil +} + func (c *Client) listWLANGroup(ctx context.Context, site string) ([]WLANGroup, error) { var respBody struct { Meta meta `json:"meta"`