go.uuid
go.uuid copied to clipboard
uuid: cannot convert uuid.UUID to UUID
I have the following struct
type Identity struct {
gormsupport.Lifecycle
// Link to User
UserID uuid.NullUUID `sql:"type:uuid"`
User User
}
and
identity := account.Identity{
User: user,
UserID: uuid.NullUUID{UUID: uuid.NewV4(), Valid: true},
}
err := s.identityRepo.Create(context.Background(), &identity)
and this is the Create
method being called
// Create creates a new record.
func (m *GormIdentityRepository) Create(ctx context.Context, model *Identity) error {
defer goa.MeasureSince([]string{"goa", "db", "identity", "create"}, time.Now())
if model.ID == uuid.Nil {
model.ID = uuid.NewV4()
}
err := m.db.Create(model).Error
if err != nil {
log.Error(ctx, map[string]interface{}{
"identity_id": model.ID,
"err": err,
}, "unable to create the identity")
return errs.WithStack(err)
}
The line m.db.Create(model).Error
is failing with cannot convert uuid.UUID to UUID
Any update on this issue?
How to solve this issue for now? I have seen this erros
type struct Me {
ID uuid.UUID
}
...
if Me.ID != nil {
// cannot convert untyped nil to uuid.UUID
}
Happen even with uuid.NullUUID
I solve it using pointer so it could be a nil