Skip to content

Add child context for global variables#157

Merged
djthorpe merged 1 commit into
mainfrom
djt/0503/globals
May 3, 2026
Merged

Add child context for global variables#157
djthorpe merged 1 commit into
mainfrom
djt/0503/globals

Conversation

@djthorpe
Copy link
Copy Markdown
Member

@djthorpe djthorpe commented May 3, 2026

This pull request introduces support for context propagation in the Cmd interface and its implementations. The main changes include adding a WithContext method to the Cmd interface, implementing a new child struct to handle context, and updating the relevant methods to support this functionality.

Context propagation support:

  • Added the WithContext(context.Context) Cmd method to the Cmd interface in interfaces.go to allow creating copies of Cmd with a new context.
  • Added a new child struct in pkg/cmd/global.go to wrap Cmd with a specific context, and implemented its Context() method. [1] [2]
  • Implemented the WithContext method for the global struct, returning a new child instance with the provided context.

Copilot AI review requested due to automatic review settings May 3, 2026 06:04
@djthorpe djthorpe self-assigned this May 3, 2026
@djthorpe djthorpe merged commit 9ee69dd into main May 3, 2026
2 checks passed
@djthorpe djthorpe deleted the djt/0503/globals branch May 3, 2026 06:04
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds context propagation support to the server.Cmd runtime interface so callers can derive a Cmd instance with an overridden context.Context while keeping other runtime dependencies (logger, tracer, defaults, etc.) the same.

Changes:

  • Added WithContext(context.Context) Cmd to the server.Cmd interface.
  • Introduced an internal child wrapper in pkg/cmd/global.go to override Context() while delegating the rest of Cmd.
  • Implemented (*global).WithContext to produce a child instance.

Reviewed changes

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

File Description
interfaces.go Extends the public server.Cmd interface with WithContext.
pkg/cmd/global.go Adds child wrapper + implements WithContext for *global and Context() for *child.

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

Comment thread interfaces.go
Comment on lines 81 to +82
HTTPTimeout() time.Duration

Comment thread pkg/cmd/global.go
}

func (c *child) Context() context.Context {
return c.ctx
Comment thread pkg/cmd/global.go
Comment on lines +179 to +184
// WithContext returns a copy of the Cmd with the provided context.
func (g *global) WithContext(ctx context.Context) server.Cmd {
return types.Ptr(child{
Cmd: g,
ctx: ctx,
})
Comment thread pkg/cmd/global.go
Comment on lines +180 to +184
func (g *global) WithContext(ctx context.Context) server.Cmd {
return types.Ptr(child{
Cmd: g,
ctx: ctx,
})
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