frontend.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package main
  2. import (
  3. "html/template"
  4. "golang-fave/engine/wrapper"
  5. )
  6. type TmplMenuItem struct {
  7. Name string
  8. Link string
  9. Active bool
  10. }
  11. type TmplData struct {
  12. PathSysIcoFav string
  13. PathSysCssBootstrap string
  14. PathSysJsJquery string
  15. PathSysJsPopper string
  16. PathSysJsBootstrap string
  17. MetaTitle string
  18. MetaKeywords string
  19. MetaDescription string
  20. MenuItems []TmplMenuItem
  21. SomeHtml template.HTML
  22. }
  23. func handleFrontEnd(e *wrapper.Wrapper) bool {
  24. tmpl, err := template.ParseFiles(
  25. e.DirVhostHome+"/template"+"/index.html",
  26. e.DirVhostHome+"/template"+"/header.html",
  27. e.DirVhostHome+"/template"+"/sidebar.html",
  28. e.DirVhostHome+"/template"+"/footer.html",
  29. )
  30. if err != nil {
  31. e.PrintTmplPageError(err)
  32. return true
  33. }
  34. tmpl.Execute(*e.W, TmplData{
  35. PathSysIcoFav: e.R.URL.Scheme + "://" + e.R.Host + "/assets/sys/fave.ico",
  36. PathSysCssBootstrap: e.R.URL.Scheme + "://" + e.R.Host + "/assets/sys/bootstrap.css",
  37. PathSysJsJquery: e.R.URL.Scheme + "://" + e.R.Host + "/assets/sys/jquery.js",
  38. PathSysJsPopper: e.R.URL.Scheme + "://" + e.R.Host + "/assets/sys/popper.js",
  39. PathSysJsBootstrap: e.R.URL.Scheme + "://" + e.R.Host + "/assets/sys/bootstrap.js",
  40. MetaTitle: "Meta Title",
  41. MetaKeywords: "Meta Keywords",
  42. MetaDescription: "Meta Description",
  43. MenuItems: []TmplMenuItem{
  44. {Name: "Home", Link: "/", Active: true},
  45. {Name: "Item 1", Link: "/#1", Active: false},
  46. {Name: "Item 2", Link: "/#2", Active: false},
  47. {Name: "Item 3", Link: "/#3", Active: false},
  48. },
  49. SomeHtml: template.HTML("<div class=\"some-class\">DIV</div>"),
  50. })
  51. return true
  52. }