Given the following interface
type Entity interface {
Key() *datastore.Key
Uuid() uuid.UUID
CreatedOn() time.Time
}
This is what I want:
func NewAccount(uuid uuid.UUID, owner *person.Person, createdOn time.Time) *Account {
key := datastore.NameKey(KIND, uuid.String(), owner.Key()) //<- this complains with "Cannot use 'owner.Key()' (type datastore.Key) as type *Key"
return &Account{key: key, Owner: *owner, createdOn: createdOn.UTC().Format(time.RFC3339Nano)}
}
But it complains about ownerKey
when I try and pass it to datastore.NameKey
with
“Cannot use ‘owner.Key()’ (type datastore.Key) as type *Key”
I can get it to stop complaining with:
func NewAccount(uuid uuid.UUID, owner *person.Person, createdOn time.Time) *Account {
ownerKey := owner.Key()
key := datastore.NameKey(KIND, uuid.String(), &ownerKey)
return &Account{key: key, Owner: *owner, createdOn: createdOn.UTC().Format(time.RFC3339Nano)}
}
I have tried everything I can trying to get it to stop complaining with what I have read but I can not get the mix of ()/&/*
to satisfy it inline
.
What is the magical incantation to get this to reference/dereference inline instead of having to use an intermediate variable?
PS: this is using the google cloud datastore and it requires the *datastore.Key