我第一次使用谷歌云环境,特别是谷歌应用引擎和数据存储,当我在本地运行时一切正常。我通过按照文档设置环境变量 GOOGLE_APPLICATION_CREDENTIALS 对数据存储进行身份验证。但是一旦我部署到应用程序引擎,请求总是超时,似乎 GetAll 方法永远不会返回。以下是我的应用程序的代码:
package app
import (
"fmt"
"net/http"
"time"
"golang.org/x/net/context"
"google.golang.org/appengine"
"google.golang.org/cloud/datastore"
)
type User struct {
FirstName string
LastName string
Email string
Created time.Time
id int64
}
func init() {
http.HandleFunc("/", handler)
}
func handler(w http.ResponseWriter, r *http.Request) {
var err error
var dbClient *datastore.Client
var ctx context.Context
ctx = appengine.NewContext(r)
dbClient, err = datastore.NewClient(ctx, "app-id")//this has the real app id, not sure if this is meant to be secret
if err != nil {
fmt.Fprintf(w, "Could not create datastore client: %+v", err)
return
}
defer dbClient.Close()
var users []*User
query := datastore.NewQuery("User").Filter("Email=", "jcarm010@fiu.edu")
keys, err := dbClient.GetAll(ctx, query, &users)
if err != nil {
fmt.Fprintf(w, "Could not query users: %+v", err)
return
}
for i, key := range keys {
users[i].id = key.ID()
fmt.Fprintf(w, "%+v\n",users[i])
}
fmt.Fprintf(w, "done!!!")
}
App Engine 日志中的错误有以下两行:
This request caused a new process to be started for your application, and thus caused your application code to be loaded for the first time. This request may thus take longer and use more CPU than a typical request for your application.
Process terminated because the request deadline was exceeded. (Error code 123)
顺便说一句,这在我的本地快速完成,并且我的数据存储中只有一条记录。关于为什么会发生这种情况或如何调试它的任何猜测?谢谢
吃鸡游戏
慕村9548890
数据表的存储引擎
什么是数据表的存储引擎
储存引擎是什么
angular里使用service存储数据和sessionstorage存储数据的区别?
相关分类