GithubHelp home page GithubHelp logo

chikamif / fsevent Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ya5u/fsevent

0.0 0.0 0.0 53 KB

Eazy handling Cloud Firestore events on Google Cloud Functions Go Runtime.

License: MIT License

Go 100.00%

fsevent's Introduction

fsevent

Eazy handling Cloud Firestore events on Google Cloud Functions Go Runtime.

Description

Cloud Functions events triggered by Cloud Firestore are somewhat complex to handle.
GCP Documentation: Google Cloud Firestore Triggers
Receive fsevent as an event and you can use the same type definition for Cloud Firestore.

features

  • get event types - TypeCreate TypeUpdate or TypeDelete
  • reflect value in event to struct you defined for firestore

Installation

Minimum Go version: Go 1.11

Use go get to install and update:

$ go get -u github.com/ya5u/fsevent

Usage

Example Cloud Functions Code is below

package handler

import (
  "context"
  "time"

  "github.com/ya5u/fsevent"
)

// FsData is defined type for firestore as you like
type FsData struct {
  Name     string     `firestore:"name"`
  Age      int64      `firestore:"age"`
  Birthday *time.Time `firestore:"birthday"`
}

// Handler is the entry point of Cloud Functions triggered by firestore event
func Handler(ctx context.Context, e fsevent.FirestoreEvent) error {
  // get event type
  eventType := e.Type()

  // reflect updated value to struct you defined
  var updated FsData
  err := e.Value.DataTo(&updated)
  if err != nil {
    // error handling
  }

  // reflect old value to struct you defined
  var old FsData
  err = e.OldValue.DataTo(&old)
  if err != nil {
    // error handling
  }
}

TODO

  • support primitive pointer types
  • support Arrays
  • support Maps
  • support References
  • implement method of Value type like firestore.DocumentSnapshot.Data

Licence

MIT

Author

ya5u

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.