diff --git a/fields/extract.go b/fields/extract.go index 777a541..f382318 100644 --- a/fields/extract.go +++ b/fields/extract.go @@ -139,7 +139,7 @@ func extractJSON(jarFile, fieldsDir string) error { return fmt.Errorf("unable to open settings file: %w", err) } - var settings map[string]interface{} + var settings map[string]any err = json.Unmarshal(settingsData, &settings) if err != nil { return fmt.Errorf("unable to unmarshal settings: %w", err) diff --git a/fields/fwupdate.go b/fields/fwupdate.go index 15e67ed..eb5b50b 100644 --- a/fields/fwupdate.go +++ b/fields/fwupdate.go @@ -54,7 +54,7 @@ func (l firmwareUpdateApiResponseEmbeddedFirmwareDataLink) MarshalJSON() ([]byte } func (l *firmwareUpdateApiResponseEmbeddedFirmwareDataLink) UnmarshalJSON(j []byte) error { - var m map[string]interface{} + var m map[string]any err := json.Unmarshal(j, &m) if err != nil { diff --git a/fields/main.go b/fields/main.go index eb81f5b..af7a3c3 100644 --- a/fields/main.go +++ b/fields/main.go @@ -482,7 +482,7 @@ func (r *Resource) IsSetting() bool { return strings.HasPrefix(r.StructName, "Setting") } -func (r *Resource) processFields(fields map[string]interface{}) { +func (r *Resource) processFields(fields map[string]any) { t := r.Types[r.StructName] for name, validation := range fields { fieldInfo, err := r.fieldInfoFromValidation(name, validation) @@ -494,7 +494,7 @@ func (r *Resource) processFields(fields map[string]interface{}) { } } -func (r *Resource) fieldInfoFromValidation(name string, validation interface{}) (*FieldInfo, error) { +func (r *Resource) fieldInfoFromValidation(name string, validation any) (*FieldInfo, error) { fieldName := strcase.ToCamel(name) fieldName = cleanName(fieldName, fieldReps) @@ -502,7 +502,7 @@ func (r *Resource) fieldInfoFromValidation(name string, validation interface{}) var fieldInfo *FieldInfo switch validation := validation.(type) { - case []interface{}: + case []any: if len(validation) == 0 { fieldInfo = NewFieldInfo(fieldName, name, "string", "", false, true, "") err := r.FieldProcessor(fieldName, fieldInfo) @@ -523,7 +523,7 @@ func (r *Resource) fieldInfoFromValidation(name string, validation interface{}) err = r.FieldProcessor(fieldName, fieldInfo) return fieldInfo, err - case map[string]interface{}: + case map[string]any: typeName := r.StructName + fieldName result := NewFieldInfo(fieldName, name, typeName, "", true, false, "") @@ -587,7 +587,7 @@ func (r *Resource) fieldInfoFromValidation(name string, validation interface{}) } func (r *Resource) processJSON(b []byte) error { - var fields map[string]interface{} + var fields map[string]any err := json.Unmarshal(b, &fields) if err != nil { return err diff --git a/fields/main_test.go b/fields/main_test.go index f45bfd0..e896436 100644 --- a/fields/main_test.go +++ b/fields/main_test.go @@ -12,7 +12,7 @@ func TestFieldInfoFromValidation(t *testing.T) { expectedType string expectedComment string expectedOmitEmpty bool - validation interface{} + validation any }{ {"string", "", true, ""}, {"string", "default|custom", true, "default|custom"}, diff --git a/unifi/network.generated.go b/unifi/network.generated.go index 8befb14..f298225 100644 --- a/unifi/network.generated.go +++ b/unifi/network.generated.go @@ -92,7 +92,7 @@ type Network struct { IPSecEspDhGroup int `json:"ipsec_esp_dh_group,omitempty"` // 1|2|5|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32 IPSecEspEncryption string `json:"ipsec_esp_encryption,omitempty"` // aes128|aes192|aes256|3des IPSecEspHash string `json:"ipsec_esp_hash,omitempty"` // sha1|md5|sha256|sha384|sha512 - IPSecEspLifetime string `json:"ipsec_esp_lifetime,omitempty"` // ^(?:3[0-9]|[4-9][0-9]|[1-9][0-9]{2,3}|[1-7][0-9]{4}|8[0-5][0-9]{3}|86[0-3][0-9]{2}|86400)$ + IPSecEspLifetime emptyStringInt `json:"ipsec_esp_lifetime,omitempty"` // ^(?:3[0-9]|[4-9][0-9]|[1-9][0-9]{2,3}|[1-7][0-9]{4}|8[0-5][0-9]{3}|86[0-3][0-9]{2}|86400)$ IPSecHash string `json:"ipsec_hash,omitempty"` // sha1|md5|sha256|sha384|sha512 IPSecIkeDhGroup int `json:"ipsec_ike_dh_group,omitempty"` // 1|2|5|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32 IPSecIkeEncryption string `json:"ipsec_ike_encryption,omitempty"` // aes128|aes192|aes256|3des diff --git a/unifi/setting.go b/unifi/setting.go index 0c89e1f..34f6ecd 100644 --- a/unifi/setting.go +++ b/unifi/setting.go @@ -12,7 +12,7 @@ type Setting struct { Key string `json:"key"` } -func (s *Setting) newFields() (interface{}, error) { +func (s *Setting) newFields() (any, error) { switch s.Key { case "auto_speedtest": return &SettingAutoSpeedtest{}, nil @@ -79,7 +79,7 @@ func (s *Setting) newFields() (interface{}, error) { return nil, fmt.Errorf("unexpected key %q", s.Key) } -func (c *Client) GetSetting(ctx context.Context, site, key string) (*Setting, interface{}, error) { +func (c *Client) GetSetting(ctx context.Context, site, key string) (*Setting, any, error) { var respBody struct { Meta meta `json:"meta"` Data []json.RawMessage `json:"data"` diff --git a/unifi/unifi.go b/unifi/unifi.go index 516a9a9..1ffa0ec 100644 --- a/unifi/unifi.go +++ b/unifi/unifi.go @@ -190,7 +190,7 @@ func (c *Client) Login(ctx context.Context, user, pass string) error { return nil } -func (c *Client) do(ctx context.Context, method, relativeURL string, reqBody interface{}, respBody interface{}) error { +func (c *Client) do(ctx context.Context, method, relativeURL string, reqBody any, respBody any) error { // single threading requests, this is mostly to assist in CSRF token propagation c.Lock() defer c.Unlock() diff --git a/unifi/user.go b/unifi/user.go index b939c8c..d8397c9 100644 --- a/unifi/user.go +++ b/unifi/user.go @@ -71,8 +71,8 @@ func (c *Client) CreateUser(ctx context.Context, site string, d *User) (*User, e return &user, nil } -func (c *Client) stamgr(ctx context.Context, site, cmd string, data map[string]interface{}) ([]User, error) { - reqBody := map[string]interface{}{} +func (c *Client) stamgr(ctx context.Context, site, cmd string, data map[string]any) ([]User, error) { + reqBody := map[string]any{} for k, v := range data { reqBody[k] = v @@ -94,7 +94,7 @@ func (c *Client) stamgr(ctx context.Context, site, cmd string, data map[string]i } func (c *Client) BlockUserByMAC(ctx context.Context, site, mac string) error { - users, err := c.stamgr(ctx, site, "block-sta", map[string]interface{}{ + users, err := c.stamgr(ctx, site, "block-sta", map[string]any{ "mac": mac, }) if err != nil { @@ -107,7 +107,7 @@ func (c *Client) BlockUserByMAC(ctx context.Context, site, mac string) error { } func (c *Client) UnblockUserByMAC(ctx context.Context, site, mac string) error { - users, err := c.stamgr(ctx, site, "unblock-sta", map[string]interface{}{ + users, err := c.stamgr(ctx, site, "unblock-sta", map[string]any{ "mac": mac, }) if err != nil { @@ -120,7 +120,7 @@ func (c *Client) UnblockUserByMAC(ctx context.Context, site, mac string) error { } func (c *Client) DeleteUserByMAC(ctx context.Context, site, mac string) error { - users, err := c.stamgr(ctx, site, "forget-sta", map[string]interface{}{ + users, err := c.stamgr(ctx, site, "forget-sta", map[string]any{ "macs": []string{mac}, }) if err != nil { @@ -133,7 +133,7 @@ func (c *Client) DeleteUserByMAC(ctx context.Context, site, mac string) error { } func (c *Client) KickUserByMAC(ctx context.Context, site, mac string) error { - users, err := c.stamgr(ctx, site, "kick-sta", map[string]interface{}{ + users, err := c.stamgr(ctx, site, "kick-sta", map[string]any{ "mac": mac, }) if err != nil { @@ -146,7 +146,7 @@ func (c *Client) KickUserByMAC(ctx context.Context, site, mac string) error { } func (c *Client) OverrideUserFingerprint(ctx context.Context, site, mac string, devIdOveride int) error { - reqBody := map[string]interface{}{ + reqBody := map[string]any{ "mac": mac, "dev_id_override": devIdOveride, "search_query": "",