Add context support
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user