Golang - Appengine datastore filter query with []byte comparison

血红的双手。 提交于 2019-12-05 10:33:16

The answer to your main question is No, because []byte is stored as blob, which is not indexed by the app engine datastore.

queries with a filter or sort order on the unindexed property 
will never match that entity.
Note: In addition to any unindexed properties you declare explicitly, 
those typed as []byte are automatically treated as unindexed.

Here is the documentation: https://developers.google.com/appengine/docs/go/datastore/indexes#Go_Unindexed_properties

In 1.9.11, the ByteString type was introduced to the datastore package. It can be used for storing short, indexed byte slices.

If you change your entity to the following, it should work:

type Data struct {
  ID      int64                `json:"id"`
  Version int32                `json:"-"`
  HMAC    datastore.ByteString `json:"-"`
  Status  string               `json:"status"`
}

More info: https://developers.google.com/appengine/docs/go/datastore/entities#Go_Properties_and_value_types

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!