From d076e780050a376a05f1065b76b0cc97e897f27a Mon Sep 17 00:00:00 2001 From: Paul Tyng Date: Thu, 26 Mar 2020 16:12:52 -0400 Subject: [PATCH] Add context support --- fields/main.go | 26 +++++++----- unifi/account.generated.go | 26 +++++++----- unifi/broadcast_group.generated.go | 26 +++++++----- unifi/dhcp_option.generated.go | 26 +++++++----- unifi/dpi_app.generated.go | 26 +++++++----- unifi/dpi_group.generated.go | 26 +++++++----- unifi/dynamic_dns.generated.go | 26 +++++++----- unifi/firewall_group.generated.go | 26 +++++++----- unifi/firewall_group.go | 22 +++++----- unifi/firewall_rule.generated.go | 26 +++++++----- unifi/firewall_rule.go | 22 +++++----- unifi/heat_map.generated.go | 26 +++++++----- unifi/heat_map_point.generated.go | 26 +++++++----- unifi/hotspot_op.generated.go | 26 +++++++----- unifi/hotspot_package.generated.go | 26 +++++++----- unifi/map.generated.go | 26 +++++++----- unifi/media_file.generated.go | 26 +++++++----- unifi/network.generated.go | 26 +++++++----- unifi/network.go | 21 +++++----- unifi/port_conf.generated.go | 26 +++++++----- unifi/port_forward.generated.go | 26 +++++++----- unifi/port_forward.go | 22 +++++----- unifi/routing.generated.go | 26 +++++++----- unifi/setting.go | 12 +++--- unifi/setting_auto_speedtest.generated.go | 6 ++- unifi/setting_baresip.generated.go | 6 ++- unifi/setting_broadcast.generated.go | 6 ++- unifi/setting_connectivity.generated.go | 6 ++- unifi/setting_country.generated.go | 6 ++- unifi/setting_dpi.generated.go | 6 ++- unifi/setting_element_adopt.generated.go | 6 ++- unifi/setting_guest_access.generated.go | 6 ++- unifi/setting_lcm.generated.go | 6 ++- unifi/setting_locale.generated.go | 6 ++- unifi/setting_mgmt.generated.go | 6 ++- .../setting_network_optimization.generated.go | 6 ++- unifi/setting_ntp.generated.go | 6 ++- unifi/setting_porta.generated.go | 6 ++- ...setting_provider_capabilities.generated.go | 6 ++- unifi/setting_radio_ai.generated.go | 6 ++- unifi/setting_radius.generated.go | 6 ++- unifi/setting_rsyslogd.generated.go | 6 ++- unifi/setting_snmp.generated.go | 6 ++- unifi/setting_super_cloudaccess.generated.go | 6 ++- unifi/setting_super_events.generated.go | 6 ++- unifi/setting_super_fwupdate.generated.go | 6 ++- unifi/setting_super_identity.generated.go | 6 ++- unifi/setting_super_mail.generated.go | 6 ++- unifi/setting_super_mgmt.generated.go | 6 ++- unifi/setting_super_sdn.generated.go | 6 ++- unifi/setting_super_smtp.generated.go | 6 ++- unifi/setting_usg.generated.go | 6 ++- unifi/setting_usw.generated.go | 6 ++- unifi/sites.go | 6 ++- unifi/tag.generated.go | 26 +++++++----- unifi/unifi.go | 9 ++-- unifi/user.generated.go | 26 +++++++----- unifi/user.go | 41 ++++++++++--------- unifi/user_group.generated.go | 26 +++++++----- unifi/user_group.go | 22 +++++----- unifi/virtual_device.generated.go | 26 +++++++----- unifi/wlan.generated.go | 26 +++++++----- unifi/wlan.go | 21 +++++----- unifi/wlan_group.generated.go | 26 +++++++----- unifi/wlan_group.go | 25 ++++++----- 65 files changed, 642 insertions(+), 405 deletions(-) diff --git a/fields/main.go b/fields/main.go index 78ad56c..f7df839 100644 --- a/fields/main.go +++ b/fields/main.go @@ -156,11 +156,15 @@ func generateCode(fieldsFile string, structName string, urlPath string) (string, package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type %s struct { ID string `+"`json:\"_id,omitempty\"`"+` @@ -216,13 +220,13 @@ type %s struct { } code = code + fmt.Sprintf(` -func (c *Client) list%[1]s(site string) ([]%[1]s, error) { +func (c *Client) list%[1]s(ctx context.Context, site string) ([]%[1]s, error) { var respBody struct { Meta meta `+"`"+`json:"meta"`+"`"+` Data []%[1]s `+"`"+`json:"data"`+"`"+` } - err := c.do("GET", fmt.Sprintf("s/%%s/rest/%[2]s", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%%s/rest/%[2]s", site), nil, &respBody) if err != nil { return nil, err } @@ -230,13 +234,13 @@ func (c *Client) list%[1]s(site string) ([]%[1]s, error) { return respBody.Data, nil } -func (c *Client) get%[1]s(site, id string) (*%[1]s, error) { +func (c *Client) get%[1]s(ctx context.Context, site, id string) (*%[1]s, error) { var respBody struct { Meta meta `+"`"+`json:"meta"`+"`"+` Data []%[1]s `+"`"+`json:"data"`+"`"+` } - err := c.do("GET", fmt.Sprintf("s/%%s/rest/%[2]s/%%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%%s/rest/%[2]s/%%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -249,21 +253,21 @@ func (c *Client) get%[1]s(site, id string) (*%[1]s, error) { return &d, nil } -func (c *Client) delete%[1]s(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%%s/rest/%[2]s/%%s", site, id), struct{}{}, nil) +func (c *Client) delete%[1]s(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%%s/rest/%[2]s/%%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) create%[1]s(site string, d *%[1]s) (*%[1]s, error) { +func (c *Client) create%[1]s(ctx context.Context, site string, d *%[1]s) (*%[1]s, error) { var respBody struct { Meta meta `+"`"+`json:"meta"`+"`"+` Data []%[1]s `+"`"+`json:"data"`+"`"+` } - err := c.do("POST", fmt.Sprintf("s/%%s/rest/%[2]s", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%%s/rest/%[2]s", site), d, &respBody) if err != nil { return nil, err } @@ -277,13 +281,13 @@ func (c *Client) create%[1]s(site string, d *%[1]s) (*%[1]s, error) { return &new, nil } -func (c *Client) update%[1]s(site string, d *%[1]s) (*%[1]s, error) { +func (c *Client) update%[1]s(ctx context.Context, site string, d *%[1]s) (*%[1]s, error) { var respBody struct { Meta meta `+"`"+`json:"meta"`+"`"+` Data []%[1]s `+"`"+`json:"data"`+"`"+` } - err := c.do("PUT", fmt.Sprintf("s/%%s/rest/%[2]s/%%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%%s/rest/%[2]s/%%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/account.generated.go b/unifi/account.generated.go index 7466cac..d862363 100644 --- a/unifi/account.generated.go +++ b/unifi/account.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type Account struct { ID string `json:"_id,omitempty"` @@ -28,13 +32,13 @@ type Account struct { XPassword string `json:"x_password,omitempty"` } -func (c *Client) listAccount(site string) ([]Account, error) { +func (c *Client) listAccount(ctx context.Context, site string) ([]Account, error) { var respBody struct { Meta meta `json:"meta"` Data []Account `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/account", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/account", site), nil, &respBody) if err != nil { return nil, err } @@ -42,13 +46,13 @@ func (c *Client) listAccount(site string) ([]Account, error) { return respBody.Data, nil } -func (c *Client) getAccount(site, id string) (*Account, error) { +func (c *Client) getAccount(ctx context.Context, site, id string) (*Account, error) { var respBody struct { Meta meta `json:"meta"` Data []Account `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/account/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/account/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -61,21 +65,21 @@ func (c *Client) getAccount(site, id string) (*Account, error) { return &d, nil } -func (c *Client) deleteAccount(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/account/%s", site, id), struct{}{}, nil) +func (c *Client) deleteAccount(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/account/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createAccount(site string, d *Account) (*Account, error) { +func (c *Client) createAccount(ctx context.Context, site string, d *Account) (*Account, error) { var respBody struct { Meta meta `json:"meta"` Data []Account `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/account", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/account", site), d, &respBody) if err != nil { return nil, err } @@ -89,13 +93,13 @@ func (c *Client) createAccount(site string, d *Account) (*Account, error) { return &new, nil } -func (c *Client) updateAccount(site string, d *Account) (*Account, error) { +func (c *Client) updateAccount(ctx context.Context, site string, d *Account) (*Account, error) { var respBody struct { Meta meta `json:"meta"` Data []Account `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/account/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/account/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/broadcast_group.generated.go b/unifi/broadcast_group.generated.go index 43260a8..dfe1c34 100644 --- a/unifi/broadcast_group.generated.go +++ b/unifi/broadcast_group.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type BroadcastGroup struct { ID string `json:"_id,omitempty"` @@ -23,13 +27,13 @@ type BroadcastGroup struct { Name string `json:"name,omitempty"` } -func (c *Client) listBroadcastGroup(site string) ([]BroadcastGroup, error) { +func (c *Client) listBroadcastGroup(ctx context.Context, site string) ([]BroadcastGroup, error) { var respBody struct { Meta meta `json:"meta"` Data []BroadcastGroup `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/broadcastgroup", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/broadcastgroup", site), nil, &respBody) if err != nil { return nil, err } @@ -37,13 +41,13 @@ func (c *Client) listBroadcastGroup(site string) ([]BroadcastGroup, error) { return respBody.Data, nil } -func (c *Client) getBroadcastGroup(site, id string) (*BroadcastGroup, error) { +func (c *Client) getBroadcastGroup(ctx context.Context, site, id string) (*BroadcastGroup, error) { var respBody struct { Meta meta `json:"meta"` Data []BroadcastGroup `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/broadcastgroup/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/broadcastgroup/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -56,21 +60,21 @@ func (c *Client) getBroadcastGroup(site, id string) (*BroadcastGroup, error) { return &d, nil } -func (c *Client) deleteBroadcastGroup(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/broadcastgroup/%s", site, id), struct{}{}, nil) +func (c *Client) deleteBroadcastGroup(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/broadcastgroup/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createBroadcastGroup(site string, d *BroadcastGroup) (*BroadcastGroup, error) { +func (c *Client) createBroadcastGroup(ctx context.Context, site string, d *BroadcastGroup) (*BroadcastGroup, error) { var respBody struct { Meta meta `json:"meta"` Data []BroadcastGroup `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/broadcastgroup", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/broadcastgroup", site), d, &respBody) if err != nil { return nil, err } @@ -84,13 +88,13 @@ func (c *Client) createBroadcastGroup(site string, d *BroadcastGroup) (*Broadcas return &new, nil } -func (c *Client) updateBroadcastGroup(site string, d *BroadcastGroup) (*BroadcastGroup, error) { +func (c *Client) updateBroadcastGroup(ctx context.Context, site string, d *BroadcastGroup) (*BroadcastGroup, error) { var respBody struct { Meta meta `json:"meta"` Data []BroadcastGroup `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/broadcastgroup/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/broadcastgroup/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/dhcp_option.generated.go b/unifi/dhcp_option.generated.go index 34fade6..c8191de 100644 --- a/unifi/dhcp_option.generated.go +++ b/unifi/dhcp_option.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type DHCPOption struct { ID string `json:"_id,omitempty"` @@ -26,13 +30,13 @@ type DHCPOption struct { Width int `json:"width,omitempty"` // ^(8|16|32)$ } -func (c *Client) listDHCPOption(site string) ([]DHCPOption, error) { +func (c *Client) listDHCPOption(ctx context.Context, site string) ([]DHCPOption, error) { var respBody struct { Meta meta `json:"meta"` Data []DHCPOption `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/dhcpoption", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/dhcpoption", site), nil, &respBody) if err != nil { return nil, err } @@ -40,13 +44,13 @@ func (c *Client) listDHCPOption(site string) ([]DHCPOption, error) { return respBody.Data, nil } -func (c *Client) getDHCPOption(site, id string) (*DHCPOption, error) { +func (c *Client) getDHCPOption(ctx context.Context, site, id string) (*DHCPOption, error) { var respBody struct { Meta meta `json:"meta"` Data []DHCPOption `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/dhcpoption/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/dhcpoption/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -59,21 +63,21 @@ func (c *Client) getDHCPOption(site, id string) (*DHCPOption, error) { return &d, nil } -func (c *Client) deleteDHCPOption(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/dhcpoption/%s", site, id), struct{}{}, nil) +func (c *Client) deleteDHCPOption(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/dhcpoption/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createDHCPOption(site string, d *DHCPOption) (*DHCPOption, error) { +func (c *Client) createDHCPOption(ctx context.Context, site string, d *DHCPOption) (*DHCPOption, error) { var respBody struct { Meta meta `json:"meta"` Data []DHCPOption `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/dhcpoption", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/dhcpoption", site), d, &respBody) if err != nil { return nil, err } @@ -87,13 +91,13 @@ func (c *Client) createDHCPOption(site string, d *DHCPOption) (*DHCPOption, erro return &new, nil } -func (c *Client) updateDHCPOption(site string, d *DHCPOption) (*DHCPOption, error) { +func (c *Client) updateDHCPOption(ctx context.Context, site string, d *DHCPOption) (*DHCPOption, error) { var respBody struct { Meta meta `json:"meta"` Data []DHCPOption `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/dhcpoption/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/dhcpoption/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/dpi_app.generated.go b/unifi/dpi_app.generated.go index 5048e8a..caba619 100644 --- a/unifi/dpi_app.generated.go +++ b/unifi/dpi_app.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type DpiApp struct { ID string `json:"_id,omitempty"` @@ -29,13 +33,13 @@ 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 (c *Client) listDpiApp(site string) ([]DpiApp, error) { +func (c *Client) listDpiApp(ctx context.Context, site string) ([]DpiApp, error) { var respBody struct { Meta meta `json:"meta"` Data []DpiApp `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/dpiapp", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/dpiapp", site), nil, &respBody) if err != nil { return nil, err } @@ -43,13 +47,13 @@ func (c *Client) listDpiApp(site string) ([]DpiApp, error) { return respBody.Data, nil } -func (c *Client) getDpiApp(site, id string) (*DpiApp, error) { +func (c *Client) getDpiApp(ctx context.Context, site, id string) (*DpiApp, error) { var respBody struct { Meta meta `json:"meta"` Data []DpiApp `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/dpiapp/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/dpiapp/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -62,21 +66,21 @@ func (c *Client) getDpiApp(site, id string) (*DpiApp, error) { return &d, nil } -func (c *Client) deleteDpiApp(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/dpiapp/%s", site, id), struct{}{}, nil) +func (c *Client) deleteDpiApp(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/dpiapp/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createDpiApp(site string, d *DpiApp) (*DpiApp, error) { +func (c *Client) createDpiApp(ctx context.Context, site string, d *DpiApp) (*DpiApp, error) { var respBody struct { Meta meta `json:"meta"` Data []DpiApp `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/dpiapp", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/dpiapp", site), d, &respBody) if err != nil { return nil, err } @@ -90,13 +94,13 @@ func (c *Client) createDpiApp(site string, d *DpiApp) (*DpiApp, error) { return &new, nil } -func (c *Client) updateDpiApp(site string, d *DpiApp) (*DpiApp, error) { +func (c *Client) updateDpiApp(ctx context.Context, site string, d *DpiApp) (*DpiApp, error) { var respBody struct { Meta meta `json:"meta"` Data []DpiApp `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/dpiapp/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/dpiapp/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/dpi_group.generated.go b/unifi/dpi_group.generated.go index 68b0cb0..1089482 100644 --- a/unifi/dpi_group.generated.go +++ b/unifi/dpi_group.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type DpiGroup struct { ID string `json:"_id,omitempty"` @@ -24,13 +28,13 @@ type DpiGroup struct { Name string `json:"name,omitempty"` // .{1,128} } -func (c *Client) listDpiGroup(site string) ([]DpiGroup, error) { +func (c *Client) listDpiGroup(ctx context.Context, site string) ([]DpiGroup, error) { var respBody struct { Meta meta `json:"meta"` Data []DpiGroup `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/dpigroup", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/dpigroup", site), nil, &respBody) if err != nil { return nil, err } @@ -38,13 +42,13 @@ func (c *Client) listDpiGroup(site string) ([]DpiGroup, error) { return respBody.Data, nil } -func (c *Client) getDpiGroup(site, id string) (*DpiGroup, error) { +func (c *Client) getDpiGroup(ctx context.Context, site, id string) (*DpiGroup, error) { var respBody struct { Meta meta `json:"meta"` Data []DpiGroup `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/dpigroup/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/dpigroup/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -57,21 +61,21 @@ func (c *Client) getDpiGroup(site, id string) (*DpiGroup, error) { return &d, nil } -func (c *Client) deleteDpiGroup(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/dpigroup/%s", site, id), struct{}{}, nil) +func (c *Client) deleteDpiGroup(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/dpigroup/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createDpiGroup(site string, d *DpiGroup) (*DpiGroup, error) { +func (c *Client) createDpiGroup(ctx context.Context, site string, d *DpiGroup) (*DpiGroup, error) { var respBody struct { Meta meta `json:"meta"` Data []DpiGroup `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/dpigroup", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/dpigroup", site), d, &respBody) if err != nil { return nil, err } @@ -85,13 +89,13 @@ func (c *Client) createDpiGroup(site string, d *DpiGroup) (*DpiGroup, error) { return &new, nil } -func (c *Client) updateDpiGroup(site string, d *DpiGroup) (*DpiGroup, error) { +func (c *Client) updateDpiGroup(ctx context.Context, site string, d *DpiGroup) (*DpiGroup, error) { var respBody struct { Meta meta `json:"meta"` Data []DpiGroup `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/dpigroup/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/dpigroup/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/dynamic_dns.generated.go b/unifi/dynamic_dns.generated.go index d8523f0..a86e8cc 100644 --- a/unifi/dynamic_dns.generated.go +++ b/unifi/dynamic_dns.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type DynamicDNS struct { ID string `json:"_id,omitempty"` @@ -29,13 +33,13 @@ type DynamicDNS struct { XPassword string `json:"x_password,omitempty"` // ^[^"' ]+$ } -func (c *Client) listDynamicDNS(site string) ([]DynamicDNS, error) { +func (c *Client) listDynamicDNS(ctx context.Context, site string) ([]DynamicDNS, error) { var respBody struct { Meta meta `json:"meta"` Data []DynamicDNS `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/dynamicdns", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/dynamicdns", site), nil, &respBody) if err != nil { return nil, err } @@ -43,13 +47,13 @@ func (c *Client) listDynamicDNS(site string) ([]DynamicDNS, error) { return respBody.Data, nil } -func (c *Client) getDynamicDNS(site, id string) (*DynamicDNS, error) { +func (c *Client) getDynamicDNS(ctx context.Context, site, id string) (*DynamicDNS, error) { var respBody struct { Meta meta `json:"meta"` Data []DynamicDNS `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/dynamicdns/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/dynamicdns/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -62,21 +66,21 @@ func (c *Client) getDynamicDNS(site, id string) (*DynamicDNS, error) { return &d, nil } -func (c *Client) deleteDynamicDNS(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/dynamicdns/%s", site, id), struct{}{}, nil) +func (c *Client) deleteDynamicDNS(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/dynamicdns/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createDynamicDNS(site string, d *DynamicDNS) (*DynamicDNS, error) { +func (c *Client) createDynamicDNS(ctx context.Context, site string, d *DynamicDNS) (*DynamicDNS, error) { var respBody struct { Meta meta `json:"meta"` Data []DynamicDNS `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/dynamicdns", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/dynamicdns", site), d, &respBody) if err != nil { return nil, err } @@ -90,13 +94,13 @@ func (c *Client) createDynamicDNS(site string, d *DynamicDNS) (*DynamicDNS, erro return &new, nil } -func (c *Client) updateDynamicDNS(site string, d *DynamicDNS) (*DynamicDNS, error) { +func (c *Client) updateDynamicDNS(ctx context.Context, site string, d *DynamicDNS) (*DynamicDNS, error) { var respBody struct { Meta meta `json:"meta"` Data []DynamicDNS `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/dynamicdns/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/dynamicdns/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/firewall_group.generated.go b/unifi/firewall_group.generated.go index a104603..8f667c3 100644 --- a/unifi/firewall_group.generated.go +++ b/unifi/firewall_group.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type FirewallGroup struct { ID string `json:"_id,omitempty"` @@ -24,13 +28,13 @@ type FirewallGroup struct { Name string `json:"name,omitempty"` // .{1,64} } -func (c *Client) listFirewallGroup(site string) ([]FirewallGroup, error) { +func (c *Client) listFirewallGroup(ctx context.Context, site string) ([]FirewallGroup, error) { var respBody struct { Meta meta `json:"meta"` Data []FirewallGroup `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/firewallgroup", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/firewallgroup", site), nil, &respBody) if err != nil { return nil, err } @@ -38,13 +42,13 @@ func (c *Client) listFirewallGroup(site string) ([]FirewallGroup, error) { return respBody.Data, nil } -func (c *Client) getFirewallGroup(site, id string) (*FirewallGroup, error) { +func (c *Client) getFirewallGroup(ctx context.Context, site, id string) (*FirewallGroup, error) { var respBody struct { Meta meta `json:"meta"` Data []FirewallGroup `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/firewallgroup/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/firewallgroup/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -57,21 +61,21 @@ func (c *Client) getFirewallGroup(site, id string) (*FirewallGroup, error) { return &d, nil } -func (c *Client) deleteFirewallGroup(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/firewallgroup/%s", site, id), struct{}{}, nil) +func (c *Client) deleteFirewallGroup(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/firewallgroup/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createFirewallGroup(site string, d *FirewallGroup) (*FirewallGroup, error) { +func (c *Client) createFirewallGroup(ctx context.Context, site string, d *FirewallGroup) (*FirewallGroup, error) { var respBody struct { Meta meta `json:"meta"` Data []FirewallGroup `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/firewallgroup", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/firewallgroup", site), d, &respBody) if err != nil { return nil, err } @@ -85,13 +89,13 @@ func (c *Client) createFirewallGroup(site string, d *FirewallGroup) (*FirewallGr return &new, nil } -func (c *Client) updateFirewallGroup(site string, d *FirewallGroup) (*FirewallGroup, error) { +func (c *Client) updateFirewallGroup(ctx context.Context, site string, d *FirewallGroup) (*FirewallGroup, error) { var respBody struct { Meta meta `json:"meta"` Data []FirewallGroup `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/firewallgroup/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/firewallgroup/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/firewall_group.go b/unifi/firewall_group.go index 75a1a42..92459a8 100644 --- a/unifi/firewall_group.go +++ b/unifi/firewall_group.go @@ -1,21 +1,23 @@ package unifi -func (c *Client) ListFirewallGroup(site string) ([]FirewallGroup, error) { - return c.listFirewallGroup(site) +import "context" + +func (c *Client) ListFirewallGroup(ctx context.Context, site string) ([]FirewallGroup, error) { + return c.listFirewallGroup(ctx, site) } -func (c *Client) GetFirewallGroup(site, id string) (*FirewallGroup, error) { - return c.getFirewallGroup(site, id) +func (c *Client) GetFirewallGroup(ctx context.Context, site, id string) (*FirewallGroup, error) { + return c.getFirewallGroup(ctx, site, id) } -func (c *Client) DeleteFirewallGroup(site, id string) error { - return c.deleteFirewallGroup(site, id) +func (c *Client) DeleteFirewallGroup(ctx context.Context, site, id string) error { + return c.deleteFirewallGroup(ctx, site, id) } -func (c *Client) CreateFirewallGroup(site string, d *FirewallGroup) (*FirewallGroup, error) { - return c.createFirewallGroup(site, d) +func (c *Client) CreateFirewallGroup(ctx context.Context, site string, d *FirewallGroup) (*FirewallGroup, error) { + return c.createFirewallGroup(ctx, site, d) } -func (c *Client) UpdateFirewallGroup(site string, d *FirewallGroup) (*FirewallGroup, error) { - return c.updateFirewallGroup(site, d) +func (c *Client) UpdateFirewallGroup(ctx context.Context, site string, d *FirewallGroup) (*FirewallGroup, error) { + return c.updateFirewallGroup(ctx, site, d) } diff --git a/unifi/firewall_rule.generated.go b/unifi/firewall_rule.generated.go index 0257bb4..0a38509 100644 --- a/unifi/firewall_rule.generated.go +++ b/unifi/firewall_rule.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type FirewallRule struct { ID string `json:"_id,omitempty"` @@ -60,13 +64,13 @@ type FirewallRule struct { WeekdaysNegate bool `json:"weekdays_negate"` } -func (c *Client) listFirewallRule(site string) ([]FirewallRule, error) { +func (c *Client) listFirewallRule(ctx context.Context, site string) ([]FirewallRule, error) { var respBody struct { Meta meta `json:"meta"` Data []FirewallRule `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/firewallrule", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/firewallrule", site), nil, &respBody) if err != nil { return nil, err } @@ -74,13 +78,13 @@ func (c *Client) listFirewallRule(site string) ([]FirewallRule, error) { return respBody.Data, nil } -func (c *Client) getFirewallRule(site, id string) (*FirewallRule, error) { +func (c *Client) getFirewallRule(ctx context.Context, site, id string) (*FirewallRule, error) { var respBody struct { Meta meta `json:"meta"` Data []FirewallRule `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/firewallrule/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/firewallrule/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -93,21 +97,21 @@ func (c *Client) getFirewallRule(site, id string) (*FirewallRule, error) { return &d, nil } -func (c *Client) deleteFirewallRule(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/firewallrule/%s", site, id), struct{}{}, nil) +func (c *Client) deleteFirewallRule(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/firewallrule/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createFirewallRule(site string, d *FirewallRule) (*FirewallRule, error) { +func (c *Client) createFirewallRule(ctx context.Context, site string, d *FirewallRule) (*FirewallRule, error) { var respBody struct { Meta meta `json:"meta"` Data []FirewallRule `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/firewallrule", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/firewallrule", site), d, &respBody) if err != nil { return nil, err } @@ -121,13 +125,13 @@ func (c *Client) createFirewallRule(site string, d *FirewallRule) (*FirewallRule return &new, nil } -func (c *Client) updateFirewallRule(site string, d *FirewallRule) (*FirewallRule, error) { +func (c *Client) updateFirewallRule(ctx context.Context, site string, d *FirewallRule) (*FirewallRule, error) { var respBody struct { Meta meta `json:"meta"` Data []FirewallRule `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/firewallrule/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/firewallrule/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/firewall_rule.go b/unifi/firewall_rule.go index d0877a2..fc6e3cc 100644 --- a/unifi/firewall_rule.go +++ b/unifi/firewall_rule.go @@ -1,21 +1,23 @@ package unifi -func (c *Client) ListFirewallRule(site string) ([]FirewallRule, error) { - return c.listFirewallRule(site) +import "context" + +func (c *Client) ListFirewallRule(ctx context.Context, site string) ([]FirewallRule, error) { + return c.listFirewallRule(ctx, site) } -func (c *Client) GetFirewallRule(site, id string) (*FirewallRule, error) { - return c.getFirewallRule(site, id) +func (c *Client) GetFirewallRule(ctx context.Context, site, id string) (*FirewallRule, error) { + return c.getFirewallRule(ctx, site, id) } -func (c *Client) DeleteFirewallRule(site, id string) error { - return c.deleteFirewallRule(site, id) +func (c *Client) DeleteFirewallRule(ctx context.Context, site, id string) error { + return c.deleteFirewallRule(ctx, site, id) } -func (c *Client) CreateFirewallRule(site string, d *FirewallRule) (*FirewallRule, error) { - return c.createFirewallRule(site, d) +func (c *Client) CreateFirewallRule(ctx context.Context, site string, d *FirewallRule) (*FirewallRule, error) { + return c.createFirewallRule(ctx, site, d) } -func (c *Client) UpdateFirewallRule(site string, d *FirewallRule) (*FirewallRule, error) { - return c.updateFirewallRule(site, d) +func (c *Client) UpdateFirewallRule(ctx context.Context, site string, d *FirewallRule) (*FirewallRule, error) { + return c.updateFirewallRule(ctx, site, d) } diff --git a/unifi/heat_map.generated.go b/unifi/heat_map.generated.go index 4949dd4..4367643 100644 --- a/unifi/heat_map.generated.go +++ b/unifi/heat_map.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type HeatMap struct { ID string `json:"_id,omitempty"` @@ -25,13 +29,13 @@ type HeatMap struct { Type string `json:"type,omitempty"` // download|upload } -func (c *Client) listHeatMap(site string) ([]HeatMap, error) { +func (c *Client) listHeatMap(ctx context.Context, site string) ([]HeatMap, error) { var respBody struct { Meta meta `json:"meta"` Data []HeatMap `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/heatmap", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/heatmap", site), nil, &respBody) if err != nil { return nil, err } @@ -39,13 +43,13 @@ func (c *Client) listHeatMap(site string) ([]HeatMap, error) { return respBody.Data, nil } -func (c *Client) getHeatMap(site, id string) (*HeatMap, error) { +func (c *Client) getHeatMap(ctx context.Context, site, id string) (*HeatMap, error) { var respBody struct { Meta meta `json:"meta"` Data []HeatMap `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/heatmap/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/heatmap/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -58,21 +62,21 @@ func (c *Client) getHeatMap(site, id string) (*HeatMap, error) { return &d, nil } -func (c *Client) deleteHeatMap(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/heatmap/%s", site, id), struct{}{}, nil) +func (c *Client) deleteHeatMap(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/heatmap/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createHeatMap(site string, d *HeatMap) (*HeatMap, error) { +func (c *Client) createHeatMap(ctx context.Context, site string, d *HeatMap) (*HeatMap, error) { var respBody struct { Meta meta `json:"meta"` Data []HeatMap `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/heatmap", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/heatmap", site), d, &respBody) if err != nil { return nil, err } @@ -86,13 +90,13 @@ func (c *Client) createHeatMap(site string, d *HeatMap) (*HeatMap, error) { return &new, nil } -func (c *Client) updateHeatMap(site string, d *HeatMap) (*HeatMap, error) { +func (c *Client) updateHeatMap(ctx context.Context, site string, d *HeatMap) (*HeatMap, error) { var respBody struct { Meta meta `json:"meta"` Data []HeatMap `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/heatmap/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/heatmap/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/heat_map_point.generated.go b/unifi/heat_map_point.generated.go index 666a0c0..ca130ba 100644 --- a/unifi/heat_map_point.generated.go +++ b/unifi/heat_map_point.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type HeatMapPoint struct { ID string `json:"_id,omitempty"` @@ -26,13 +30,13 @@ type HeatMapPoint struct { Y float64 `json:"y,omitempty"` } -func (c *Client) listHeatMapPoint(site string) ([]HeatMapPoint, error) { +func (c *Client) listHeatMapPoint(ctx context.Context, site string) ([]HeatMapPoint, error) { var respBody struct { Meta meta `json:"meta"` Data []HeatMapPoint `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/heatmappoint", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/heatmappoint", site), nil, &respBody) if err != nil { return nil, err } @@ -40,13 +44,13 @@ func (c *Client) listHeatMapPoint(site string) ([]HeatMapPoint, error) { return respBody.Data, nil } -func (c *Client) getHeatMapPoint(site, id string) (*HeatMapPoint, error) { +func (c *Client) getHeatMapPoint(ctx context.Context, site, id string) (*HeatMapPoint, error) { var respBody struct { Meta meta `json:"meta"` Data []HeatMapPoint `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/heatmappoint/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/heatmappoint/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -59,21 +63,21 @@ func (c *Client) getHeatMapPoint(site, id string) (*HeatMapPoint, error) { return &d, nil } -func (c *Client) deleteHeatMapPoint(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/heatmappoint/%s", site, id), struct{}{}, nil) +func (c *Client) deleteHeatMapPoint(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/heatmappoint/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createHeatMapPoint(site string, d *HeatMapPoint) (*HeatMapPoint, error) { +func (c *Client) createHeatMapPoint(ctx context.Context, site string, d *HeatMapPoint) (*HeatMapPoint, error) { var respBody struct { Meta meta `json:"meta"` Data []HeatMapPoint `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/heatmappoint", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/heatmappoint", site), d, &respBody) if err != nil { return nil, err } @@ -87,13 +91,13 @@ func (c *Client) createHeatMapPoint(site string, d *HeatMapPoint) (*HeatMapPoint return &new, nil } -func (c *Client) updateHeatMapPoint(site string, d *HeatMapPoint) (*HeatMapPoint, error) { +func (c *Client) updateHeatMapPoint(ctx context.Context, site string, d *HeatMapPoint) (*HeatMapPoint, error) { var respBody struct { Meta meta `json:"meta"` Data []HeatMapPoint `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/heatmappoint/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/heatmappoint/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/hotspot_op.generated.go b/unifi/hotspot_op.generated.go index 50fa991..f3236e3 100644 --- a/unifi/hotspot_op.generated.go +++ b/unifi/hotspot_op.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type HotspotOp struct { ID string `json:"_id,omitempty"` @@ -24,13 +28,13 @@ type HotspotOp struct { XPassword string `json:"x_password,omitempty"` // .{1,256} } -func (c *Client) listHotspotOp(site string) ([]HotspotOp, error) { +func (c *Client) listHotspotOp(ctx context.Context, site string) ([]HotspotOp, error) { var respBody struct { Meta meta `json:"meta"` Data []HotspotOp `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/hotspotop", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/hotspotop", site), nil, &respBody) if err != nil { return nil, err } @@ -38,13 +42,13 @@ func (c *Client) listHotspotOp(site string) ([]HotspotOp, error) { return respBody.Data, nil } -func (c *Client) getHotspotOp(site, id string) (*HotspotOp, error) { +func (c *Client) getHotspotOp(ctx context.Context, site, id string) (*HotspotOp, error) { var respBody struct { Meta meta `json:"meta"` Data []HotspotOp `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/hotspotop/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/hotspotop/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -57,21 +61,21 @@ func (c *Client) getHotspotOp(site, id string) (*HotspotOp, error) { return &d, nil } -func (c *Client) deleteHotspotOp(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/hotspotop/%s", site, id), struct{}{}, nil) +func (c *Client) deleteHotspotOp(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/hotspotop/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createHotspotOp(site string, d *HotspotOp) (*HotspotOp, error) { +func (c *Client) createHotspotOp(ctx context.Context, site string, d *HotspotOp) (*HotspotOp, error) { var respBody struct { Meta meta `json:"meta"` Data []HotspotOp `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/hotspotop", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/hotspotop", site), d, &respBody) if err != nil { return nil, err } @@ -85,13 +89,13 @@ func (c *Client) createHotspotOp(site string, d *HotspotOp) (*HotspotOp, error) return &new, nil } -func (c *Client) updateHotspotOp(site string, d *HotspotOp) (*HotspotOp, error) { +func (c *Client) updateHotspotOp(ctx context.Context, site string, d *HotspotOp) (*HotspotOp, error) { var respBody struct { Meta meta `json:"meta"` Data []HotspotOp `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/hotspotop/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/hotspotop/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/hotspot_package.generated.go b/unifi/hotspot_package.generated.go index 01c6209..d5cdd35 100644 --- a/unifi/hotspot_package.generated.go +++ b/unifi/hotspot_package.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type HotspotPackage struct { ID string `json:"_id,omitempty"` @@ -50,13 +54,13 @@ type HotspotPackage struct { TrialReset float64 `json:"trial_reset,omitempty"` } -func (c *Client) listHotspotPackage(site string) ([]HotspotPackage, error) { +func (c *Client) listHotspotPackage(ctx context.Context, site string) ([]HotspotPackage, error) { var respBody struct { Meta meta `json:"meta"` Data []HotspotPackage `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/hotspotpackage", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/hotspotpackage", site), nil, &respBody) if err != nil { return nil, err } @@ -64,13 +68,13 @@ func (c *Client) listHotspotPackage(site string) ([]HotspotPackage, error) { return respBody.Data, nil } -func (c *Client) getHotspotPackage(site, id string) (*HotspotPackage, error) { +func (c *Client) getHotspotPackage(ctx context.Context, site, id string) (*HotspotPackage, error) { var respBody struct { Meta meta `json:"meta"` Data []HotspotPackage `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/hotspotpackage/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/hotspotpackage/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -83,21 +87,21 @@ func (c *Client) getHotspotPackage(site, id string) (*HotspotPackage, error) { return &d, nil } -func (c *Client) deleteHotspotPackage(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/hotspotpackage/%s", site, id), struct{}{}, nil) +func (c *Client) deleteHotspotPackage(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/hotspotpackage/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createHotspotPackage(site string, d *HotspotPackage) (*HotspotPackage, error) { +func (c *Client) createHotspotPackage(ctx context.Context, site string, d *HotspotPackage) (*HotspotPackage, error) { var respBody struct { Meta meta `json:"meta"` Data []HotspotPackage `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/hotspotpackage", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/hotspotpackage", site), d, &respBody) if err != nil { return nil, err } @@ -111,13 +115,13 @@ func (c *Client) createHotspotPackage(site string, d *HotspotPackage) (*HotspotP return &new, nil } -func (c *Client) updateHotspotPackage(site string, d *HotspotPackage) (*HotspotPackage, error) { +func (c *Client) updateHotspotPackage(ctx context.Context, site string, d *HotspotPackage) (*HotspotPackage, error) { var respBody struct { Meta meta `json:"meta"` Data []HotspotPackage `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/hotspotpackage/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/hotspotpackage/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/map.generated.go b/unifi/map.generated.go index 401eee6..ba02405 100644 --- a/unifi/map.generated.go +++ b/unifi/map.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type Map struct { ID string `json:"_id,omitempty"` @@ -34,13 +38,13 @@ type Map struct { Zoom int `json:"zoom,omitempty"` } -func (c *Client) listMap(site string) ([]Map, error) { +func (c *Client) listMap(ctx context.Context, site string) ([]Map, error) { var respBody struct { Meta meta `json:"meta"` Data []Map `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/map", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/map", site), nil, &respBody) if err != nil { return nil, err } @@ -48,13 +52,13 @@ func (c *Client) listMap(site string) ([]Map, error) { return respBody.Data, nil } -func (c *Client) getMap(site, id string) (*Map, error) { +func (c *Client) getMap(ctx context.Context, site, id string) (*Map, error) { var respBody struct { Meta meta `json:"meta"` Data []Map `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/map/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/map/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -67,21 +71,21 @@ func (c *Client) getMap(site, id string) (*Map, error) { return &d, nil } -func (c *Client) deleteMap(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/map/%s", site, id), struct{}{}, nil) +func (c *Client) deleteMap(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/map/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createMap(site string, d *Map) (*Map, error) { +func (c *Client) createMap(ctx context.Context, site string, d *Map) (*Map, error) { var respBody struct { Meta meta `json:"meta"` Data []Map `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/map", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/map", site), d, &respBody) if err != nil { return nil, err } @@ -95,13 +99,13 @@ func (c *Client) createMap(site string, d *Map) (*Map, error) { return &new, nil } -func (c *Client) updateMap(site string, d *Map) (*Map, error) { +func (c *Client) updateMap(ctx context.Context, site string, d *Map) (*Map, error) { var respBody struct { Meta meta `json:"meta"` Data []Map `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/map/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/map/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/media_file.generated.go b/unifi/media_file.generated.go index 77a67c4..c2ad8a5 100644 --- a/unifi/media_file.generated.go +++ b/unifi/media_file.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type MediaFile struct { ID string `json:"_id,omitempty"` @@ -22,13 +26,13 @@ type MediaFile struct { Name string `json:"name,omitempty"` } -func (c *Client) listMediaFile(site string) ([]MediaFile, error) { +func (c *Client) listMediaFile(ctx context.Context, site string) ([]MediaFile, error) { var respBody struct { Meta meta `json:"meta"` Data []MediaFile `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/mediafile", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/mediafile", site), nil, &respBody) if err != nil { return nil, err } @@ -36,13 +40,13 @@ func (c *Client) listMediaFile(site string) ([]MediaFile, error) { return respBody.Data, nil } -func (c *Client) getMediaFile(site, id string) (*MediaFile, error) { +func (c *Client) getMediaFile(ctx context.Context, site, id string) (*MediaFile, error) { var respBody struct { Meta meta `json:"meta"` Data []MediaFile `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/mediafile/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/mediafile/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -55,21 +59,21 @@ func (c *Client) getMediaFile(site, id string) (*MediaFile, error) { return &d, nil } -func (c *Client) deleteMediaFile(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/mediafile/%s", site, id), struct{}{}, nil) +func (c *Client) deleteMediaFile(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/mediafile/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createMediaFile(site string, d *MediaFile) (*MediaFile, error) { +func (c *Client) createMediaFile(ctx context.Context, site string, d *MediaFile) (*MediaFile, error) { var respBody struct { Meta meta `json:"meta"` Data []MediaFile `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/mediafile", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/mediafile", site), d, &respBody) if err != nil { return nil, err } @@ -83,13 +87,13 @@ func (c *Client) createMediaFile(site string, d *MediaFile) (*MediaFile, error) return &new, nil } -func (c *Client) updateMediaFile(site string, d *MediaFile) (*MediaFile, error) { +func (c *Client) updateMediaFile(ctx context.Context, site string, d *MediaFile) (*MediaFile, error) { var respBody struct { Meta meta `json:"meta"` Data []MediaFile `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/mediafile/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/mediafile/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/network.generated.go b/unifi/network.generated.go index 8dc4d3e..482e66d 100644 --- a/unifi/network.generated.go +++ b/unifi/network.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type Network struct { ID string `json:"_id,omitempty"` @@ -157,13 +161,13 @@ type Network struct { XWANPassword string `json:"x_wan_password,omitempty"` // [^"' ]+ } -func (c *Client) listNetwork(site string) ([]Network, error) { +func (c *Client) listNetwork(ctx context.Context, site string) ([]Network, error) { var respBody struct { Meta meta `json:"meta"` Data []Network `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/networkconf", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/networkconf", site), nil, &respBody) if err != nil { return nil, err } @@ -171,13 +175,13 @@ func (c *Client) listNetwork(site string) ([]Network, error) { return respBody.Data, nil } -func (c *Client) getNetwork(site, id string) (*Network, error) { +func (c *Client) getNetwork(ctx context.Context, site, id string) (*Network, error) { var respBody struct { Meta meta `json:"meta"` Data []Network `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/networkconf/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/networkconf/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -190,21 +194,21 @@ func (c *Client) getNetwork(site, id string) (*Network, error) { return &d, nil } -func (c *Client) deleteNetwork(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/networkconf/%s", site, id), struct{}{}, nil) +func (c *Client) deleteNetwork(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/networkconf/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createNetwork(site string, d *Network) (*Network, error) { +func (c *Client) createNetwork(ctx context.Context, site string, d *Network) (*Network, error) { var respBody struct { Meta meta `json:"meta"` Data []Network `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/networkconf", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/networkconf", site), d, &respBody) if err != nil { return nil, err } @@ -218,13 +222,13 @@ func (c *Client) createNetwork(site string, d *Network) (*Network, error) { return &new, nil } -func (c *Client) updateNetwork(site string, d *Network) (*Network, error) { +func (c *Client) updateNetwork(ctx context.Context, site string, d *Network) (*Network, error) { var respBody struct { Meta meta `json:"meta"` Data []Network `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/networkconf/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/networkconf/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/network.go b/unifi/network.go index 8cb6825..4cbbbbc 100644 --- a/unifi/network.go +++ b/unifi/network.go @@ -1,6 +1,7 @@ package unifi import ( + "context" "encoding/json" "fmt" ) @@ -41,8 +42,8 @@ func (dst *Network) UnmarshalJSON(b []byte) error { return nil } -func (c *Client) DeleteNetwork(site, id, name string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/networkconf/%s", site, id), struct { +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"` }{ Name: name, @@ -53,18 +54,18 @@ func (c *Client) DeleteNetwork(site, id, name string) error { return nil } -func (c *Client) ListNetwork(site string) ([]Network, error) { - return c.listNetwork(site) +func (c *Client) ListNetwork(ctx context.Context, site string) ([]Network, error) { + return c.listNetwork(ctx, site) } -func (c *Client) GetNetwork(site, id string) (*Network, error) { - return c.getNetwork(site, id) +func (c *Client) GetNetwork(ctx context.Context, site, id string) (*Network, error) { + return c.getNetwork(ctx, site, id) } -func (c *Client) CreateNetwork(site string, d *Network) (*Network, error) { - return c.createNetwork(site, d) +func (c *Client) CreateNetwork(ctx context.Context, site string, d *Network) (*Network, error) { + return c.createNetwork(ctx, site, d) } -func (c *Client) UpdateNetwork(site string, d *Network) (*Network, error) { - return c.updateNetwork(site, d) +func (c *Client) UpdateNetwork(ctx context.Context, site string, d *Network) (*Network, error) { + return c.updateNetwork(ctx, site, d) } diff --git a/unifi/port_conf.generated.go b/unifi/port_conf.generated.go index 54489e9..86af138 100644 --- a/unifi/port_conf.generated.go +++ b/unifi/port_conf.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type PortConf struct { ID string `json:"_id,omitempty"` @@ -54,13 +58,13 @@ type PortConf struct { VoiceNetworkID string `json:"voice_networkconf_id"` } -func (c *Client) listPortConf(site string) ([]PortConf, error) { +func (c *Client) listPortConf(ctx context.Context, site string) ([]PortConf, error) { var respBody struct { Meta meta `json:"meta"` Data []PortConf `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/portconf", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/portconf", site), nil, &respBody) if err != nil { return nil, err } @@ -68,13 +72,13 @@ func (c *Client) listPortConf(site string) ([]PortConf, error) { return respBody.Data, nil } -func (c *Client) getPortConf(site, id string) (*PortConf, error) { +func (c *Client) getPortConf(ctx context.Context, site, id string) (*PortConf, error) { var respBody struct { Meta meta `json:"meta"` Data []PortConf `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/portconf/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/portconf/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -87,21 +91,21 @@ func (c *Client) getPortConf(site, id string) (*PortConf, error) { return &d, nil } -func (c *Client) deletePortConf(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/portconf/%s", site, id), struct{}{}, nil) +func (c *Client) deletePortConf(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/portconf/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createPortConf(site string, d *PortConf) (*PortConf, error) { +func (c *Client) createPortConf(ctx context.Context, site string, d *PortConf) (*PortConf, error) { var respBody struct { Meta meta `json:"meta"` Data []PortConf `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/portconf", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/portconf", site), d, &respBody) if err != nil { return nil, err } @@ -115,13 +119,13 @@ func (c *Client) createPortConf(site string, d *PortConf) (*PortConf, error) { return &new, nil } -func (c *Client) updatePortConf(site string, d *PortConf) (*PortConf, error) { +func (c *Client) updatePortConf(ctx context.Context, site string, d *PortConf) (*PortConf, error) { var respBody struct { Meta meta `json:"meta"` Data []PortConf `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/portconf/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/portconf/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/port_forward.generated.go b/unifi/port_forward.generated.go index f761365..7ef210c 100644 --- a/unifi/port_forward.generated.go +++ b/unifi/port_forward.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type PortForward struct { ID string `json:"_id,omitempty"` @@ -30,13 +34,13 @@ 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 (c *Client) listPortForward(site string) ([]PortForward, error) { +func (c *Client) listPortForward(ctx context.Context, site string) ([]PortForward, error) { var respBody struct { Meta meta `json:"meta"` Data []PortForward `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/portforward", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/portforward", site), nil, &respBody) if err != nil { return nil, err } @@ -44,13 +48,13 @@ func (c *Client) listPortForward(site string) ([]PortForward, error) { return respBody.Data, nil } -func (c *Client) getPortForward(site, id string) (*PortForward, error) { +func (c *Client) getPortForward(ctx context.Context, site, id string) (*PortForward, error) { var respBody struct { Meta meta `json:"meta"` Data []PortForward `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/portforward/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/portforward/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -63,21 +67,21 @@ func (c *Client) getPortForward(site, id string) (*PortForward, error) { return &d, nil } -func (c *Client) deletePortForward(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/portforward/%s", site, id), struct{}{}, nil) +func (c *Client) deletePortForward(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/portforward/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createPortForward(site string, d *PortForward) (*PortForward, error) { +func (c *Client) createPortForward(ctx context.Context, site string, d *PortForward) (*PortForward, error) { var respBody struct { Meta meta `json:"meta"` Data []PortForward `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/portforward", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/portforward", site), d, &respBody) if err != nil { return nil, err } @@ -91,13 +95,13 @@ func (c *Client) createPortForward(site string, d *PortForward) (*PortForward, e return &new, nil } -func (c *Client) updatePortForward(site string, d *PortForward) (*PortForward, error) { +func (c *Client) updatePortForward(ctx context.Context, site string, d *PortForward) (*PortForward, error) { var respBody struct { Meta meta `json:"meta"` Data []PortForward `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/portforward/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/portforward/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/port_forward.go b/unifi/port_forward.go index c2c5b3f..05144e0 100644 --- a/unifi/port_forward.go +++ b/unifi/port_forward.go @@ -1,21 +1,23 @@ package unifi -func (c *Client) ListPortForward(site string) ([]PortForward, error) { - return c.listPortForward(site) +import "context" + +func (c *Client) ListPortForward(ctx context.Context, site string) ([]PortForward, error) { + return c.listPortForward(ctx, site) } -func (c *Client) GetPortForward(site, id string) (*PortForward, error) { - return c.getPortForward(site, id) +func (c *Client) GetPortForward(ctx context.Context, site, id string) (*PortForward, error) { + return c.getPortForward(ctx, site, id) } -func (c *Client) DeletePortForward(site, id string) error { - return c.deletePortForward(site, id) +func (c *Client) DeletePortForward(ctx context.Context, site, id string) error { + return c.deletePortForward(ctx, site, id) } -func (c *Client) CreatePortForward(site string, d *PortForward) (*PortForward, error) { - return c.createPortForward(site, d) +func (c *Client) CreatePortForward(ctx context.Context, site string, d *PortForward) (*PortForward, error) { + return c.createPortForward(ctx, site, d) } -func (c *Client) UpdatePortForward(site string, d *PortForward) (*PortForward, error) { - return c.updatePortForward(site, d) +func (c *Client) UpdatePortForward(ctx context.Context, site string, d *PortForward) (*PortForward, error) { + return c.updatePortForward(ctx, site, d) } diff --git a/unifi/routing.generated.go b/unifi/routing.generated.go index 98b5f31..f779758 100644 --- a/unifi/routing.generated.go +++ b/unifi/routing.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type Routing struct { ID string `json:"_id,omitempty"` @@ -29,13 +33,13 @@ type Routing struct { Type string `json:"type,omitempty"` // static-route } -func (c *Client) listRouting(site string) ([]Routing, error) { +func (c *Client) listRouting(ctx context.Context, site string) ([]Routing, error) { var respBody struct { Meta meta `json:"meta"` Data []Routing `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/routing", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/routing", site), nil, &respBody) if err != nil { return nil, err } @@ -43,13 +47,13 @@ func (c *Client) listRouting(site string) ([]Routing, error) { return respBody.Data, nil } -func (c *Client) getRouting(site, id string) (*Routing, error) { +func (c *Client) getRouting(ctx context.Context, site, id string) (*Routing, error) { var respBody struct { Meta meta `json:"meta"` Data []Routing `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/routing/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/routing/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -62,21 +66,21 @@ func (c *Client) getRouting(site, id string) (*Routing, error) { return &d, nil } -func (c *Client) deleteRouting(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/routing/%s", site, id), struct{}{}, nil) +func (c *Client) deleteRouting(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/routing/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createRouting(site string, d *Routing) (*Routing, error) { +func (c *Client) createRouting(ctx context.Context, site string, d *Routing) (*Routing, error) { var respBody struct { Meta meta `json:"meta"` Data []Routing `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/routing", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/routing", site), d, &respBody) if err != nil { return nil, err } @@ -90,13 +94,13 @@ func (c *Client) createRouting(site string, d *Routing) (*Routing, error) { return &new, nil } -func (c *Client) updateRouting(site string, d *Routing) (*Routing, error) { +func (c *Client) updateRouting(ctx context.Context, site string, d *Routing) (*Routing, error) { var respBody struct { Meta meta `json:"meta"` Data []Routing `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/routing/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/routing/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/setting.go b/unifi/setting.go index cbfdb92..0c89e1f 100644 --- a/unifi/setting.go +++ b/unifi/setting.go @@ -1,8 +1,10 @@ package unifi -import "fmt" - -import "encoding/json" +import ( + "context" + "encoding/json" + "fmt" +) type Setting struct { ID string `json:"_id,omitempty"` @@ -77,13 +79,13 @@ func (s *Setting) newFields() (interface{}, error) { return nil, fmt.Errorf("unexpected key %q", s.Key) } -func (c *Client) GetSetting(site, key string) (*Setting, interface{}, error) { +func (c *Client) GetSetting(ctx context.Context, site, key string) (*Setting, interface{}, error) { var respBody struct { Meta meta `json:"meta"` Data []json.RawMessage `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/get/setting", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting", site), nil, &respBody) if err != nil { return nil, nil, err } diff --git a/unifi/setting_auto_speedtest.generated.go b/unifi/setting_auto_speedtest.generated.go index 77c6e7c..60fc5a0 100644 --- a/unifi/setting_auto_speedtest.generated.go +++ b/unifi/setting_auto_speedtest.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingAutoSpeedtest struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_baresip.generated.go b/unifi/setting_baresip.generated.go index 05528ee..30f2bb5 100644 --- a/unifi/setting_baresip.generated.go +++ b/unifi/setting_baresip.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingBaresip struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_broadcast.generated.go b/unifi/setting_broadcast.generated.go index a5b526d..d086ab4 100644 --- a/unifi/setting_broadcast.generated.go +++ b/unifi/setting_broadcast.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingBroadcast struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_connectivity.generated.go b/unifi/setting_connectivity.generated.go index bf32d65..28b781e 100644 --- a/unifi/setting_connectivity.generated.go +++ b/unifi/setting_connectivity.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingConnectivity struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_country.generated.go b/unifi/setting_country.generated.go index b4d6b0a..31b4ea4 100644 --- a/unifi/setting_country.generated.go +++ b/unifi/setting_country.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingCountry struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_dpi.generated.go b/unifi/setting_dpi.generated.go index 23a5c3e..3493b02 100644 --- a/unifi/setting_dpi.generated.go +++ b/unifi/setting_dpi.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingDpi struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_element_adopt.generated.go b/unifi/setting_element_adopt.generated.go index ddccbae..bb083dd 100644 --- a/unifi/setting_element_adopt.generated.go +++ b/unifi/setting_element_adopt.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingElementAdopt struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_guest_access.generated.go b/unifi/setting_guest_access.generated.go index cce779b..abc1161 100644 --- a/unifi/setting_guest_access.generated.go +++ b/unifi/setting_guest_access.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingGuestAccess struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_lcm.generated.go b/unifi/setting_lcm.generated.go index 3b0a9e7..361b743 100644 --- a/unifi/setting_lcm.generated.go +++ b/unifi/setting_lcm.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingLcm struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_locale.generated.go b/unifi/setting_locale.generated.go index b6aafbb..40c9030 100644 --- a/unifi/setting_locale.generated.go +++ b/unifi/setting_locale.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingLocale struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_mgmt.generated.go b/unifi/setting_mgmt.generated.go index 0360da5..a7598a7 100644 --- a/unifi/setting_mgmt.generated.go +++ b/unifi/setting_mgmt.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingMgmt struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_network_optimization.generated.go b/unifi/setting_network_optimization.generated.go index 15fcae0..b9a6172 100644 --- a/unifi/setting_network_optimization.generated.go +++ b/unifi/setting_network_optimization.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingNetworkOptimization struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_ntp.generated.go b/unifi/setting_ntp.generated.go index 7a64d0f..346c74c 100644 --- a/unifi/setting_ntp.generated.go +++ b/unifi/setting_ntp.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingNtp struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_porta.generated.go b/unifi/setting_porta.generated.go index 1a1cc58..a4b782f 100644 --- a/unifi/setting_porta.generated.go +++ b/unifi/setting_porta.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingPorta struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_provider_capabilities.generated.go b/unifi/setting_provider_capabilities.generated.go index 469c0d6..bf722f7 100644 --- a/unifi/setting_provider_capabilities.generated.go +++ b/unifi/setting_provider_capabilities.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingProviderCapabilities struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_radio_ai.generated.go b/unifi/setting_radio_ai.generated.go index 3936f03..b54b2b3 100644 --- a/unifi/setting_radio_ai.generated.go +++ b/unifi/setting_radio_ai.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingRadioAi struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_radius.generated.go b/unifi/setting_radius.generated.go index 61e95d6..4a36556 100644 --- a/unifi/setting_radius.generated.go +++ b/unifi/setting_radius.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingRadius struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_rsyslogd.generated.go b/unifi/setting_rsyslogd.generated.go index d8dd065..15d05b9 100644 --- a/unifi/setting_rsyslogd.generated.go +++ b/unifi/setting_rsyslogd.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingRsyslogd struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_snmp.generated.go b/unifi/setting_snmp.generated.go index 3ee0486..0e07347 100644 --- a/unifi/setting_snmp.generated.go +++ b/unifi/setting_snmp.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingSnmp struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_super_cloudaccess.generated.go b/unifi/setting_super_cloudaccess.generated.go index c71c070..1e03b29 100644 --- a/unifi/setting_super_cloudaccess.generated.go +++ b/unifi/setting_super_cloudaccess.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingSuperCloudaccess struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_super_events.generated.go b/unifi/setting_super_events.generated.go index d7a0923..c218de2 100644 --- a/unifi/setting_super_events.generated.go +++ b/unifi/setting_super_events.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingSuperEvents struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_super_fwupdate.generated.go b/unifi/setting_super_fwupdate.generated.go index b0da6e7..80a9ccc 100644 --- a/unifi/setting_super_fwupdate.generated.go +++ b/unifi/setting_super_fwupdate.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingSuperFwupdate struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_super_identity.generated.go b/unifi/setting_super_identity.generated.go index c4daec5..8d26885 100644 --- a/unifi/setting_super_identity.generated.go +++ b/unifi/setting_super_identity.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingSuperIdentity struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_super_mail.generated.go b/unifi/setting_super_mail.generated.go index 657b375..f264313 100644 --- a/unifi/setting_super_mail.generated.go +++ b/unifi/setting_super_mail.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingSuperMail struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_super_mgmt.generated.go b/unifi/setting_super_mgmt.generated.go index 0250816..a34116f 100644 --- a/unifi/setting_super_mgmt.generated.go +++ b/unifi/setting_super_mgmt.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingSuperMgmt struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_super_sdn.generated.go b/unifi/setting_super_sdn.generated.go index 2c78004..7bce123 100644 --- a/unifi/setting_super_sdn.generated.go +++ b/unifi/setting_super_sdn.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingSuperSdn struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_super_smtp.generated.go b/unifi/setting_super_smtp.generated.go index 50585f5..8ebfa04 100644 --- a/unifi/setting_super_smtp.generated.go +++ b/unifi/setting_super_smtp.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingSuperSmtp struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_usg.generated.go b/unifi/setting_usg.generated.go index 97fd539..65358e1 100644 --- a/unifi/setting_usg.generated.go +++ b/unifi/setting_usg.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingUsg struct { ID string `json:"_id,omitempty"` diff --git a/unifi/setting_usw.generated.go b/unifi/setting_usw.generated.go index c757d2d..dbe0646 100644 --- a/unifi/setting_usw.generated.go +++ b/unifi/setting_usw.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type SettingUsw struct { ID string `json:"_id,omitempty"` diff --git a/unifi/sites.go b/unifi/sites.go index 226f6b0..acdc41a 100644 --- a/unifi/sites.go +++ b/unifi/sites.go @@ -1,5 +1,7 @@ package unifi +import "context" + type Site struct { ID string `json:"_id,omitempty"` @@ -14,13 +16,13 @@ type Site struct { //Role string `json:"role"` } -func (c *Client) ListSites() ([]Site, error) { +func (c *Client) ListSites(ctx context.Context) ([]Site, error) { var respBody struct { Meta meta `json:"meta"` Data []Site `json:"data"` } - err := c.do("GET", "self/sites", nil, &respBody) + err := c.do(ctx, "GET", "self/sites", nil, &respBody) if err != nil { return nil, err } diff --git a/unifi/tag.generated.go b/unifi/tag.generated.go index 58306fc..e42523c 100644 --- a/unifi/tag.generated.go +++ b/unifi/tag.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type Tag struct { ID string `json:"_id,omitempty"` @@ -23,13 +27,13 @@ type Tag struct { Name string `json:"name,omitempty"` } -func (c *Client) listTag(site string) ([]Tag, error) { +func (c *Client) listTag(ctx context.Context, site string) ([]Tag, error) { var respBody struct { Meta meta `json:"meta"` Data []Tag `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/tag", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/tag", site), nil, &respBody) if err != nil { return nil, err } @@ -37,13 +41,13 @@ func (c *Client) listTag(site string) ([]Tag, error) { return respBody.Data, nil } -func (c *Client) getTag(site, id string) (*Tag, error) { +func (c *Client) getTag(ctx context.Context, site, id string) (*Tag, error) { var respBody struct { Meta meta `json:"meta"` Data []Tag `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/tag/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/tag/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -56,21 +60,21 @@ func (c *Client) getTag(site, id string) (*Tag, error) { return &d, nil } -func (c *Client) deleteTag(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/tag/%s", site, id), struct{}{}, nil) +func (c *Client) deleteTag(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/tag/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createTag(site string, d *Tag) (*Tag, error) { +func (c *Client) createTag(ctx context.Context, site string, d *Tag) (*Tag, error) { var respBody struct { Meta meta `json:"meta"` Data []Tag `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/tag", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/tag", site), d, &respBody) if err != nil { return nil, err } @@ -84,13 +88,13 @@ func (c *Client) createTag(site string, d *Tag) (*Tag, error) { return &new, nil } -func (c *Client) updateTag(site string, d *Tag) (*Tag, error) { +func (c *Client) updateTag(ctx context.Context, site string, d *Tag) (*Tag, error) { var respBody struct { Meta meta `json:"meta"` Data []Tag `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/tag/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/tag/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/unifi.go b/unifi/unifi.go index a018a30..7e4a13b 100644 --- a/unifi/unifi.go +++ b/unifi/unifi.go @@ -2,6 +2,7 @@ package unifi // import ( "bytes" + "context" "encoding/json" "fmt" "io" @@ -44,7 +45,7 @@ func (c *Client) SetHTTPClient(hc *http.Client) error { return nil } -func (c *Client) Login(user, pass string) error { +func (c *Client) Login(ctx context.Context, user, pass string) error { if c.c == nil { c.c = &http.Client{} @@ -52,7 +53,7 @@ func (c *Client) Login(user, pass string) error { c.c.Jar = jar } - err := c.do("POST", "login", &struct { + err := c.do(ctx, "POST", "login", &struct { Username string `json:"username"` Password string `json:"password"` }{ @@ -66,7 +67,7 @@ func (c *Client) Login(user, pass string) error { return nil } -func (c *Client) do(method, relativeURL string, reqBody interface{}, respBody interface{}) error { +func (c *Client) do(ctx context.Context, method, relativeURL string, reqBody interface{}, respBody interface{}) error { var ( reqReader io.Reader err error @@ -88,7 +89,7 @@ func (c *Client) do(method, relativeURL string, reqBody interface{}, respBody in url := c.baseURL.ResolveReference(reqURL) - req, err := http.NewRequest(method, url.String(), reqReader) + req, err := http.NewRequestWithContext(ctx, method, url.String(), reqReader) if err != nil { return err } diff --git a/unifi/user.generated.go b/unifi/user.generated.go index 43e2be5..67580d1 100644 --- a/unifi/user.generated.go +++ b/unifi/user.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type User struct { ID string `json:"_id,omitempty"` @@ -33,13 +37,13 @@ type User struct { IP string `json:"ip,omitempty"` } -func (c *Client) listUser(site string) ([]User, error) { +func (c *Client) listUser(ctx context.Context, site string) ([]User, error) { var respBody struct { Meta meta `json:"meta"` Data []User `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/user", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/user", site), nil, &respBody) if err != nil { return nil, err } @@ -47,13 +51,13 @@ func (c *Client) listUser(site string) ([]User, error) { return respBody.Data, nil } -func (c *Client) getUser(site, id string) (*User, error) { +func (c *Client) getUser(ctx context.Context, site, id string) (*User, error) { var respBody struct { Meta meta `json:"meta"` Data []User `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/user/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/user/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -66,21 +70,21 @@ func (c *Client) getUser(site, id string) (*User, error) { return &d, nil } -func (c *Client) deleteUser(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/user/%s", site, id), struct{}{}, nil) +func (c *Client) deleteUser(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/user/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createUser(site string, d *User) (*User, error) { +func (c *Client) createUser(ctx context.Context, site string, d *User) (*User, error) { var respBody struct { Meta meta `json:"meta"` Data []User `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/user", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/user", site), d, &respBody) if err != nil { return nil, err } @@ -94,13 +98,13 @@ func (c *Client) createUser(site string, d *User) (*User, error) { return &new, nil } -func (c *Client) updateUser(site string, d *User) (*User, error) { +func (c *Client) updateUser(ctx context.Context, site string, d *User) (*User, error) { var respBody struct { Meta meta `json:"meta"` Data []User `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/user/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/user/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/user.go b/unifi/user.go index 1a651f1..f240df2 100644 --- a/unifi/user.go +++ b/unifi/user.go @@ -1,17 +1,20 @@ package unifi -import "fmt" +import ( + "context" + "fmt" +) // GetUserByMAC returns slightly different information than GetUser, as they // use separate endpoints for their lookups. Specifically IP is only returned // by this method. -func (c *Client) GetUserByMAC(site, mac string) (*User, error) { +func (c *Client) GetUserByMAC(ctx context.Context, site, mac string) (*User, error) { var respBody struct { Meta meta `json:"meta"` Data []User `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/stat/user/%s", site, mac), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/stat/user/%s", site, mac), nil, &respBody) if err != nil { return nil, err } @@ -24,7 +27,7 @@ func (c *Client) GetUserByMAC(site, mac string) (*User, error) { return &d, nil } -func (c *Client) CreateUser(site string, d *User) (*User, error) { +func (c *Client) CreateUser(ctx context.Context, site string, d *User) (*User, error) { reqBody := struct { Objects []struct { Data *User `json:"data"` @@ -45,7 +48,7 @@ func (c *Client) CreateUser(site string, d *User) (*User, error) { } `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/group/user", site), reqBody, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/group/user", site), reqBody, &respBody) if err != nil { return nil, err } @@ -67,7 +70,7 @@ func (c *Client) CreateUser(site string, d *User) (*User, error) { return &new, nil } -func (c *Client) stamgr(site, cmd string, data map[string]interface{}) ([]User, error) { +func (c *Client) stamgr(ctx context.Context, site, cmd string, data map[string]interface{}) ([]User, error) { reqBody := map[string]interface{}{} for k, v := range data { @@ -81,7 +84,7 @@ func (c *Client) stamgr(site, cmd string, data map[string]interface{}) ([]User, Data []User `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/cmd/stamgr", site), reqBody, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/cmd/stamgr", site), reqBody, &respBody) if err != nil { return nil, err } @@ -89,8 +92,8 @@ func (c *Client) stamgr(site, cmd string, data map[string]interface{}) ([]User, return respBody.Data, nil } -func (c *Client) BlockUserByMAC(site, mac string) error { - users, err := c.stamgr(site, "block-sta", map[string]interface{}{ +func (c *Client) BlockUserByMAC(ctx context.Context, site, mac string) error { + users, err := c.stamgr(ctx, site, "block-sta", map[string]interface{}{ "mac": mac, }) if err != nil { @@ -102,8 +105,8 @@ func (c *Client) BlockUserByMAC(site, mac string) error { return nil } -func (c *Client) UnblockUserByMAC(site, mac string) error { - users, err := c.stamgr(site, "unblock-sta", map[string]interface{}{ +func (c *Client) UnblockUserByMAC(ctx context.Context, site, mac string) error { + users, err := c.stamgr(ctx, site, "unblock-sta", map[string]interface{}{ "mac": mac, }) if err != nil { @@ -115,8 +118,8 @@ func (c *Client) UnblockUserByMAC(site, mac string) error { return nil } -func (c *Client) DeleteUserByMAC(site, mac string) error { - users, err := c.stamgr(site, "forget-sta", map[string]interface{}{ +func (c *Client) DeleteUserByMAC(ctx context.Context, site, mac string) error { + users, err := c.stamgr(ctx, site, "forget-sta", map[string]interface{}{ "macs": []string{mac}, }) if err != nil { @@ -128,17 +131,17 @@ func (c *Client) DeleteUserByMAC(site, mac string) error { return nil } -func (c *Client) ListUser(site string) ([]User, error) { - return c.listUser(site) +func (c *Client) ListUser(ctx context.Context, site string) ([]User, error) { + return c.listUser(ctx, site) } // GetUser returns information about a user from the REST endpoint. // The GetUserByMAC method returns slightly different information (for // example the IP) as it uses a different endpoint. -func (c *Client) GetUser(site, id string) (*User, error) { - return c.getUser(site, id) +func (c *Client) GetUser(ctx context.Context, site, id string) (*User, error) { + return c.getUser(ctx, site, id) } -func (c *Client) UpdateUser(site string, d *User) (*User, error) { - return c.updateUser(site, d) +func (c *Client) UpdateUser(ctx context.Context, site string, d *User) (*User, error) { + return c.updateUser(ctx, site, d) } diff --git a/unifi/user_group.generated.go b/unifi/user_group.generated.go index 312095d..2c85f81 100644 --- a/unifi/user_group.generated.go +++ b/unifi/user_group.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type UserGroup struct { ID string `json:"_id,omitempty"` @@ -24,13 +28,13 @@ type UserGroup struct { QOSRateMaxUp int `json:"qos_rate_max_up,omitempty"` // -1|[2-9]|[1-9][0-9]{1,4}|100000 } -func (c *Client) listUserGroup(site string) ([]UserGroup, error) { +func (c *Client) listUserGroup(ctx context.Context, site string) ([]UserGroup, error) { var respBody struct { Meta meta `json:"meta"` Data []UserGroup `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/usergroup", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/usergroup", site), nil, &respBody) if err != nil { return nil, err } @@ -38,13 +42,13 @@ func (c *Client) listUserGroup(site string) ([]UserGroup, error) { return respBody.Data, nil } -func (c *Client) getUserGroup(site, id string) (*UserGroup, error) { +func (c *Client) getUserGroup(ctx context.Context, site, id string) (*UserGroup, error) { var respBody struct { Meta meta `json:"meta"` Data []UserGroup `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/usergroup/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/usergroup/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -57,21 +61,21 @@ func (c *Client) getUserGroup(site, id string) (*UserGroup, error) { return &d, nil } -func (c *Client) deleteUserGroup(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/usergroup/%s", site, id), struct{}{}, nil) +func (c *Client) deleteUserGroup(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/usergroup/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createUserGroup(site string, d *UserGroup) (*UserGroup, error) { +func (c *Client) createUserGroup(ctx context.Context, site string, d *UserGroup) (*UserGroup, error) { var respBody struct { Meta meta `json:"meta"` Data []UserGroup `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/usergroup", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/usergroup", site), d, &respBody) if err != nil { return nil, err } @@ -85,13 +89,13 @@ func (c *Client) createUserGroup(site string, d *UserGroup) (*UserGroup, error) return &new, nil } -func (c *Client) updateUserGroup(site string, d *UserGroup) (*UserGroup, error) { +func (c *Client) updateUserGroup(ctx context.Context, site string, d *UserGroup) (*UserGroup, error) { var respBody struct { Meta meta `json:"meta"` Data []UserGroup `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/usergroup/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/usergroup/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/user_group.go b/unifi/user_group.go index faa142d..54ef065 100644 --- a/unifi/user_group.go +++ b/unifi/user_group.go @@ -1,21 +1,23 @@ package unifi -func (c *Client) ListUserGroup(site string) ([]UserGroup, error) { - return c.listUserGroup(site) +import "context" + +func (c *Client) ListUserGroup(ctx context.Context, site string) ([]UserGroup, error) { + return c.listUserGroup(ctx, site) } -func (c *Client) GetUserGroup(site, id string) (*UserGroup, error) { - return c.getUserGroup(site, id) +func (c *Client) GetUserGroup(ctx context.Context, site, id string) (*UserGroup, error) { + return c.getUserGroup(ctx, site, id) } -func (c *Client) DeleteUserGroup(site, id string) error { - return c.deleteUserGroup(site, id) +func (c *Client) DeleteUserGroup(ctx context.Context, site, id string) error { + return c.deleteUserGroup(ctx, site, id) } -func (c *Client) CreateUserGroup(site string, d *UserGroup) (*UserGroup, error) { - return c.createUserGroup(site, d) +func (c *Client) CreateUserGroup(ctx context.Context, site string, d *UserGroup) (*UserGroup, error) { + return c.createUserGroup(ctx, site, d) } -func (c *Client) UpdateUserGroup(site string, d *UserGroup) (*UserGroup, error) { - return c.updateUserGroup(site, d) +func (c *Client) UpdateUserGroup(ctx context.Context, site string, d *UserGroup) (*UserGroup, error) { + return c.updateUserGroup(ctx, site, d) } diff --git a/unifi/virtual_device.generated.go b/unifi/virtual_device.generated.go index c28d3d8..57de5dc 100644 --- a/unifi/virtual_device.generated.go +++ b/unifi/virtual_device.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type VirtualDevice struct { ID string `json:"_id,omitempty"` @@ -27,13 +31,13 @@ type VirtualDevice struct { Y string `json:"y,omitempty"` } -func (c *Client) listVirtualDevice(site string) ([]VirtualDevice, error) { +func (c *Client) listVirtualDevice(ctx context.Context, site string) ([]VirtualDevice, error) { var respBody struct { Meta meta `json:"meta"` Data []VirtualDevice `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/virtualdevice", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/virtualdevice", site), nil, &respBody) if err != nil { return nil, err } @@ -41,13 +45,13 @@ func (c *Client) listVirtualDevice(site string) ([]VirtualDevice, error) { return respBody.Data, nil } -func (c *Client) getVirtualDevice(site, id string) (*VirtualDevice, error) { +func (c *Client) getVirtualDevice(ctx context.Context, site, id string) (*VirtualDevice, error) { var respBody struct { Meta meta `json:"meta"` Data []VirtualDevice `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/virtualdevice/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/virtualdevice/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -60,21 +64,21 @@ func (c *Client) getVirtualDevice(site, id string) (*VirtualDevice, error) { return &d, nil } -func (c *Client) deleteVirtualDevice(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/virtualdevice/%s", site, id), struct{}{}, nil) +func (c *Client) deleteVirtualDevice(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/virtualdevice/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createVirtualDevice(site string, d *VirtualDevice) (*VirtualDevice, error) { +func (c *Client) createVirtualDevice(ctx context.Context, site string, d *VirtualDevice) (*VirtualDevice, error) { var respBody struct { Meta meta `json:"meta"` Data []VirtualDevice `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/virtualdevice", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/virtualdevice", site), d, &respBody) if err != nil { return nil, err } @@ -88,13 +92,13 @@ func (c *Client) createVirtualDevice(site string, d *VirtualDevice) (*VirtualDev return &new, nil } -func (c *Client) updateVirtualDevice(site string, d *VirtualDevice) (*VirtualDevice, error) { +func (c *Client) updateVirtualDevice(ctx context.Context, site string, d *VirtualDevice) (*VirtualDevice, error) { var respBody struct { Meta meta `json:"meta"` Data []VirtualDevice `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/virtualdevice/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/virtualdevice/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/wlan.generated.go b/unifi/wlan.generated.go index 9ff1690..f2fb58d 100644 --- a/unifi/wlan.generated.go +++ b/unifi/wlan.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type WLAN struct { ID string `json:"_id,omitempty"` @@ -80,13 +84,13 @@ type WLAN struct { XWEP string `json:"x_wep,omitempty"` } -func (c *Client) listWLAN(site string) ([]WLAN, error) { +func (c *Client) listWLAN(ctx context.Context, site string) ([]WLAN, error) { var respBody struct { Meta meta `json:"meta"` Data []WLAN `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/wlanconf", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/wlanconf", site), nil, &respBody) if err != nil { return nil, err } @@ -94,13 +98,13 @@ func (c *Client) listWLAN(site string) ([]WLAN, error) { return respBody.Data, nil } -func (c *Client) getWLAN(site, id string) (*WLAN, error) { +func (c *Client) getWLAN(ctx context.Context, site, id string) (*WLAN, error) { var respBody struct { Meta meta `json:"meta"` Data []WLAN `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/wlanconf/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/wlanconf/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -113,21 +117,21 @@ func (c *Client) getWLAN(site, id string) (*WLAN, error) { return &d, nil } -func (c *Client) deleteWLAN(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/wlanconf/%s", site, id), struct{}{}, nil) +func (c *Client) deleteWLAN(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/wlanconf/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createWLAN(site string, d *WLAN) (*WLAN, error) { +func (c *Client) createWLAN(ctx context.Context, site string, d *WLAN) (*WLAN, error) { var respBody struct { Meta meta `json:"meta"` Data []WLAN `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/wlanconf", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/wlanconf", site), d, &respBody) if err != nil { return nil, err } @@ -141,13 +145,13 @@ func (c *Client) createWLAN(site string, d *WLAN) (*WLAN, error) { return &new, nil } -func (c *Client) updateWLAN(site string, d *WLAN) (*WLAN, error) { +func (c *Client) updateWLAN(ctx context.Context, site string, d *WLAN) (*WLAN, error) { var respBody struct { Meta meta `json:"meta"` Data []WLAN `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/wlanconf/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/wlanconf/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/wlan.go b/unifi/wlan.go index 9d9ba25..4cccfed 100644 --- a/unifi/wlan.go +++ b/unifi/wlan.go @@ -1,6 +1,7 @@ package unifi import ( + "context" "encoding/json" ) @@ -27,26 +28,26 @@ func (n *WLAN) UnmarshalJSON(b []byte) error { return nil } -func (c *Client) CreateWLAN(site string, d *WLAN) (*WLAN, error) { +func (c *Client) CreateWLAN(ctx context.Context, site string, d *WLAN) (*WLAN, error) { if d.Schedule == nil { d.Schedule = []string{} } - return c.createWLAN(site, d) + return c.createWLAN(ctx, site, d) } -func (c *Client) ListWLAN(site string) ([]WLAN, error) { - return c.listWLAN(site) +func (c *Client) ListWLAN(ctx context.Context, site string) ([]WLAN, error) { + return c.listWLAN(ctx, site) } -func (c *Client) GetWLAN(site, id string) (*WLAN, error) { - return c.getWLAN(site, id) +func (c *Client) GetWLAN(ctx context.Context, site, id string) (*WLAN, error) { + return c.getWLAN(ctx, site, id) } -func (c *Client) DeleteWLAN(site, id string) error { - return c.deleteWLAN(site, id) +func (c *Client) DeleteWLAN(ctx context.Context, site, id string) error { + return c.deleteWLAN(ctx, site, id) } -func (c *Client) UpdateWLAN(site string, d *WLAN) (*WLAN, error) { - return c.updateWLAN(site, d) +func (c *Client) UpdateWLAN(ctx context.Context, site string, d *WLAN) (*WLAN, error) { + return c.updateWLAN(ctx, site, d) } diff --git a/unifi/wlan_group.generated.go b/unifi/wlan_group.generated.go index 50cc7b0..0aee93b 100644 --- a/unifi/wlan_group.generated.go +++ b/unifi/wlan_group.generated.go @@ -4,11 +4,15 @@ package unifi import ( + "context" "fmt" ) // just to fix compile issues with the import -var _ fmt.Formatter +var ( + _ fmt.Formatter + _ context.Context +) type WLANGroup struct { ID string `json:"_id,omitempty"` @@ -28,13 +32,13 @@ type WLANGroup struct { PMFMode string `json:"pmf_mode,omitempty"` // disabled|optional|required } -func (c *Client) listWLANGroup(site string) ([]WLANGroup, error) { +func (c *Client) listWLANGroup(ctx context.Context, site string) ([]WLANGroup, error) { var respBody struct { Meta meta `json:"meta"` Data []WLANGroup `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/wlangroup", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/wlangroup", site), nil, &respBody) if err != nil { return nil, err } @@ -42,13 +46,13 @@ func (c *Client) listWLANGroup(site string) ([]WLANGroup, error) { return respBody.Data, nil } -func (c *Client) getWLANGroup(site, id string) (*WLANGroup, error) { +func (c *Client) getWLANGroup(ctx context.Context, site, id string) (*WLANGroup, error) { var respBody struct { Meta meta `json:"meta"` Data []WLANGroup `json:"data"` } - err := c.do("GET", fmt.Sprintf("s/%s/rest/wlangroup/%s", site, id), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/wlangroup/%s", site, id), nil, &respBody) if err != nil { return nil, err } @@ -61,21 +65,21 @@ func (c *Client) getWLANGroup(site, id string) (*WLANGroup, error) { return &d, nil } -func (c *Client) deleteWLANGroup(site, id string) error { - err := c.do("DELETE", fmt.Sprintf("s/%s/rest/wlangroup/%s", site, id), struct{}{}, nil) +func (c *Client) deleteWLANGroup(ctx context.Context, site, id string) error { + err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/wlangroup/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } -func (c *Client) createWLANGroup(site string, d *WLANGroup) (*WLANGroup, error) { +func (c *Client) createWLANGroup(ctx context.Context, site string, d *WLANGroup) (*WLANGroup, error) { var respBody struct { Meta meta `json:"meta"` Data []WLANGroup `json:"data"` } - err := c.do("POST", fmt.Sprintf("s/%s/rest/wlangroup", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/wlangroup", site), d, &respBody) if err != nil { return nil, err } @@ -89,13 +93,13 @@ func (c *Client) createWLANGroup(site string, d *WLANGroup) (*WLANGroup, error) return &new, nil } -func (c *Client) updateWLANGroup(site string, d *WLANGroup) (*WLANGroup, error) { +func (c *Client) updateWLANGroup(ctx context.Context, site string, d *WLANGroup) (*WLANGroup, error) { var respBody struct { Meta meta `json:"meta"` Data []WLANGroup `json:"data"` } - err := c.do("PUT", fmt.Sprintf("s/%s/rest/wlangroup/%s", site, d.ID), d, &respBody) + err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/wlangroup/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/wlan_group.go b/unifi/wlan_group.go index 4a9a372..69de902 100644 --- a/unifi/wlan_group.go +++ b/unifi/wlan_group.go @@ -1,6 +1,9 @@ package unifi -import "encoding/json" +import ( + "context" + "encoding/json" +) func (n *WLANGroup) UnmarshalJSON(b []byte) error { type Alias WLANGroup @@ -25,22 +28,22 @@ func (n *WLANGroup) UnmarshalJSON(b []byte) error { return nil } -func (c *Client) ListWLANGroup(site string) ([]WLANGroup, error) { - return c.listWLANGroup(site) +func (c *Client) ListWLANGroup(ctx context.Context, site string) ([]WLANGroup, error) { + return c.listWLANGroup(ctx, site) } -func (c *Client) GetWLANGroup(site, id string) (*WLANGroup, error) { - return c.getWLANGroup(site, id) +func (c *Client) GetWLANGroup(ctx context.Context, site, id string) (*WLANGroup, error) { + return c.getWLANGroup(ctx, site, id) } -func (c *Client) DeleteWLANGroup(site, id string) error { - return c.deleteWLANGroup(site, id) +func (c *Client) DeleteWLANGroup(ctx context.Context, site, id string) error { + return c.deleteWLANGroup(ctx, site, id) } -func (c *Client) CreateWLANGroup(site string, d *WLANGroup) (*WLANGroup, error) { - return c.createWLANGroup(site, d) +func (c *Client) CreateWLANGroup(ctx context.Context, site string, d *WLANGroup) (*WLANGroup, error) { + return c.createWLANGroup(ctx, site, d) } -func (c *Client) UpdateWLANGroup(site string, d *WLANGroup) (*WLANGroup, error) { - return c.updateWLANGroup(site, d) +func (c *Client) UpdateWLANGroup(ctx context.Context, site string, d *WLANGroup) (*WLANGroup, error) { + return c.updateWLANGroup(ctx, site, d) }