Files
pocket-id/backend/internal/model/base.go
Elias Schneider eaff977b22 initial commit
2024-08-12 11:24:22 +02:00

21 lines
361 B
Go

package model
import (
"github.com/google/uuid"
"gorm.io/gorm"
"time"
)
// Base contains common columns for all tables.
type Base struct {
ID string `gorm:"primaryKey;not null" json:"id"`
CreatedAt time.Time `json:"createdAt"`
}
func (b *Base) BeforeCreate(db *gorm.DB) (err error) {
if b.ID == "" {
b.ID = uuid.New().String()
}
return
}