Created
January 19, 2019 11:06
-
-
Save feloy/4928c663cdfddf2a470679d9df122fd6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Package p contains a Firestore Cloud Function. | |
package p | |
import ( | |
"context" | |
"fmt" | |
"log" | |
"cloud.google.com/go/functions/metadata" | |
) | |
// FirestoreEvent is the payload of a Firestore event. | |
// Please refer to the docs for additional information | |
// regarding Firestore events. | |
type FirestoreEvent struct { | |
OldValue FirestoreValue `json:"oldValue"` | |
Value FirestoreValue `json:"value"` | |
} | |
// FirestoreValue holds Firestore fields. | |
type FirestoreValue struct { | |
Fields interface{} `json:"fields"` | |
} | |
// OnNewScore is triggered by a change to a Firestore document. | |
func OnNewScore(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("%v", e) | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment