Repository navigation
Update github package to support updated go-github library - #14
Conversation
Adds support for changes in go-github package in: google/go-github#529 Fixes #12.
| for { | ||
| prs, resp, _ := client.Search.Issues( | ||
| // Search query to find PR's | ||
| context.Background(), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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.
Adds support for changes in go-github package in:
google/go-github#529
Fixes #12.
@shurcooL Would you mind giving this change a look?