blog_post.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package fetdata
  2. import (
  3. "html/template"
  4. "time"
  5. "golang-fave/engine/wrapper"
  6. "golang-fave/utils"
  7. )
  8. type BlogPost struct {
  9. wrap *wrapper.Wrapper
  10. object *utils.MySql_blog_post
  11. user *User
  12. }
  13. func (this *BlogPost) Id() int {
  14. if this == nil {
  15. return 0
  16. }
  17. return this.object.A_id
  18. }
  19. func (this *BlogPost) User() *User {
  20. if this == nil {
  21. return nil
  22. }
  23. if this.user != nil {
  24. return this.user
  25. }
  26. this.user = &User{wrap: this.wrap}
  27. this.user.load(this.object.A_user)
  28. return this.user
  29. }
  30. func (this *BlogPost) Name() string {
  31. if this == nil {
  32. return ""
  33. }
  34. return this.object.A_name
  35. }
  36. func (this *BlogPost) Alias() string {
  37. if this == nil {
  38. return ""
  39. }
  40. return this.object.A_alias
  41. }
  42. func (this *BlogPost) Briefly() template.HTML {
  43. if this == nil {
  44. return template.HTML("")
  45. }
  46. return template.HTML(this.object.A_briefly)
  47. }
  48. func (this *BlogPost) Content() template.HTML {
  49. if this == nil {
  50. return template.HTML("")
  51. }
  52. return template.HTML(this.object.A_content)
  53. }
  54. func (this *BlogPost) DateTimeUnix() int {
  55. if this == nil {
  56. return 0
  57. }
  58. return this.object.A_datetime
  59. }
  60. func (this *BlogPost) DateTimeFormat(format string) string {
  61. if this == nil {
  62. return ""
  63. }
  64. return time.Unix(int64(this.object.A_datetime), 0).Format(format)
  65. }
  66. func (this *BlogPost) Active() bool {
  67. if this == nil {
  68. return false
  69. }
  70. return this.object.A_active > 0
  71. }
  72. func (this *BlogPost) Permalink() string {
  73. if this == nil {
  74. return ""
  75. }
  76. return "/blog/" + this.object.A_alias + "/"
  77. }