I am trying to create a wrapper around my Kinds and here is how I am doing it:
package model
import (
"time"
)
type Kind interface {
Name() string
}
type Message struct {
Text string
CreatedOn time.Time
UserId string
}
func (q Message) Name() string {
return "MESSAGE"
}
And the reason I introduced type Kind interface
is:
// Stores the given model for the the kind in data store
func Store(req *http.Request, data Kind) error {
ctx := appengine.NewContext(req)
key := datastore.NewKey(ctx, data.Name(), "", 0, nil)
_, err := datastore.Put(ctx, key, &data)
return err
}
As you can see, I am using data.Name()
to get the kinds name.
When I try to save the data, it complains about:
datastore: invalid entity type
I read that this could be due to not passing the reference to datastore.Put
, but I am doing that. Any idea?
I must add that when I checked the type of data (using reflect.TypeOf()
), it is model.Message
which is correct too. So it is a concrete type.