frontend.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package main
  2. import (
  3. "golang-fave/engine/wrapper"
  4. "net/http"
  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 handleFrontEnd(e *wrapper.Wrapper) bool {
  19. // Redirect to CP, if MySQL config file is not exists
  20. if !utils.IsMySqlConfigExists(e.DirVhostHome) {
  21. (*e.W).Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
  22. http.Redirect(*e.W, e.R, e.R.URL.Scheme+"://"+e.R.Host+"/cp/", 302)
  23. return true
  24. }
  25. // Else logic here
  26. if e.R.URL.Path == "/" {
  27. return e.TmplFrontEnd("index", TmplData{
  28. MetaTitle: "Meta Title",
  29. MetaKeywords: "Meta Keywords",
  30. MetaDescription: "Meta Description",
  31. MenuItems: []MenuItem{
  32. {Name: "Home", Link: "/", Active: true},
  33. {Name: "Item 1", Link: "/#1", Active: false},
  34. {Name: "Item 2", Link: "/#2", Active: false},
  35. {Name: "Item 3", Link: "/#3", Active: false},
  36. },
  37. })
  38. }
  39. return false
  40. }