I am trying to wrap my head around Golang's types and interfaces but am struggling a bit to do so. Anyways, a common pattern that I see is func Whatever() (thing string, err error)
. I get how all of that works, but the one thing I am confused on is why it is ok to return "thing", nil
. The specific instance that I am looking at is in revel here-
func (c *GorpController) Begin() revel.Result {
txn, err := Dbm.Begin()
if err != nil {
panic(err)
}
c.Txn = txn
return nil
}
revel.Result
is an interface with this signature-
type Result interface {
Apply(req *Request, resp *Response)
}
Anyways, I am just curious how returning nil
satisfies the compiler in that occasion. Is there a resource that I can be pointed to for that?
This is similar to returning a nil error: see "Why is my nil error value not equal to nil? "
Here
nil
is the zero-value of the interfacerevel.Result
.