Files
go-unifi/unifi/setting_country.generated.go
Mateusz Filipowicz dca894e8e7 feat: use Client interface instead of client struct when interacting with UniFi SDK (#21)
* feat: use Client interface instead of client struct when interacting with UniFi SDK

Breaking change!

* chore: linting

* chore: linting
2025-02-17 09:38:41 +01:00

91 lines
1.8 KiB
Go
Generated

// Code generated from ace.jar fields *.json files
// DO NOT EDIT.
package unifi
import (
"context"
"encoding/json"
"fmt"
)
// just to fix compile issues with the import
var (
_ context.Context
_ fmt.Formatter
_ json.Marshaler
)
type SettingCountry struct {
ID string `json:"_id,omitempty"`
SiteID string `json:"site_id,omitempty"`
Hidden bool `json:"attr_hidden,omitempty"`
HiddenID string `json:"attr_hidden_id,omitempty"`
NoDelete bool `json:"attr_no_delete,omitempty"`
NoEdit bool `json:"attr_no_edit,omitempty"`
Key string `json:"key"`
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"`
Data []SettingCountry `json:"data"`
}
err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/country", site), nil, &respBody)
if err != nil {
return nil, err
}
if len(respBody.Data) != 1 {
return nil, ErrNotFound
}
d := respBody.Data[0]
return &d, nil
}
func (c *client) updateSettingCountry(ctx context.Context, site string, d *SettingCountry) (*SettingCountry, error) {
var respBody struct {
Meta Meta `json:"meta"`
Data []SettingCountry `json:"data"`
}
d.Key = "country"
err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/country", site), d, &respBody)
if err != nil {
return nil, err
}
if len(respBody.Data) != 1 {
return nil, ErrNotFound
}
new := respBody.Data[0]
return &new, nil
}