by klabb3 · 2y ago · 0 comments
The idiomatic way is to return an error or an `ok` boolean at the function boundary. Callers always check return value anyway, this is hard to forget because it’s almost always needed anyway.
The type itself can be value or pointer – its an orthogonal choice. If you have a value type that you return, then you should return the zero value (for instance `time.Time{}`. Both nil and the zero type are comparable by equality check.
This is not ideal, and gets messy when the zero type is a valid value for instance. Generics offer some hope but they are not as capable as in eg Rust.
The unmarshal functions take a reference but they don’t need to be declared as (heap-based) pointers. You can pass a `&val` directly. It needs a reference passed in to determine the type.