function

package module
v0.0.0-...-f05bedb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2021 License: MIT Imports: 7 Imported by: 0

README

Firebase Project Template for Go

Go Report Card Go Doc

A "just works" template for a Firebase project: clone, run locally and deploy to Cloud. Contains Cloud Functions, Firestore Rules/Indexes and other stuff.

Getting Started

Prerequisites
  • Install Go language, v1.13 is used
  • Install Google Cloud SDK for running gcloud
  • Be able to use the Make tool
Installing

Not needed, runs as is, just clone: $ cd my_projects_or_smth
$ git clone https://github.com/dibikhin/firebase-template-go.git $ cd firebase-template-go

Running the tests

$ make test
> Testing...

Running Functions Locally

Build --> start --> navigate.

Build

$ make build
> Building...

Start

$ make run
> Listening on http://localhost:8080 ...

Or just

$ make && make run

Navigate

http://localhost:8080

Deployment

Running Functions remotely

Deploy to Google Cloud

$ ./deploy

Navigate

https://<region>-<project>.cloudfunctions.net/Hello -> "Hey there!" and server timestamp

Delete Function

$ ./deployments/delete

Project Structure

  • /cmd — Running locally
    • /firestore
    • /https
  • /deployment — Managing Functions deployments
  • /internal — Cloud Functions by triggers
    • /firestore
    • /https
  • firestore.indexes.json — Firestore Indexes
  • firestore.rules — Firestore Security Rules
  • function.go — Entry point
  • Makefile — Test, build, run, clean
  • storage.rules — Storage Security Rules

TODOs

  • DONE Add Go badges
  • DONE Reorder files to /cmd, /deployments, /internal
  • DONE Wrap HelloWorld -> Hello
  • DONE Move /scripts to Makefile partially
  • DONE Improve README.md
  • NEXT Add a Cloud function
  • Update the HTTPS function to worker?
  • Add a local worker?
  • Add pre-commit:
    • clean
    • lint, etc.
  • Customize deploying selected function
  • Add dependency injection
  • Add generation by template for HTTPS functions
  • Add loading service keys from env/files
  • Split envs for:
    • indexes and rules
    • functions

Contributing

  • TBD

Versioning

  • TBD

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Many thanks to enthusiasts and authors of official docs:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hello

func Hello(w http.ResponseWriter, r *http.Request)

Hello again

func HelloFirestore

func HelloFirestore(ctx context.Context, e FirestoreEvent) error

HelloFirestore is triggered by a change to a Firestore document.

Types

type FirestoreEvent

type FirestoreEvent struct {
	OldValue   FirestoreValue `json:"oldValue"`
	Value      FirestoreValue `json:"value"`
	UpdateMask struct {
		FieldPaths []string `json:"fieldPaths"`
	} `json:"updateMask"`
}

FirestoreEvent is the payload of a Firestore event.

type FirestoreValue

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"`
}

FirestoreValue holds Firestore fields.

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL