Here is a snippet that I am looking at:
var t txn
t.c = c
err := c.read(&t.req)
Why do you have to write &t and not just t.req?
Here is a snippet that I am looking at:
var t txn
t.c = c
err := c.read(&t.req)
Why do you have to write &t and not just t.req?
You don't always have to use the ampersand. In your example it depends on the signature of c.read, which asks for a pointer (*
before the type, such as *MyStruct
). &
returns the address of a value, giving you a pointer to it, so &t.req
satisfies read's signature.
For further reading, see the FAQ on pointers and the spec on Address operators.