fetdata.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package fetdata
  2. import (
  3. "time"
  4. "golang-fave/engine/wrapper"
  5. "golang-fave/utils"
  6. )
  7. type FERData struct {
  8. wrap *wrapper.Wrapper
  9. dataRow interface{}
  10. is404 bool
  11. bufferUser *utils.MySql_user
  12. bufferPosts map[string][]*BlogPost
  13. }
  14. func New(wrap *wrapper.Wrapper, drow interface{}, is404 bool) *FERData {
  15. fer := &FERData{
  16. wrap: wrap,
  17. dataRow: drow,
  18. is404: is404,
  19. }
  20. return fer.init()
  21. }
  22. func (this *FERData) init() *FERData {
  23. if this.dataRow != nil {
  24. if this.wrap.CurrModule == "index" {
  25. if this.dataRow.(*utils.MySql_page).A_meta_title == "" {
  26. this.dataRow.(*utils.MySql_page).A_meta_title = this.dataRow.(*utils.MySql_page).A_name
  27. }
  28. }
  29. }
  30. return this
  31. }
  32. func (this *FERData) Module() string {
  33. if this.is404 {
  34. return "404"
  35. }
  36. var mod string
  37. if this.wrap.CurrModule == "index" {
  38. mod = "index"
  39. } else if this.wrap.CurrModule == "blog" {
  40. if len(this.wrap.UrlArgs) >= 2 && this.wrap.UrlArgs[0] == "blog" && this.wrap.UrlArgs[1] == "category" {
  41. mod = "blog-category"
  42. } else if len(this.wrap.UrlArgs) >= 2 && this.wrap.UrlArgs[0] == "blog" && this.wrap.UrlArgs[1] != "" {
  43. mod = "blog-post"
  44. } else {
  45. mod = "blog"
  46. }
  47. }
  48. return mod
  49. }
  50. func (this *FERData) CurrentDateTime() int {
  51. return int(time.Now().Unix())
  52. }
  53. func (this *FERData) CurrentDateTimeFormat(format string) string {
  54. return time.Unix(int64(time.Now().Unix()), 0).Format(format)
  55. }