Files
platform/web/core/model.go
2026-04-16 14:24:59 +08:00

30 lines
588 B
Go

package core
import (
"platform/pkg/u"
"time"
"gorm.io/gorm"
)
type IModel interface {
GetID() int32
}
type Model struct {
ID int32 `json:"id,omitzero" gorm:"column:id;primaryKey"`
CreatedAt time.Time `json:"created_at,omitzero" gorm:"column:created_at"`
UpdatedAt time.Time `json:"updated_at,omitzero" gorm:"column:updated_at"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"column:deleted_at"`
}
func (m *Model) GetID() int32 {
return m.ID
}
func GetIDs[T IModel](models []T) []int32 {
return u.Map(models, func(m T) int32 {
return m.GetID()
})
}