-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Second NewClient() overrides initial NewClient()? #20
Comments
I think it might be the use of the global variable RestyClient which is overridden each time a new client is initialised and then used for API calls:
|
I tried the following changes which seemed to work. Any chance you could try it out and maybe implement? Thanks.
type service struct {
client *resty.Client
} func NewClient() *Client {
client := resty.New()
client.SetHostURL(apiURL)
if os.Getenv("WEBEX_TEAMS_ACCESS_TOKEN") != "" {
client.SetAuthToken(os.Getenv("WEBEX_TEAMS_ACCESS_TOKEN"))
}
c := &Client{}
c.common.client = client
...
} then in each of the services, e.g.
func (s *PeopleService) GetMe() (*Person, *resty.Response, error) {
path := "/people/me"
response, err := s.client.R().
SetResult(&Person{}).
SetError(&Error{}).
Get(path)
if err != nil {
return nil, nil, err
}
result := response.Result().(*Person)
return result, response, err
} I also had to update the pagination functions to make them methods of the service and then update the List methods to reference it under s. |
@darrenparkinson Sorry for the delay. Let me test this tomorrow. |
@darrenparkinson Thanks a lot for your valuable input. I tested your recommendations and included them in the repo, plus I created tag 0.4.2 |
Hi, me again ;)
I'm experiencing a weird issue which I suspect is obvious, but I can't quite get my head around it...
Essentially, if I create two clients with
NewClient()
using two separate tokens withSetAuthToken()
the second one seems to overwrite the first.For example, this code works as expected:
But this does not, it basically prints the second clients display name twice
Any thoughts before I start digging into it further greatly appreciated.
Thanks.
The text was updated successfully, but these errors were encountered: