Calorie counting web application written in the Go language

app.go 703B

123456789101112131415161718192021222324252627282930313233343536
  1. package controllers
  2. import (
  3. "github.com/revolvingcow/grassfed/app/models"
  4. )
  5. type Application struct {
  6. DatabaseController
  7. }
  8. func (c Application) Connected() *models.Account {
  9. if c.RenderArgs["account"] != nil {
  10. return c.RenderArgs["account"].(*models.Account)
  11. }
  12. if id, ok := c.Session["account"]; ok {
  13. return c.getAccount(id)
  14. }
  15. return nil
  16. }
  17. func (c Application) getAccount(id string) *models.Account {
  18. accounts, err := c.Transaction.Select(models.Account{}, `select * from Account where Profile = ?`, id)
  19. if err != nil {
  20. panic(err)
  21. }
  22. if len(accounts) == 0 {
  23. return nil
  24. }
  25. return accounts[0].(*models.Account)
  26. }