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
6 changes: 6 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ default:
tidy:
go mod tidy

# run specific unit test
[group('build')]
[no-cd]
test unit:
go test -v -count=1 -race -run {{unit}} 2>/dev/null

# run tests across source tree
[group('build')]
tests:
Expand Down
10 changes: 10 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,13 @@ func WithCancel(c C) (C, Cancel) {
func WithTTL(c C, duration time.Duration) (C, Cancel) {
return context.WithTimeout(c, duration)
}

// WithValue wraps an existing Context with value set for key.
func WithValue[K, V any](c C, key K, value V) C {
return context.WithValue(c, key, value)
}

// Value retrieves the value associated with the given key.
func Value[K, V any](c C, key K) V {
return c.Value(key).(V)
}