-
Notifications
You must be signed in to change notification settings - Fork 0
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
Adding uhttp client #7
Conversation
mchavez
commented
Apr 11, 2024
- Add uhttp client
func (v *VGSClient) GetOrganizations(ctx context.Context) ([]Organization, error) { | ||
v.InitHttpClient() | ||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, v.endpoint+"/organizations", nil) | ||
url, _ := url.JoinPath(v.endpoint, "/organizations") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should check the error. Also the variable name "url" shadows the url library, so you might want to change the name.
v.InitHttpClient() | ||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, v.endpoint+"/organizations", nil) | ||
url, _ := url.JoinPath(v.endpoint, "/organizations") | ||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uhttp has a helper function for making requests, so this can be:
v.httpClient.NewRequest(ctx,
http.MethodGet,
orgUrl,
WithHeader("Authorization", "Bearer "+v.GetToken()),
WithAcceptJSONHeader(),
WithJSONResponse(&organizationsAPIData),
)
...and then you don't need to add the headers separately, nor do you need to read and unmarshal the response body below. All of the requests in this file can get this treatment.
Also I'm pretty sure we don't want the content-type header here. This is a get, so we're not sending a body to the server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah.. It looks weirds, but according to docs it is necessary in some cases.
https://www.verygoodsecurity.com/docs/accounts/api/#tag/users/paths/~1organizations~1{organizationId}~1members/get