Skip to content

fix(go): pass context to functions - #14

Open
syndbg wants to merge 1 commit into
gotha:mainfrom
syndbg:fix-ctx-usage
Open

fix(go): pass context to functions#14
syndbg wants to merge 1 commit into
gotha:mainfrom
syndbg:fix-ctx-usage

Conversation

@syndbg

@syndbg syndbg commented May 14, 2026

Copy link
Copy Markdown

Enables cancellation, timeouts and follow industry best practices for Go.

Do not store Contexts inside a struct type; instead, pass a Context explicitly to each function that needs it.
This is discussed further in https://go.dev/blog/context-and-structs. The Context should be the first parameter, typically named ctx:

ref: https://pkg.go.dev/context

Enables cancellation, timeouts and follow industry best practices for Go.

```
Do not store Contexts inside a struct type; instead, pass a Context explicitly to each function that needs it.
This is discussed further in https://go.dev/blog/context-and-structs. The Context should be the first parameter, typically named ctx:
```

ref: https://pkg.go.dev/context
Copilot AI review requested due to automatic review settings May 14, 2026 16:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Refactors Go cache helper functions to accept a context.Context parameter from the caller instead of creating a new background context internally, allowing proper context propagation.

Changes:

  • Updated getFromCache and saveToCache signatures in both starter and solution to accept ctx context.Context.
  • Updated call sites in main to pass the existing ctx.
  • Removed internal context.Background() creation in solution.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
workshop/session-2/go/starter/main.go Add ctx parameter to cache function signatures and pass it from main.
workshop/session-2/go/solution/main.go Same signature update; remove internal context.Background() calls.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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