Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ type Cmd interface {

// HTTPTimeout returns the HTTP read/write timeout.
HTTPTimeout() time.Duration

Comment on lines 81 to +82
// WithContext returns a copy of the Cmd with the provided context.
WithContext(context.Context) Cmd
}

///////////////////////////////////////////////////////////////////////////////
Expand Down
17 changes: 17 additions & 0 deletions pkg/cmd/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ type global struct {
defaults
}

type child struct {
server.Cmd
ctx context.Context
}

// Ensure *globals implements server.Cmd
var _ server.Cmd = (*global)(nil)

Expand All @@ -81,6 +86,10 @@ func (g *global) Context() context.Context {
return g.ctx
}

func (c *child) Context() context.Context {
return c.ctx
}

func (g *global) Logger() *slog.Logger {
return g.logger
}
Expand Down Expand Up @@ -166,3 +175,11 @@ func (g *global) HTTPPrefix() string {
func (g *global) HTTPTimeout() time.Duration {
return g.HTTP.Timeout
}

// 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 on lines +179 to +184
Comment on lines +180 to +184
}