在OSX上重新启动后,本地GAE数据存储为空。

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

Local GAE Datastore is empty after restart on OSX

问题

我正在使用Go后端+Polymer前端构建一个Google App Engine应用程序。因此,我正在使用dispatch.yaml文件同时提供两者。

我面临的问题是,当我重新启动计算机时,数据存储为空。我在OSX 10.9.5和10.10.4上都进行了测试,两者在系统重启后都表现出相同的响应。然而,Windows 7似乎保留了数据。

文档建议数据应该持久存在,因为我没有显式调用clear。但实际上并没有。我尝试使用以下命令自己设置数据存储位置:

dev_appserver.py --datastore_path=~/go_apps/data ~/go_apps/my_app

我收到以下错误:

google.appengine.tools.devappserver2.errors.AppConfigNotFoundError: "/Users/anthony/go_apps/my_app是一个目录,但不包含app.yaml或app.yml"

显然,由于我使用了dispatch.yaml文件,它不会包含这些文件。因此,由处理数据的后端确实有一个app.yaml文件,我尝试在那里设置它。我使用以下命令:

dev_appserver.py --datastore_path=~/go_apps/data ~/go_apps/my_app/backend

这似乎也不起作用,因为我收到以下错误:

sqlite3.OperationalError: 无法打开数据库文件

好吧,现在不确定该去哪里了。从其他帖子中我了解到,数据是临时存储的。但是,我似乎无法设置自定义的非临时位置来存储数据。所以,现在每次重新启动时我都要填充数据存储,这似乎很荒谬。

*** 编辑 ***

我尝试了以下操作,它似乎尝试启动应用程序,并在正确的位置创建了一个datastore.db文件:

dev_appserver.py --datastore_path ~/go_apps/my_app/data/datastore.db ~/go_apps/my_app/dispatch.yaml ~/go_apps/my_app/backend/app.yaml ~/go_apps/my_app/frontend/app.yaml

然而,我现在遇到了一个奇怪的错误:

/var/folders/04/3hxnpxc15wj2k4v40lkdncd00000gn/T/tmpkcQYnFappengine-go-bin/backend.go:13: 找不到导入: "github.com/gorilla/mux"

Go是否临时构建到该文件夹中?该导入肯定是可用的,并且始终可以通过调用goapp serve进行正常构建。

这是我的backend.go文件中的导入部分:

import (
//标准库
"fmt"
"net/http"
"time"
"log"

//第三方
"github.com/gorilla/mux"
"github.com/gorilla/securecookie"
"github.com/dgrijalva/jwt-go"
"golang.org/x/crypto/bcrypt"

//我的导入
"github.com/section14/go_polymer_comm_pkg/controller"

)

英文:

I'm building a Google App Engine application with a Go backend + Polymer frontend. As a result, I'm using a dispatch.yaml file to serve both at the same time.

The problem I'm facing is that the datastore is empty when I restart my computer. I've tested this on both OSX 10.9.5 and 10.10.4. Both exhibit the same response upon a system reboot. Windows 7, however, seems to hold on to the data.

The documentation suggests that data should persist, since I'm not explicitly calling a clear. It's not. I've tried to set the datastore location myself using this:

dev_appserver.py --datastore_path=~/go_apps/data ~/go_apps/my_app

I'm receiving this error:

google.appengine.tools.devappserver2.errors.AppConfigNotFoundError: "/Users/anthony/go_apps/my_app is a directory but does not contain app.yaml or app.yml

Obviously, since I'm using a dispatch.yaml file, it wouldn't. So, since the backend, which handles the data, does have an app.yaml file, I try to set it there. I use this command:

dev_appserver.py --datastore_path=~/go_apps/data ~/go_apps/my_app/backend

That doesn't seem to work either, as I get this error:

sqlite3.OperationalError: unable to open database file

Okay? Well, not sure where to turn now. From what I could gather from other posts, that data is stored temporarily. But, I can't seem to set a custom, non-temporary location for the data. So, now I'm populating a datastore every time I reboot, which seems ridiculous.

*** Edit ***

I've tried the following, which seems like it tries to launch the app, and creates a datastore.db file at the correct location:

dev_appserver.py --datastore_path ~/go_apps/my_app/data/datastore.db  ~/go_apps/my_app/dispatch.yaml ~/go_apps/my_app/backend/app.yaml ~/go_apps/my_app/frontend/app.yaml

However, I'm getting a weird error now:

/var/folders/04/3hxnpxc15wj2k4v40lkdncd00000gn/T/tmpkcQYnFappengine-go-bin/backend.go:13: can't find import: "github.com/gorilla/mux"

Does Go build to that folder temporarily? That import is definitely available, and always builds fine calling goapp serve.

Here is what my imports look like on backend.go

import (
    //standard library
    "fmt"
    "net/http"
    "time"
    "log"

    //third party
    "github.com/gorilla/mux"
    "github.com/gorilla/securecookie"
    "github.com/dgrijalva/jwt-go"
    "golang.org/x/crypto/bcrypt"

    //my imports
    "github.com/section14/go_polymer_comm_pkg/controller"
)

答案1

得分: 3

你必须传递要用作持久化数据存储的文件的名称,而不是文件夹。

然后提供你的应用程序文件夹(其中包含app.yaml)。不要混淆这两者。所以应该是这样的:

dev_appserver.py --datastore_path=~/my_app/my_app.db ~/go_apps/my_app

详细信息可以在这里找到:

Go开发服务器/使用数据存储

注意:

默认的数据存储文件位于临时文件夹中,你的OS-X很可能在系统重启时清除该文件夹,这就是为什么它不能被保留下来的原因。另一方面,例如Windows 7在系统重启时不会清除临时文件夹。

英文:

You have to pass the name of the file to be used as the persisted datastore, not a folder.

And next provide the folder of your app (which contains app.yaml). Don't mix the 2. So it should be something like:

dev_appserver.py --datastore_path=~/my_app/my_app.db ~/go_apps/my_app

Details can be found here:

The Go Development Server / Using the Datastore

Notes:

The default datastore file is in the temp folder, and your OS-X most likely clears that on system restart, that's why it is not preserved for you. On the other hand Windows 7 for example does not clear the temp folder on system restarts.

答案2

得分: 1

通过将GOPATHGOROOT环境变量添加到我的.bash_profile文件中,我成功地启动了它。总共需要这三个路径(第一个路径已经设置好)才能运行:

# 添加Google AppEngine路径
export PATH=/Users/anthony/go_appengine:$PATH

# GOPATH
export GOPATH=/Users/anthony/go_appengine/gopath
export PATH=$PATH:$GOPATH

# GOROOT
export GOROOT=/Users/anthony/go_appengine/goroot
export PATH=$PATH:$GOROOT

要启动该命令,需要在项目文件夹内部(我的项目文件夹位于appengine文件夹外部)执行以下命令:

dev_appserver.py --datastore_path data/datastore.db  dispatch.yaml backend/app.yaml frontend/app.yaml

请注意,.yaml文件仍然存在。如果不需要dispatch.yaml文件,它可以正常构建,也可以在没有这些文件的情况下正常构建。

感谢@icza的指导。为了方便阅读,我想将这些步骤整理在一篇帖子中。

英文:

Got it up and running by adding both GOPATH and GOROOT environment variables to my .bash_profile. In total, these three paths (first path was already set) are needed for it to run:

# Add Google AppEngine path
export PATH=/Users/anthony/go_appengine:$PATH

# GOPATH
export GOPATH=/Users/anthony/go_appengine/gopath
export PATH=$PATH:$GOPATH

# GOROOT
export GOROOT=/Users/anthony/go_appengine/goroot
export PATH=$PATH:$GOROOT

This command is called from inside the project folder (mine resides outside of the appengine folder) for it to launch:

dev_appserver.py --datastore_path data/datastore.db  dispatch.yaml backend/app.yaml frontend/app.yaml

Notice that the .yaml files are still there. It builds fine with them, and probably builds fine without them if you don't need a dispatch.yaml file.

Thanks @icza for the direction. Wanted to organize the steps in a post for easier reading.

huangapple
  • 本文由 发表于 2015年8月17日 05:46:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/32040244.html
匿名

发表评论

匿名网友

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

确定