Re: [go-nuts] Using struct{} for context keys

2023-05-29 Thread Andreas Götz
Thank you. Zero values are of course identical. I was only thinking about the pointer case... On Sunday, May 28, 2023 at 5:10:33 PM UTC+2 burak serdar wrote: > Two values A and B are equal (A==B) if A and B have the same type and the > same values. In a code where > > a:=clientContextKey{} >

Re: [go-nuts] Using struct{} for context keys

2023-05-28 Thread burak serdar
Two values A and B are equal (A==B) if A and B have the same type and the same values. In a code where a:=clientContextKey{} b:=clientContextKey{} a==b is true, because they have the same types, and they have the same values (i.e. the empty value). Note however: a:={} b:={} It is not

[go-nuts] Using struct{} for context keys

2023-05-28 Thread cpu...@gmail.com
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