frontend.go 1011 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package frontend
  2. import (
  3. "database/sql"
  4. _ "github.com/go-sql-driver/mysql"
  5. "golang-fave/engine/wrapper"
  6. )
  7. // --- Demo
  8. type MenuItem struct {
  9. Name string
  10. Link string
  11. Active bool
  12. }
  13. type TmplData struct {
  14. MetaTitle string
  15. MetaKeywords string
  16. MetaDescription string
  17. MenuItems []MenuItem
  18. }
  19. // --------
  20. type Frontend struct {
  21. wrapper *wrapper.Wrapper
  22. db *sql.DB
  23. }
  24. func New(wrapper *wrapper.Wrapper, db *sql.DB) *Frontend {
  25. return &Frontend{wrapper, db}
  26. }
  27. func (this *Frontend) Run() bool {
  28. // --- Demo
  29. if this.wrapper.R.URL.Path == "/" {
  30. return this.wrapper.TmplFrontEnd("index", TmplData{
  31. MetaTitle: "Meta Title",
  32. MetaKeywords: "Meta Keywords",
  33. MetaDescription: "Meta Description",
  34. MenuItems: []MenuItem{
  35. {Name: "Home", Link: "/", Active: true},
  36. {Name: "Item 1", Link: "/#1", Active: false},
  37. {Name: "Item 2", Link: "/#2", Active: false},
  38. {Name: "Item 3", Link: "/#3", Active: false},
  39. },
  40. })
  41. }
  42. // --------
  43. return false
  44. }