在golang google云后端函数中获取参数

在golang google云后端函数中获取参数,go,google-cloud-firestore,google-cloud-functions,Go,Google Cloud Firestore,Google Cloud Functions,在Go Google Cloud后台函数中,我想从Firestore事件访问参数 指出两个对象-ctx和Event被传递到后台函数entrypoint。 Event应该能够处理将要接收的特定事件的json.Unmarshal() 利用这些知识,将事件结构记录为 { "oldValue": { // Update and Delete operations only A Document object containing a pre-operation document

在Go Google Cloud后台函数中,我想从Firestore事件访问参数

指出两个对象-
ctx
Event
被传递到后台函数entrypoint。
Event
应该能够处理将要接收的特定事件的json.Unmarshal()

利用这些知识,将事件结构记录为

{
    "oldValue": { // Update and Delete operations only
        A Document object containing a pre-operation document snapshot
    },
    "updateMask": { // Update operations only
        A DocumentMask object that lists changed fields.
    },
    "value": {
        // A Document object containing a post-operation document snapshot
    }
}
但它还声明,
通配符匹配从文档路径中提取并存储在event.params中。您可以定义任意多个通配符来替换显式集合或文档ID。

因此,根据上面的内容,我可能应该添加如下内容

Params map[string]string `json:"params"`

到我的用于解码事件的结构。不幸的是,这不起作用。欢迎提供有关如何从Golang后台函数中的firestore事件访问这些命名参数的任何提示。

您可以获取事件完整路径,然后按
'/documents'
将其拆分,然后再次拆分以查找参数值:

path := strings.Split(e.Value.Name, "/documents/")[1]
parts := strings.Split(path, "/")

文档不太清楚,但似乎这是从golang访问参数的唯一方法。

您可以获取事件完整路径,然后通过
“/documents”
将其拆分,然后再次拆分以找到参数值:

path := strings.Split(e.Value.Name, "/documents/")[1]
parts := strings.Split(path, "/")

文档不是很清楚,但似乎这是从golang访问params的唯一方法。

您尝试过:
params-map[string]接口{}`json:`params`
?您尝试过:
params-map[string]接口{}`json:`params`