22 lines
365 B
Go
22 lines
365 B
Go
package entity
|
|
|
|
import (
|
|
"github.com/google/uuid"
|
|
"gorm.io/datatypes"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type Base struct {
|
|
Id string `json:"id" gorm:"primaryKey;type:varchar(36);not null;comment:'主键'"`
|
|
CreatedAt datatypes.Time
|
|
UpdatedAt datatypes.Time
|
|
}
|
|
|
|
func (b *Base) BeforeCreate(*gorm.DB) (err error) {
|
|
if b.Id == "" {
|
|
b.Id = uuid.NewString()
|
|
}
|
|
|
|
return
|
|
}
|