Hello I am new in Golang and need some help, am a Java programmer
Look at this line of code
1) f := goutil.Try(os.Open("file")).(io.Reader)
My util Try manages the error cases etc etc, then return an interface and cast for f.
If I use simply, as taught on the documentation, the following code
2) f := os.Open("file")
f in this case is a File !
So Why above I have to convert in io.Reader ? That is ok and work fine !
In other word why these two piece of code, work anyway !
f := goutil.Try(os.Open("file")).(io.Reader)
AND
f := os.Open("file")
defer f.Close()
my Try function is for now simply
func Try(res interface{}, err error) interface{}{
if err != nil {
panic(err)
os.Exit(-1)
}
return res
}
Thank you in adavnced