frontend.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package main
  2. import (
  3. "net/http"
  4. "golang-fave/engine/wrapper"
  5. utils "golang-fave/engine/wrapper/utils"
  6. )
  7. type MenuItem struct {
  8. Name string
  9. Link string
  10. Active bool
  11. }
  12. type TmplData struct {
  13. MetaTitle string
  14. MetaKeywords string
  15. MetaDescription string
  16. MenuItems []MenuItem
  17. }
  18. func handlerFrontEnd(wrapper *wrapper.Wrapper) bool {
  19. // Redirect to CP, if MySQL config file is not exists
  20. if !utils.IsMySqlConfigExists(wrapper.DirVHostHome) {
  21. (*wrapper.W).Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
  22. http.Redirect(*wrapper.W, wrapper.R, wrapper.R.URL.Scheme+"://"+wrapper.R.Host+"/cp/", 302)
  23. return true
  24. }
  25. // Connect to database
  26. // Else logic here
  27. if wrapper.R.URL.Path == "/" {
  28. return wrapper.TmplFrontEnd("index", TmplData{
  29. MetaTitle: "Meta Title",
  30. MetaKeywords: "Meta Keywords",
  31. MetaDescription: "Meta Description",
  32. MenuItems: []MenuItem{
  33. {Name: "Home", Link: "/", Active: true},
  34. {Name: "Item 1", Link: "/#1", Active: false},
  35. {Name: "Item 2", Link: "/#2", Active: false},
  36. {Name: "Item 3", Link: "/#3", Active: false},
  37. },
  38. })
  39. }
  40. return false
  41. }