I'm writing a web application in Go but I have some troubles getting my code organized.
For basic CRUD operations on MongoDB I always have to do something like this in the beginning of my code:
session, err := mgo.Dial("localhost")
if err != nil {
return err
}
defer session.Close()
But I don't like the fact that I always have to repeat the same code.
Is there a way to make it shorter or to avoid a lot of this in my code:
if err != nil {
return err
}
I'm new to Go so maybe I'm missing something obvious.