This question already has an answer here:
I was reading some code written in golang on github and found very interesting piece of code. I simplified it to be clear.
func Insert(docs ...interface{}) (err error) {
for i := 0; i < 3; i++ {
err = fmt.Errorf("")
if err.Error()!="EOF" {
return
}
}
return err
}
I'm very confused about empty return here... How it works? He returns nil as error or breaks for loop? I understand that this question looks dummy, but i cannot find any info on this in go docs... Also i don't understand how we can return err, which is, as i understood, declared somehow in return. Does (err error) means that we already have an error variable available in our func which is used as default return value if none specified? Why then we implicitly make return err in the end of func?
I'll be very gratefull for explanation.
</div>