I'm trying to setup a cloud function trigger by firestore, and just use google's sample code https://cloud.google.com/functions/docs/calling/cloud-firestore
I just want to print log for document write event, and i only change that function's name
I deploy go file like this
gcloud functions deploy HelloLogger --runtime go111 --trigger-event providers/cloud.firestore/eventTypes/document.write --trigger-resource projects/[my project id]/databases/default/documents/post/{pushId}
Database looks like this : https://imgur.com/3LSldnK
and the function page : https://imgur.com/vW5KiJX
I create new document and to some update, buy my HelloLogger not logging any message
what went wrong in my function?
EDIT:
fallowing are the sample code I use, almost nothing change
package logger
import (
"context"
"fmt"
"log"
"time"
"cloud.google.com/go/functions/metadata"
)
// FirestoreEvent is the payload of a Firestore event.
type FirestoreEvent struct {
OldValue FirestoreValue `json:"oldValue"`
Value FirestoreValue `json:"value"`
UpdateMask struct {
FieldPaths []string `json:"fieldPaths"`
} `json:"updateMask"`
}
// FirestoreValue holds Firestore fields.
type FirestoreValue struct {
CreateTime time.Time `json:"createTime"`
// Fields is the data for this value. The type depends on the format of your
// database. Log the interface{} value and inspect the result to see a JSON
// representation of your database fields.
Fields interface{} `json:"fields"`
Name string `json:"name"`
UpdateTime time.Time `json:"updateTime"`
}
// HelloFirestore is triggered by a change to a Firestore document.
func HelloLogger(ctx context.Context, e FirestoreEvent) error {
meta, err := metadata.FromContext(ctx)
if err != nil {
return fmt.Errorf("metadata.FromContext: %v", err)
}
log.Printf("Function triggered by change to: %v", meta.Resource)
log.Printf("Old value: %+v", e.OldValue)
log.Printf("New value: %+v", e.Value)
return nil
}