Been reading about when to use a pointer or value receiver and I think I know most of the reasons for making the decision but, now I’m curious about this specific example:
// Example of using the testing library
func TestHelloName(t *testing.T) {
name := "Gladys"
want := regexp.MustCompile(`\b` + name + `\b`)
msg, err := Hello("Gladys")
if !want.MatchString(msg) || err != nil {
t.Fatalf(`Hello("Gladys") = %q, %v, want match for %#q, nil`, msg, err, want)
}
}
I would LOVE to know the reason pointer receivers were chosen for the testing library- I think this would be helpful for my understanding. Did they chose a pointer because large structs could be passed to it? Or is there something inherent to how the testing library is used that makes pointer receivers the right choice here?