I've recently stumbled across code like this 
https://go.dev/play/p/u3UER2ywRlr:

type clientContextKey struct{}

ctx := context.Background()
ctx = context.WithValue(ctx, clientContextKey{}, "foo")
_, ok := ctx.Value(clientContextKey{}).(string)

Naively, I had expected this to fail since I assumed that 
clientContextKey{} would create a new variable instance every time it was 
used and hence the keys would not match.

Why does this use of instantiating the struct type work here?

Thanks,
Andi

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/55783f87-bad8-4ca4-9c4a-d8686ae156abn%40googlegroups.com.

Reply via email to