From 4bfea961d0a598a689065d47f3682f983d8b8b41 Mon Sep 17 00:00:00 2001 From: Simon Bronner Date: Wed, 21 Jul 2021 21:15:37 +1000 Subject: [PATCH] Moved to use the new /api/admin/user/id/ endpoint - available in 1.0.184 --- client/user.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/client/user.go b/client/user.go index 0c29c15..e80678e 100644 --- a/client/user.go +++ b/client/user.go @@ -1,7 +1,6 @@ package client import ( - "errors" "fmt" "log" ) @@ -234,18 +233,27 @@ func (client *Client) GetAllUsers() (*[]User, error) { func (client *Client) GetUserByID(userId string) (*User, error) { - users, err := client.GetAllUsers() + opts := RequestOptions{ + Path: fmt.Sprintf("/admin/user/id/%s", userId), + Method: "GET", + } + + resp, err := client.RequestAPI(&opts) + if err != nil { return nil, err } - for _, user := range *users { - if user.ID == userId { - return &user, nil - } + var user User + + err = DecodeResponseInto(resp, &user) + + if err != nil { + return nil, err } - return nil, errors.New(fmt.Sprintf("[ERROR] User with ID %s wasn't found.", userId)) + return &user, nil + } func (client *Client) DeleteUser(userName string) error {