google-app-engine - 在 appspot.com 上解析 64 位 int 与在本地主机上不同?

标签 google-app-engine go

当您尝试在 JavaScript (parseInt("5838406743490560")) 中解析 64 位整数时,它可以在本地主机服务器上运行,但不能在 Appspot.com 服务器上运行。在 appspot.com 服务器上,您需要将其解析为字符串而不是 int64。有谁知道这是为什么吗?

在本地主机上我可以这样做:

type Entity struct {
    List []*Message `json:"list"`
}

type Message struct {
    Id int64 `json:"id" datastore:"-"`
}

将其上传到 appspot.com 后,我需要将其解析为字符串,否则会收到以下错误消息。

type Entity struct {
    List []*Message `json:"list"`
}

type Message struct {
    Id int64 `json:"id,string" datastore:"-"`
}

发送到 id=parseInt("5838406743490560") 的包:

[{"jsonrpc":"2.0","id":"gapiRpc","method":"service.datastore.delete","apiVersion":"v0","params":{"list":[{"id":5838406743490560}]}}]
  • 在 Appspot.com 上,我无法使用 json:"id"datastore:"-" 解码。

  • 在本地主机上运行完美。

仅在 Appspot.com 上出错:

[
 {
  "error": {
   "code": 400,
   "message": "json: cannot unmarshal string into Go value of type int64",
   "data": [
    {
     "domain": "global",
     "reason": "badRequest",
     "message": "json: cannot unmarshal string into Go value of type int64"
    }
   ]
  },
  "id": "gapiRpc"
 }
]

我正在使用 SDK v1.9.6。

最佳答案

我的本​​地主机在 64 位环境中运行,appspot.com 在 32 位环境中运行。所有比 2147483647 小的数字都可以解析,但尽管定义为 int64,但 id 5838406743490560 太大以适应 32 位,因此它在 appspot.com 实例上被解析为字符串。

关于google-app-engine - 在 appspot.com 上解析 64 位 int 与在本地主机上不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24441960/

相关文章:

google-app-engine - 没有路由器 Gorilla Mux 的 Google Cloud Go 处理程序?

java - Google App Engine - 生成二维码

java - 使用 maven 的带有 struts2、spring 和 JPA 的谷歌应用程序引擎

api - Web api 将名称和密码设置为 request.BasicAuth

pointers - 如何在双链表中获取元素值的指针(go-lang)

go - function赋值给一个Underscores,什么意思

java - 为服务媒体项目(照片、mp3、文档等)生成 key 的最佳实践

java - Google Cloud sql 和 Google 应用引擎

戈朗 : Can I apply helper function to one of the returned arguments

go - 如何在 Go 中创建不固定长度的 slice