fetdata.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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{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{object: o}}
  24. d_Blog.init()
  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{object: o}}
  29. d_Blog.init()
  30. }
  31. } else {
  32. d_Blog = &Blog{wrap: wrap}
  33. d_Blog.init()
  34. }
  35. }
  36. if d_Blog == nil {
  37. d_Blog = &Blog{wrap: wrap}
  38. }
  39. fer := &FERData{
  40. wrap: wrap,
  41. is404: is404,
  42. Page: d_Page,
  43. Blog: d_Blog,
  44. }
  45. return fer
  46. }
  47. func (this *FERData) RequestURI() string {
  48. return this.wrap.R.RequestURI
  49. }
  50. func (this *FERData) RequestURL() string {
  51. return this.wrap.R.URL.Path
  52. }
  53. func (this *FERData) RequestGET() string {
  54. return utils.ExtractGetParams(this.wrap.R.RequestURI)
  55. }
  56. func (this *FERData) Module() string {
  57. if this.is404 {
  58. return "404"
  59. }
  60. var mod string
  61. if this.wrap.CurrModule == "index" {
  62. mod = "index"
  63. } else if this.wrap.CurrModule == "blog" {
  64. if len(this.wrap.UrlArgs) == 3 && this.wrap.UrlArgs[0] == "blog" && this.wrap.UrlArgs[1] == "category" && this.wrap.UrlArgs[2] != "" {
  65. mod = "blog-category"
  66. } else if len(this.wrap.UrlArgs) == 2 && this.wrap.UrlArgs[0] == "blog" && this.wrap.UrlArgs[1] != "" {
  67. mod = "blog-post"
  68. } else {
  69. mod = "blog"
  70. }
  71. }
  72. return mod
  73. }
  74. func (this *FERData) DateTimeUnix() int {
  75. return int(time.Now().Unix())
  76. }
  77. func (this *FERData) DateTimeFormat(format string) string {
  78. return time.Unix(int64(time.Now().Unix()), 0).Format(format)
  79. }