package models import ( "time" "github.com/google/uuid" "gorm.io/gorm" ) type ApiKey struct { ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;default:gen_random_uuid()"` Key string `json:"key" gorm:"not null;unique"` UserID *uuid.UUID `json:"user_id"` Revoked bool `json:"revoked" gorm:"not null;default:false"` ExpiresAt *time.Time `json:"expires_at"` CreatedAt time.Time `json:"created_at" gorm:"not null;default:now()"` UpdatedAt time.Time `json:"updated_at" gorm:"not null;default:now()"` DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index;default:null"` // Relationships User *User `json:"user" gorm:"foreignKey:user_id;references:id"` } func (a *ApiKey) TableName() string { return "api_keys" } func (a *ApiKey) BeforeCreate(tx *gorm.DB) (err error) { a.ID = uuid.New() return }