Python ndb.Model
有一个方便的 _post_put_hook
,您可以在实体保存到数据存储后执行一些工作。
由于 Go 中的模型只是结构,如何支持此功能?
最佳答案
App 引擎数据存储操作将 PropertyLoadSaver
接口(interface)作为输入。例如,datastore.Put
具有以下签名:
func Put(c context.Context, key *Key, src interface{}) (*Key, error)
关于 src
的以下文档:
Put saves the entity src into the datastore with key k. src must be a struct pointer or implement PropertyLoadSaver
这意味着您可以围绕各种数据存储操作实现您自己的自定义行为。可以找到一个例子here .
关于google-app-engine - Go 中的 _post_put_hook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38845620/