Skip to content

Update github package to support updated go-github library - #14

Merged
karanjthakkar merged 2 commits into
masterfrom
fix-github-package-impl
Mar 5, 2017
Merged

karanjthakkar merged 2 commits into
masterfrom
fix-github-package-impl

Conversation

@karanjthakkar

Copy link
Copy Markdown
Owner

Adds support for changes in go-github package in:
google/go-github#529

Fixes #12.

@shurcooL Would you mind giving this change a look?

Adds support for changes in go-github package in:
google/go-github#529

Fixes #12.
Comment thread main.go Outdated
for {
prs, resp, _ := client.Search.Issues(
// Search query to find PR's
context.Background(),

@dmitshur dmitshur Mar 5, 2017 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is valid and it would work.

If you wanted to use the context request that's available in this handler, I believe you can simply pass c here.

If you look at the signature of the handler:

// User handler
router.GET("user/:username", func(c *gin.Context) {

From what I can tell, *gin.Context implements context.Context interface and should work.

I'm not very familiar with "github.com/gin-gonic/gin" package, so I could be off.

@karanjthakkar karanjthakkar Mar 5, 2017 •

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@shurcooL How can I identify that passing c is working as expected? I passed c instead of context.Background() in all the three places and it doesnt give me any errors and starts up my server. Is that enough of an indicator?

Honestly I have not really understood what passing the context to go-github does.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

How can I identify that passing c is working as expected? It doesnt give me any errors and starts up my server. Is that enough of an indicator?

Yep, then it should be fine.

Honestly I have not really understood what passing the context to go-github does.

In your situation, practically, it probably does not have much effect. One of the ways it can help is if the incoming HTTP request to your server is canceled early (imagine, the user closes their browser window while the page was loading), then the relevant request to github servers will also be cancelled automatically and avoid doing extra unnecessary work.

However, from a quick look at the current version of gin, it doesn't seem they support request cancellation.

In the general case, it's a good idea to propagate context for the reasons described in https://blog.golang.org/context. But it's more helpful and applicable to larger projects where you're doing tracing, or if you want to set specific timeouts or deadlines, etc.

@dmitshur dmitshur Mar 5, 2017 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If you prefer, it's completely okay to keep your code as is, just use context.Background() for now. It's valid and will continue to behave as before.

Later on, once you have more advanced needs and you want to take advantage of things that contexts allow you to do, then you can change this code to fit those needs.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@shurcooL Got it! Thanks for the explanation. I've changed it to use gin.Context in case I need to use it in the future.

@karanjthakkar
karanjthakkar merged commit 1d9d213 into master Mar 5, 2017
@karanjthakkar
karanjthakkar deleted the fix-github-package-impl branch March 5, 2017 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants