21 lines
346 B
Go
21 lines
346 B
Go
|
package db
|
||
|
|
||
|
import (
|
||
|
"time"
|
||
|
|
||
|
uuid "github.com/satori/go.uuid"
|
||
|
"gorm.io/gorm"
|
||
|
)
|
||
|
|
||
|
type Base struct {
|
||
|
ID *uuid.UUID `gorm:"type:uuid;primary_key" json:"id"`
|
||
|
CreatedAt time.Time `json:"created_at"`
|
||
|
UpdatedAt time.Time `json:"updated_at"`
|
||
|
}
|
||
|
|
||
|
func (b *Base) BeforeCreate(_ *gorm.DB) error {
|
||
|
id := uuid.NewV4()
|
||
|
b.ID = &id
|
||
|
return nil
|
||
|
}
|