fetdata.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. is404 bool
  10. Page *Page
  11. Blog *Blog
  12. }
  13. func New(wrap *wrapper.Wrapper, drow interface{}, is404 bool) *FERData {
  14. var d_Page *Page
  15. var d_Blog *Blog
  16. if wrap.CurrModule == "index" {
  17. if o, ok := drow.(*utils.MySql_page); ok {
  18. d_Page = &Page{wrap: wrap, object: o}
  19. }
  20. } else if wrap.CurrModule == "blog" {
  21. if len(wrap.UrlArgs) == 3 && wrap.UrlArgs[0] == "blog" && wrap.UrlArgs[1] == "category" && wrap.UrlArgs[2] != "" {
  22. if o, ok := drow.(*utils.MySql_blog_category); ok {
  23. d_Blog = &Blog{wrap: wrap, category: &BlogCategory{wrap: wrap, object: o}}
  24. d_Blog.load()
  25. }
  26. } else if len(wrap.UrlArgs) == 2 && wrap.UrlArgs[0] == "blog" && wrap.UrlArgs[1] != "" {
  27. if o, ok := drow.(*utils.MySql_blog_post); ok {
  28. d_Blog = &Blog{wrap: wrap, post: &BlogPost{wrap: wrap, object: o}}
  29. }
  30. } else {
  31. d_Blog = &Blog{wrap: wrap}
  32. d_Blog.load()
  33. }
  34. }
  35. if d_Blog == nil {
  36. d_Blog = &Blog{wrap: wrap}
  37. }
  38. fer := &FERData{
  39. wrap: wrap,
  40. is404: is404,
  41. Page: d_Page,
  42. Blog: d_Blog,
  43. }
  44. return fer
  45. }
  46. func (this *FERData) RequestURI() string {
  47. return this.wrap.R.RequestURI
  48. }
  49. func (this *FERData) RequestURL() string {
  50. return this.wrap.R.URL.Path
  51. }
  52. func (this *FERData) RequestGET() string {
  53. return utils.ExtractGetParams(this.wrap.R.RequestURI)
  54. }
  55. func (this *FERData) Module() string {
  56. if this.is404 {
  57. return "404"
  58. }
  59. var mod string
  60. if this.wrap.CurrModule == "index" {
  61. mod = "index"
  62. } else if this.wrap.CurrModule == "blog" {
  63. if len(this.wrap.UrlArgs) == 3 && this.wrap.UrlArgs[0] == "blog" && this.wrap.UrlArgs[1] == "category" && this.wrap.UrlArgs[2] != "" {
  64. mod = "blog-category"
  65. } else if len(this.wrap.UrlArgs) == 2 && this.wrap.UrlArgs[0] == "blog" && this.wrap.UrlArgs[1] != "" {
  66. mod = "blog-post"
  67. } else {
  68. mod = "blog"
  69. }
  70. }
  71. return mod
  72. }
  73. func (this *FERData) DateTimeUnix() int {
  74. return int(time.Now().Unix())
  75. }
  76. func (this *FERData) DateTimeFormat(format string) string {
  77. return time.Unix(int64(time.Now().Unix()), 0).Format(format)
  78. }