Encrypted messaging app
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.

27 lines
428 B

  1. package Models
  2. import (
  3. "github.com/gofrs/uuid"
  4. "gorm.io/gorm"
  5. )
  6. // Base contains common columns for all tables.
  7. type Base struct {
  8. ID uuid.UUID `gorm:"type:uuid;primary_key;" json:"id"`
  9. }
  10. // BeforeCreate will set a UUID rather than numeric ID.
  11. func (base *Base) BeforeCreate(tx *gorm.DB) error {
  12. var (
  13. id uuid.UUID
  14. err error
  15. )
  16. id, err = uuid.NewV4()
  17. if err != nil {
  18. return err
  19. }
  20. base.ID = id
  21. return nil
  22. }