将Python GAE db.GeoPt转换为Go类型是否可能?

huangapple go评论85阅读模式
英文:

Is it possible to port Python GAE db.GeoPt to a Go type?

问题

我正在将一个原本用Python编写的GAE应用程序移植到Go语言。到目前为止,进展还不错,而且相对容易(尽管也有一些小问题)。

由于这个移植版本将部署到同一个GAE应用程序的不同版本中,所以两个版本将共享同一个数据存储。问题是原始的Python应用程序广泛使用了db.GeoPt类型。

我在我的某个类型上实现了自定义的PropertyLoadSaver,以便通过反射来查看如何在Go中表示db.GeoPt。但显然,db.GeoPt的内存布局与Go中的任何内容都不兼容。有人知道我该如何解决这个问题吗?有人以前做过这个吗?

以下是一些代码,以便更好地理解我的做法:

func (sS *SomeStruct) Load(c <-chan datastore.Property) error {
    for p := range c {
        if p.Name == "location" { // "location"是原始db.GeoPt属性的名称
            v := reflect.ValueOf(p.Value) // 如果我调用v.Kind(),它会返回reflect.Invalid
            // 是的,我知道v被声明了但从未使用过:P
        }
    }
    return nil
}

提前感谢你的帮助!

英文:

I'm working on a porting an existing GAE app that was originally written in Python to Go. So far it's been pretty great and reasonably easy (though it's not been without its quirks).

Since this port will be deployed to the same GAE app on a different version, the two versions will share the same datastore. The problem is that the original Python app makes extensive use of the db.GeoPt type.

I implemented my own custom PropertyLoadSaver on one of my types so I could look at how I might represent a db.GeoPt in Go, via reflection. But apparently the memory layout of db.GeoPt is not compatible with anything in Go at all. Does anybody know how I might go about this? Has anybody done this before?

Here's some code to give you guys a better idea of what I'm doing:

<!-- language: lang-go -->

func (sS *SomeStruct) Load(c &lt;-chan datastore.Property) error {
    for p := range c {
        if p.Name == &quot;location&quot; { // &quot;location&quot; is the name of the original db.GeoPt property
            v := reflect.ValueOf(p.Value) // If I call v.Kind(), it returns reflect.Invalid
            // And yes, I know v is declared and never used :P
        }
    }
    return nil
}

Thank you in advance!

答案1

得分: 2

appengine/datastore中添加了对appengine.GeoPoint的支持,该功能在1.9.3版本的App Engine发布中引入。

英文:

appengine.GeoPoint support in appengine/datastore was added in the 1.9.3 App Engine release.

huangapple
  • 本文由 发表于 2014年3月27日 11:08:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/22677507.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定