blog_post.go 1.2 KB

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