Wrap clients in a struct too.

This commit is contained in:
David Newhall II 2019-01-26 12:51:08 -08:00
parent 483480a4eb
commit c5c1907be7
2 changed files with 7 additions and 2 deletions

View File

@ -34,6 +34,11 @@ type Devices struct {
USWs []USW USWs []USW
} }
// Clients conptains a list of all the unifi clients from a controller.
type Clients struct {
UCLs []UCL
}
// Unifi is what you get in return for providing a password! // Unifi is what you get in return for providing a password!
type Unifi struct { type Unifi struct {
*http.Client *http.Client

View File

@ -8,7 +8,7 @@ import (
) )
// GetClients returns a response full of clients' data from the Unifi Controller. // GetClients returns a response full of clients' data from the Unifi Controller.
func (u *Unifi) GetClients() ([]UCL, error) { func (u *Unifi) GetClients() (*Clients, error) {
var response struct { var response struct {
Clients []UCL `json:"data"` Clients []UCL `json:"data"`
} }
@ -28,7 +28,7 @@ func (u *Unifi) GetClients() ([]UCL, error) {
} else if err = json.Unmarshal(body, &response); err != nil { } else if err = json.Unmarshal(body, &response); err != nil {
return nil, errors.Wrap(err, "json.Unmarshal([]UCL)") return nil, errors.Wrap(err, "json.Unmarshal([]UCL)")
} }
return response.Clients, nil return &Clients{UCLs: response.Clients}, nil
} }
// GetDevices returns a response full of devices' data from the Unifi Controller. // GetDevices returns a response full of devices' data from the Unifi Controller.