如何在Google App Engine for Go中设置数据固定装置

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

How to setup data fixtures in Google App Engine for Go

问题

我想在部署我的Go项目时将一些数据固定放入数据存储中,类似于Django中可以做的那样。这可能吗?如果不行,有没有其他替代方案?

英文:

I would like to have some data fixtures put into data store when my go project is deployed, similar to what can be done in Django. Is it possible? If not, are there any alternatives?

答案1

得分: 1

如果你正在寻找一些将数据放入数据存储的配置,答案是否定的。AppEngine的Python和Java版本也没有这样的功能。

我认为AppEngine的Django框架所做的与你可以做的是一样的。

只需在你的应用程序的init方法中将所需的数据写入数据存储中,同时在init方法中检查数据是否已经写入。

然后,每次应用程序启动时,它都会检查是否应该将一些固定数据写入数据存储,并且你可以确保在处理第一个请求之前它已经存在。

英文:

if your are looking for some configuration to put data into datastore, the answer is no. also the python and java versions of appengine don't have such feature.

what i think the django framework for appengine is doing, is the same as you could do.

just write the data you need to the datastore inside your app init method
also inside init you check if the data is already written.

then any time the app is startet, he checks if it should write some fixture data to datastore, and you can be sure that before first request is processed that its there.

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

发表评论

匿名网友

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

确定