Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to put my struct to datastore (golang)

here is my struct:

type AreaPrerequisite struct {
    SideQuestId   int // 
    SideQuestProg int // progress
}

type AreaInfo struct {
    Id                int              `datastore:""`
    Name              string           `datastore:",noindex"`
    ActionPoint       int              `datastore:",noindex"`
    Prerequisite      AreaPrerequisite `datastore:",noindex"`

    // ignored:
    DsMonsters        []byte           `datastore:"-"`
    DsStages          []byte           `datastore:"-"`
    Monsters          AreaMonsters     `datastore:"-"`
    Stages            []*StageEntry    `datastore:"-"`
}

and my put() call:

key := datastore.NewKey(c, "Area", "", int64(pArea.Id), nil)
_, err := datastore.Put(c, key, *pArea)
if err != nil {
    return err
}

It gives me the following error when try to put to DS:

datastore: invalid entity type

I checked the doc: https://developers.google.com/appengine/docs/go/datastore/reference

datastore:"-" should mark some non-supported fields ignored by datastore. Don't know why it is failing.

like image 674
Nick Avatar asked Aug 16 '13 16:08

Nick


1 Answers

I found that I accidentally added * to pArea as arg to put() so it is passing a value instead of pointer, causing invalid entity type error.

like image 179
Nick Avatar answered Oct 20 '22 12:10

Nick