Wrong types as keys

The first practice to avoid is the usage of built-in types as keys. This is problematic because they can be overwritten because two interfaces with the same built-in values are considered the same, as shown in the following example:

func main() {
var a interface{} = "request-id"
var b interface{} = "request-id"
fmt.Println(a == b)

ctx := context.Background()
ctx = context.WithValue(ctx, a, "a")
ctx = context.WithValue(ctx, b, "b")
fmt.Println(ctx.Value(a), ctx.Value(b))
}

The full example is available here: https://play.golang.org/p/2W3noYQP5eh.

The first print instruction outputs true, and since the keys are compared by value, the second assignment shadows the first, resulting in the values for both keys being the same. A potential solution to this is to use an empty struct custom type, or an unexported pointer to a built-in value.