Skip to content

Instantly share code, notes, and snippets.

@frikky
Created November 20, 2019 09:39
Show Gist options
  • Save frikky/bf670cfc8b4c956dd1d0ff5a08b6a9de to your computer and use it in GitHub Desktop.
Save frikky/bf670cfc8b4c956dd1d0ff5a08b6a9de to your computer and use it in GitHub Desktop.
As you can see, this is way less code than rollback.go
import "github.com/frikky/firestore-rollback-go"
// This is our self-defined fields.
// FirestoreEvent.Value.Fields = User
type User struct {
Username rollback.StringValue `json:"userId"`
Email rollback.StringValue `json:"email"`
DateEdited rollback.IntegerValue `json:"date_edited"`
}
// Handles the rollback of any previous document
func handleRollback(ctx context.Context, e FirestoreEvent) error {
// writtenData, firestoreReturn, err :=
_, _, err := rollback.Rollback(
ctx,
client, // Your firestore client
e.OldValue.Name, // The path to roll back
e.OldValue.Fields, // The parsed data you have
)
return err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment