I have this function which is supposed to query database and return an article
if found, and nil if the article is not found:
func GetArticleBySlug(slug string) (model.Article, error) {
var err error
var article model.Article
err = database.SQL.Get(&article, "SELECT * FROM article WHERE slug=? LIMIT 1", slug)
if err != nil {
log.Println(err)
return nil, err //<- Problem here
}
return article, nil
}
Where Article
is a struct defined in model
package.
But I get this error:
cannot use nil as type model.Article in return argument
How can I fix this?