Closed peske closed 1 year ago
Good point
The main reason I use value types is that I keep reading that people recommend value receivers unless the struct becomes really big. However, as you might notice, most of the client functions also modify it which is why I used pointer receivers. I made the following rule:
But I agree that this is only confusing and I am not even consistent with these rules. Additionally, Go recommends to have one consistent receiver type per type. So I will stick to pointer receivers.
Should be mostly fixed now, thanks
Receiver functions of the same type should have consistent receiver argument types. For example, if we have one function with receiver argument
client *Client
(note pointer type), like in:https://github.com/eduvpn/eduvpn-common/blob/6229767a7d5b0d3cf3125f2e9da0ca0e66ada814/client/client.go#L22
then it should not have a function with receiver argument
client Client
(note value type), like in:https://github.com/eduvpn/eduvpn-common/blob/6229767a7d5b0d3cf3125f2e9da0ca0e66ada814/client/client.go#L31
In my experience, for structure types it is almost always better to have pointer receivers than value receivers.