You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.1 KiB

  1. package Database
  2. import (
  3. "time"
  4. "github.com/google/uuid"
  5. "gorm.io/gorm"
  6. )
  7. const (
  8. SubjectProgramming = "Programming"
  9. SubjectPentesting = "Pentesting"
  10. )
  11. // Base contains common columns for all tables
  12. type Base struct {
  13. ID uuid.UUID `gorm:"primaryKey;autoIncrement:false"`
  14. CreatedAt time.Time
  15. UpdatedAt time.Time
  16. DeletedAt time.Time
  17. }
  18. // BeforeCreate will set Base struct before every insert
  19. func (base *Base) BeforeCreate(tx *gorm.DB) error {
  20. // uuid.New() creates a new random UUID or panics.
  21. base.ID = uuid.New()
  22. // generate timestamps
  23. var t time.Time = time.Now()
  24. base.CreatedAt, base.UpdatedAt = t, t
  25. return nil
  26. }
  27. // AfterUpdate will update the Base struct after every update
  28. func (base *Base) AfterUpdate(tx *gorm.DB) error {
  29. // update timestamps
  30. base.UpdatedAt = time.Now()
  31. return nil
  32. }
  33. type Post struct {
  34. Base
  35. Title string `gorm:"type:varchar(256);"`
  36. Intro string
  37. HtmlPath string `gorm:"type:varchar(256);uniqueindex;"`
  38. Subject string `gorm:"type:varchar(256);"`
  39. MainImage string `gorm:"type:varchar(256);"`
  40. Body string `sql:"-"`
  41. }
  42. type SidebarLink struct {
  43. Base
  44. Name string
  45. Link string
  46. }