I'm new to go - just playing with it - but I've written a command line tool - I call about 30 different functions that return x, err
. In every case - what I want to do is just panic if there is an error - basically everything works perfectly, or the whole thing fails.
I know there's template.Must( t Template*, err Error) Template*
- and I know I can make a check(something interface{}, err Error) interface{}
- but to use it I've gotta do a type cast, which is nasty.
Is it in any way possible to make a sort of generic function panicIfError
such that I can do something like
x := panicIfError( ioutil.ReadFile( fileName ))
and have x come out with the right type?
(I've seen lots of people put the if on the same line - to my mind that sacrifices too much readability - currently my only solution is to make an overload of panicIfError
for every single type I use, which is not ideal)