You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailscale/util
Joe Tsai 241a541864
util/ctxkey: add package for type-safe context keys (#10841)
The lack of type-safety in context.WithValue leads to the common pattern
of defining of package-scoped type to ensure global uniqueness:

	type fooKey struct{}

	func withFoo(ctx context, v Foo) context.Context {
		return context.WithValue(ctx, fooKey{}, v)
	}

	func fooValue(ctx context) Foo {
		v, _ := ctx.Value(fooKey{}).(Foo)
		return v
	}

where usage becomes:

	ctx = withFoo(ctx, foo)
	foo := fooValue(ctx)

With many different context keys, this can be quite tedious.

Using generics, we can simplify this as:

	var fooKey = ctxkey.New("mypkg.fooKey", Foo{})

where usage becomes:

	ctx = fooKey.WithValue(ctx, foo)
	foo := fooKey.Value(ctx)

See https://go.dev/issue/49189

Updates #cleanup

Signed-off-by: Joe Tsai <joetsai@digital-static.net>
9 months ago
..
cache util/cache: add package for general-purpose caching 10 months ago
cibuild all: update copyright and license headers 2 years ago
clientmetric util/clientmetric: allow client metric values to be provided by a function 2 years ago
cloudenv all: update copyright and license headers 2 years ago
cmpver util/cmpver: only consider ascii numerals (#9741) 12 months ago
cmpx util/cmpx: remove code that's in the stdlib now 9 months ago
codegen util/codegen: support embedded fields 1 year ago
cstruct all: update copyright and license headers 2 years ago
ctxkey util/ctxkey: add package for type-safe context keys (#10841) 9 months ago
deephash all: cleanup unused code, part 1 (#10661) 9 months ago
dirwalk all: use tstest.Replace more 2 years ago
dnsname cmd/tailscale: extend hostname validation (#7678) 2 years ago
goroutines util/goroutines: let ScrubbedGoroutineDump get only current stack 1 year ago
groupmember util/groupmember: fail earlier if group doesn't exist, use slices.Contains 11 months ago
hashx all: update copyright and license headers 2 years ago
httphdr util/httphdr: add new package for parsing HTTP headers (#9797) 12 months ago
httpm util/httpm: don't run test if .git doesn't exist 10 months ago
jsonutil all: update copyright and license headers 2 years ago
limiter util/lru, util/limiter: add debug helper to dump state as HTML 1 year ago
lineread all: update copyright and license headers 2 years ago
linuxfw all: cleanup unused code, part 2 (#10670) 9 months ago
lru util/lru: update c.head when deleting the most recently used entry 1 year ago
mak various: add golangci-lint, fix issues (#7905) 1 year ago
multierr all: use Go 1.21 slices, maps instead of x/exp/{slices,maps} 1 year ago
must all: update copyright and license headers 2 years ago
nocasemaps util/nocasemaps: import nocasemaps from corp 12 months ago
osdiag util/osdiag, util/winutil: expose Windows policy key 11 months ago
osshare all: update copyright and license headers 2 years ago
osuser ssh/tailssh,util: extract new osuser package from ssh code (#10170) 11 months ago
pidowner all: update copyright and license headers 2 years ago
precompress all: update copyright and license headers 2 years ago
quarantine all: update copyright and license headers 2 years ago
race util/race: add test to confirm we don't leak goroutines 12 months ago
racebuild all: update copyright and license headers 2 years ago
rands util/rands: add package with HexString func 1 year ago
ringbuffer util/ringbuffer: move generic ringbuffer from corp repo 2 years ago
set util/set: implement json.Marshaler/Unmarshaler (#10308) 10 months ago
singleflight all: update copyright and license headers 2 years ago
slicesx util/slicesx: add EqualSameNil, like slices.Equal but same nilness 1 year ago
syspolicy all: cleanup unused code, part 1 (#10661) 9 months ago
sysresources util/sysresources, magicsock: scale DERP buffer based on system memory 2 years ago
systemd all: update copyright and license headers 2 years ago
testenv util/testenv: add new package to hold InTest 1 year ago
truncate util: add truncate package (#7490) 2 years ago
uniq all: update copyright and license headers 2 years ago
vizerror util/vizerror: add As function to get wrapped Error 2 years ago
winutil util/winutil: add some missing docs to restartmgr errors 9 months ago