Skip to content

Instantly share code, notes, and snippets.

@bastianccm
Created February 26, 2020 13:16
Show Gist options
  • Save bastianccm/7056043e26a9dfe9c4e181c42bce3466 to your computer and use it in GitHub Desktop.
Save bastianccm/7056043e26a9dfe9c4e181c42bce3466 to your computer and use it in GitHub Desktop.
// ...
import "github.com/jinzhu/gorm"
type controller struct {
responder *web.Responder
db *gorm.DB
}
func (c *controller) Inject(responder *web.Responder, db *gorm.DB) {
c.responder = responder
c.db = db
}
func (c *controller) index(ctx context.Context, request *web.Request) web.Result {
var viewData struct {
LatestQuestionList []Question
}
c.db.Limit(5).Order("id desc").Find(&viewData.LatestQuestionList)
return c.responder.Render("index", viewData)
}
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment