gorm enum
package model
import (
"time"
"github.com/google/uuid"
"github.com/jinzhu/gorm"
)
type roleAccess string
const (
admin roleAccess = "admin"
supplier roleAccess = "supplier"
)
type ModelRole struct {
ID string `json:"id" gorm:"primary_key"`
Type string `json:"type" gorm:"type:varchar"`
Access string `json:"access" sql:"type:roleAccess"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (m *ModelRole) BeforeCreate(db *gorm.DB) error {
m.ID = uuid.NewString()
m.CreatedAt = time.Now()
return nil
}
func (m *ModelRole) BeforeUpdate(db *gorm.DB) error {
m.ID = uuid.NewString()
m.UpdatedAt = time.Now()
return nil
}