Reputation: 3519
When creating a func
that returns both an error and a result, which order should they be in? I've seen examples of both, and not sure where to look to confirm the idiomatic style.
should it be:
// a
func funcName(n int) (error, int) {}
// or b
func funcName(n int) (int, error) {}
Upvotes: 1
Views: 1913
Reputation: 3519
As pointed out by @Gavin above in the comments :
If you look here, you will see By convention, errors are the last return value and have type error, a built-in interface.
As can be seen in the standard lib.
Upvotes: 3