Skip to content
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

feat(go): Add context support to all requests #1527

Merged
merged 5 commits into from
May 9, 2023

Conversation

mehmetaligok
Copy link
Contributor

@mehmetaligok mehmetaligok commented May 8, 2023

🧭 What and Why

🎟 JIRA Ticket: https://algolia.atlassian.net/browse/APIC-696

We need to provide a way to accept users' context while respecting general conventions in Go.

Changes included:

  • Wrapper functions with a WithContext suffix added for all API methods to comply with the general DX standards.
    Ex:

// CreateAuthentication wraps CreateAuthenticationWithContext using context.Background.
func (c *APIClient) CreateAuthentication(r ApiCreateAuthenticationRequest, opts ...Option) (*AuthenticationCreateResponse, error) {
	return c.CreateAuthenticationWithContext(context.Background(), r, opts...)
}

// @return AuthenticationCreateResponse
func (c *APIClient) CreateAuthenticationWithContext(ctx context.Context, r ApiCreateAuthenticationRequest, opts ...Option) (*AuthenticationCreateResponse, error) {
.
.
.
// actual implementation
}
  • Playground example added to show context usage.

🧪 Test

Code generation and CI pipeline should be enough.

@mehmetaligok mehmetaligok self-assigned this May 8, 2023
@netlify
Copy link

netlify bot commented May 8, 2023

Deploy Preview for api-clients-automation ready!

Name Link
🔨 Latest commit 7c5dc94
🔍 Latest deploy log https://app.netlify.com/sites/api-clients-automation/deploys/645a3d3e7b1b99000746be02
😎 Deploy Preview https://deploy-preview-1527--api-clients-automation.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@mehmetaligok mehmetaligok added the Go label May 8, 2023
@algolia-bot
Copy link
Collaborator

algolia-bot commented May 8, 2023

✗ The generated branch has been deleted.

If the PR has been merged, you can check the generated code on the main branch.
You can still access the code generated on main via this commit.

@mehmetaligok mehmetaligok marked this pull request as ready for review May 8, 2023 12:27
@mehmetaligok mehmetaligok requested a review from a team as a code owner May 8, 2023 12:27
@mehmetaligok mehmetaligok requested review from aallam and millotp May 8, 2023 12:27
Copy link
Collaborator

@millotp millotp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love it ! just a suggestion

@@ -70,12 +70,20 @@ func (c *APIClient) NewApi{{{nickname}}}Request({{#pathParams}} {{paramName}} {{
}
}

// {{nickname}} wraps {{nickname}}WithContext using context.Background.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should you also add the description to this method ? I guess people will use this one first, I think it's okay to have duplicated doc in generated code, wdyt ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw this general convention on other popular packages. But your suggestion is also valid.

However, if you don't mind, is it okay to update these docs in another PR? Because, if you check you can see the actual method doesn't have a proper doc already. Most of them just say something like // @return AuthenticationCreateResponse.
I already have a ticket in the backlog to generate proper doc comments for the API functions to guide users. I think this may belong there as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure if there is a ticket no problem !

Copy link
Collaborator

@millotp millotp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gg !

@millotp
Copy link
Collaborator

millotp commented May 9, 2023

Hey, can you wait for #1534 to be merged before merging this one pls ? Once a release PR is open we can't merge anything in between otherwise it breaks the release process

@mehmetaligok
Copy link
Contributor Author

Hey, can you wait for #1534 to be merged before merging this one pls ? Once a release PR is open we can't merge anything in between otherwise it breaks the release process

@millotp sure no worries. I opened auto-merge on my other PR without noticing the release PR. Sorry if that blocked you :(

@millotp
Copy link
Collaborator

millotp commented May 9, 2023

no worries the process is a bit messy, it was just to let you know :)

@mehmetaligok mehmetaligok merged commit d2ad9cb into main May 9, 2023
@mehmetaligok mehmetaligok deleted the feat/go-client-ctx-support branch May 9, 2023 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants