register

package module
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: May 18, 2022 License: MIT Imports: 16 Imported by: 2

README

firebase-fx

A wrapper for Google Cloud Functions that simplifies the deployment of serverless applications.

Meant to expose a similar API to the Firebase Functions package for node.js.

Features
  • Deployment
    • Output bash script
    • Profile memory for deployment: --memory flag
  • HTTP triggers
    • Unauthenticated
    • Methods, Headers, Host, Query
    • Middleware
  • Analytics
  • Firebase Authentication triggers
  • Firestore triggers
    • Document path wildcards
      • Access vars
    • Custom data types
    • fx tagged fields
      • string
      • number = float64/int
      • boolean = bool
      • map = struct OR map[string]interface{}
        • map = struct OR map[string]interface{}
      • array = []interface{}
      • geopoint = struct
      • timestamp = time.Time
  • PubSub triggers
    • Custom data types
  • Firebase Realtime Database triggers
    • Path wildcards
      • Access vars
    • Custom data types - JSON tags
  • Schedule triggers
  • Storage triggers
Usage

setup.go

package functions

import (
	"context"
	"fmt"

	register "github.com/cleanflo/firebase-fx"
)

var Register = register.Shared

func init() {
	Register.PubSub("my-topic").Publish(MyCustomData{}, func(ctx context.Context, msg register.PubSubMessage) error {
		fmt.Println(msg.Topic)
		if data, ok := msg.Data.(*MyCustomData); ok {
			// do something with v
			fmt.Println(data)
		}
		return nil
	})

	Register.Firestore().Collection("users").Document("{uid}").Create(MyUserData{}, func(ctx context.Context, e register.FirestoreEvent) error {
		fmt.Println(e.Vars()["uid"])

		if data, ok := e.Value.Fields.(*MyUserData); ok {
			// do something with v
			fmt.Println(data)
		}

		if data, ok := e.OldValue.Fields.(*MyUserData); ok {
			// do something with v
			fmt.Println(data)
		}
		return nil
	})
}

type MyCustomData struct {
	Name string
}

type MyUserData struct {
	Email string
}

deploy/deploy.go

package main

import (
	"fmt"

	functions "github.com/cleanflo/firebase-fx/functions"
	register "github.com/cleanflo/firebase-fx"
)

func main() {
	fmt.Println(functions.Register.
		WithEntrypoint("Register.EntryPoint").
		WithProjectID("my-project-id").
		WithRuntime("go116").
		Verbosity(register.DebugVerbosity).
		Deploy(),
	)
}

command

$ go run deploy/deploy.go

gcloud functions deploy  --entry-point "Register.EntryPoint" --runtime "go116" --project "my-project-id" --verbosity "debug" \
pubsubpublish-my-topic --trigger-topic "my-topic" &&  \
gcloud functions deploy  --entry-point "Register.EntryPoint" --runtime "go116" --project "my-project-id" --verbosity "debug" \
firestoreDocCreate-users-uid --trigger-event "providers/cloud.firestore/eventTypes/document.create" --trigger-resource "projects/my-project-id/databases/(default)/documents/users/{uid}"

Documentation

Index

Constants

View Source
const (
	// Google Analytics Firebase event types
	AnalyticsLogEvent AnalyticsEventType = "providers/google.firebase.analytics/eventTypes/event.log"

	// Authentication event types
	AuthenticationUserCreateEvent AuthEventType = "providers/firebase.auth/eventTypes/user.create"
	AuthenticationUserDeleteEvent AuthEventType = "providers/firebase.auth/eventTypes/user.delete"

	// Firestore event types
	FirestoreDocumentCreateEvent FirestoreEventType = "providers/cloud.firestore/eventTypes/document.create"
	FirestoreDocumentDeleteEvent FirestoreEventType = "providers/cloud.firestore/eventTypes/document.delete"
	FirestoreDocumentUpdateEvent FirestoreEventType = "providers/cloud.firestore/eventTypes/document.update"
	FirestoreDocumentWriteEvent  FirestoreEventType = "providers/cloud.firestore/eventTypes/document.write"

	// Pub/Sub event types
	PubSubPublishEvent PubSubEventType = "google.pubsub.topic.publish"

	// Realtime Database event types
	RealtimeDBRefCreateEvent RealtimeDBEventType = "providers/google.firebase.database/eventTypes/ref.create"
	RealtimeDBRefDeleteEvent RealtimeDBEventType = "providers/google.firebase.database/eventTypes/ref.delete"
	RealtimeDBRefUpdateEvent RealtimeDBEventType = "providers/google.firebase.database/eventTypes/ref.update"
	RealtimeDBRefWriteEvent  RealtimeDBEventType = "providers/google.firebase.database/eventTypes/ref.write"

	// Firebase Remote Config event types
	RemoteConfigUpdateEvent RemoteConfigEventType = "remoteConfig.update"

	// Scheduler event types
	SchedulerRunEvent SchedulerEventType = "google.pubsub.topic.publish"

	// Storage event types
	StorageObjectArchiveEvent        StorageEventType = "google.storage.object.archive"
	StorageObjectDeleteEvent         StorageEventType = "google.storage.object.delete"
	StorageObjectFinalizeEvent       StorageEventType = "google.storage.object.finalize"
	StorageObjectMetadataUpdateEvent StorageEventType = "google.storage.object.metadataUpdate"
)

Variables

View Source
var (
	Shared               *FunctionRegistrar = NewRegister()         // the shared registrar
	SharedEntryPoint                        = Shared.EntryPoint     // the entrypoint for shared background functions
	SharedHttpEntrypoint                    = Shared.HttpEntrypoint // the entrypoint for shared http functions
)

Functions

func SetLogLevel

func SetLogLevel(level LogLevel)

SetLogLevel is a wrapper for setting the logrus.Level

Types

type AnalyticsEventType

type AnalyticsEventType EventType

AnalyticsEventType is the event type for Analytics CloudEvents

func (AnalyticsEventType) String

func (e AnalyticsEventType) String() string

String returns a minimal/readable representation of the event type

func (AnalyticsEventType) Type

func (e AnalyticsEventType) Type() EventType

Type returns the event type

func (AnalyticsEventType) Valid

func (a AnalyticsEventType) Valid() bool

Valid reports whether the AnalyticsEventType is valid

type AuthEvent

type AuthEvent struct {
	Email    string `json:"email"`
	Metadata struct {
		CreatedAt time.Time `json:"createdAt"`
	} `json:"metadata"`
	ProviderData []struct {
		Email    string `json:"email"`
		Provider string `json:"providerId"`
		UID      string `json:"uid"`
	} `json:"providerData"`
	UID string `json:"uid"`
}

AuthEvent is the expected payload for Firestore Auth CloudEvents.

type AuthEventType

type AuthEventType EventType

AuthEventType is the event type for Firebase Authentication CloudEvents

func (AuthEventType) String

func (e AuthEventType) String() string

String returns a minimal/readable representation of the event type

func (AuthEventType) Type

func (e AuthEventType) Type() EventType

Type returns the event type

func (AuthEventType) Valid

func (a AuthEventType) Valid() bool

Valid reports whether the AuthEventType is valid

type AuthenticationFunc

type AuthenticationFunc func(ctx context.Context, e AuthEvent) error

AuthenticationFunc is the function signature for the Firebase Authentication CloudEvent

type AuthenticationFunction

type AuthenticationFunction struct {
	// contains filtered or unexported fields
}

AuthenticationFunction is a wrapper for the AuthenticationFunc and the parent FunctionRegistrar Implements the CloudEventFunction interface

func (*AuthenticationFunction) Create

Create registers the specified function to the UserCreated event for the Firebase Authentication CloudEvent providers/firebase.auth/eventTypes/user.create

func (*AuthenticationFunction) Delete

Delete registers the specified function to the UserDeleted event for the Firebase Authentication CloudEvent providers/firebase.auth/eventTypes/user.delete

func (*AuthenticationFunction) Event

func (a *AuthenticationFunction) Event() EventType

Event returns the EventType of the function: AuthenticationUserCreateEvent / AuthenticationUserDeleteEvent

func (*AuthenticationFunction) HandleCloudEvent

func (a *AuthenticationFunction) HandleCloudEvent(ctx context.Context, md *metadata.Metadata, dec *Decoder) error

HandleCloudEvent handles the Firebase Authentication CloudEvent and calls the registered AuthenticationFunction

func (*AuthenticationFunction) Name

func (a *AuthenticationFunction) Name() string

Name returns the name of the function: "auth.user.{create,delete}"

func (*AuthenticationFunction) Resource

func (a *AuthenticationFunction) Resource() string

Resource returns the resource of the function: "providers/firebase.auth/eventTypes/user.{create,delete}"

type CloudDeployFunction

type CloudDeployFunction interface {
	HandleCloudEvent(context.Context, *metadata.Metadata, *Decoder) error
	Name() string
	Resource() string
	Event() EventType
}

CloudDeployFunction can be implemented by an event handler function

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder is a helper to retrieve the JSON data from the request

func (*Decoder) Decode

func (d *Decoder) Decode(v interface{}) error

Decode decodes the event data into the given type

func (*Decoder) UnmarshalJSON

func (d *Decoder) UnmarshalJSON(b []byte) error

UnmarshalJSON is a custom marshaller for the Decoder

type EventType

type EventType string

func (EventType) String

func (e EventType) String() string

String returns the event type

type FirestoreEvent

type FirestoreEvent struct {
	OldValue   FirestoreValue `json:"oldValue"`
	Value      FirestoreValue `json:"value"`
	UpdateMask struct {
		FieldPaths []string `json:"fieldPaths"`
	} `json:"updateMask"`
	// contains filtered or unexported fields
}

FirestoreEvent is the expected payload for Firestore CloudEvents

func (*FirestoreEvent) Copy

func (e *FirestoreEvent) Copy(v interface{}) error

Copy recursively copies the fields received in the FirestoreEvent to the struct provided to the calling FirestoreFunc The struct must have the same fields as the named fields received by the payload

func (*FirestoreEvent) Vars

func (e *FirestoreEvent) Vars() map[string]string

Vars is used to access the segment positions var names for access within the function

type FirestoreEventType

type FirestoreEventType EventType

FirestoreEventType is the event type for Firestore CloudEvents

func (FirestoreEventType) String

func (e FirestoreEventType) String() string

String returns a minimal/readable representation of the event type

func (FirestoreEventType) Type

func (e FirestoreEventType) Type() EventType

Type returns the event type

func (FirestoreEventType) Valid

func (f FirestoreEventType) Valid() bool

Valid reports whether the FirstoreEventType is valid

type FirestoreFunc

type FirestoreFunc func(ctx context.Context, e FirestoreEvent) error

FirestoreFunc is the function signature for Firestore Cloud Events

type FirestoreFunction

type FirestoreFunction struct {
	// contains filtered or unexported fields
}

FirestoreFunction is a wrapper for the expected data, FirestoreFunc and the parent FunctionRegistrar Implements the CloudEventFunction interface

func (*FirestoreFunction) Collection

func (f *FirestoreFunction) Collection(ref string) *FirestoreFunction

Collection appends the given path to the ref that the FirestoreFunc is executed on. Will replace existing collection segment if it exists Meant to be chained with .Document()

func (*FirestoreFunction) Create

func (f *FirestoreFunction) Create(data interface{}, fn FirestoreFunc) *FirestoreFunction

Create registers the specified function to the DocumentCreateEvent for Firestore CloudEvent The provided data is used to populate the Value.Fields of the FirestoreEvent received by the function providers/cloud.firestore/eventTypes/document.create

func (*FirestoreFunction) Delete

func (f *FirestoreFunction) Delete(data interface{}, fn FirestoreFunc) *FirestoreFunction

Delete registers the specified function to the DocumentDeleteEvent for Firestore CloudEvent The provided data is used to populate the OldValue.Fields of the FirestoreEvent received by the function providers/cloud.firestore/eventTypes/document.delete

func (*FirestoreFunction) Document

func (f *FirestoreFunction) Document(ref string) *FirestoreFunction

Document appends the given path to the path that the FirestoreFunc is executed on. Will replace existing document segment if it exists Meant to be chained with .Collection()

func (*FirestoreFunction) Event

func (a *FirestoreFunction) Event() EventType

Event returns the EventType of the function:

FirestoreDocumentCreateEvent / FirestoreDocumentUpdateEvent / FirestoreDocumentDeleteEvent /FirestoreDocumentWriteEvent

func (*FirestoreFunction) HandleCloudEvent

func (a *FirestoreFunction) HandleCloudEvent(ctx context.Context, md *metadata.Metadata, dec *Decoder) error

HandleCloudEvent handles the Firebase Firestore CloudEvent and calls the registered FirestoreFunction

func (*FirestoreFunction) Name

func (a *FirestoreFunction) Name() string

Name returns the name of the function: "firestore.doc.{create,delete,update,write}"

func (*FirestoreFunction) Path

func (f *FirestoreFunction) Path() string

Path creates a path for the Firestore event that can be used for registering a function returns the path with all wildcard fields replaced with "*" and saves a map of the segment positions var names for access within the function

func (*FirestoreFunction) Resource

func (a *FirestoreFunction) Resource() string

Resource returns the resource of the function: "collection/{document-id}/...."

func (*FirestoreFunction) Update

func (f *FirestoreFunction) Update(data interface{}, fn FirestoreFunc) *FirestoreFunction

Update registers the specified function to the DocumentUpdateEvent for Firestore CloudEvent The provided data is used to populate the Value.Fields and OldValue.Fields of the FirestoreEvent received by the function providers/cloud.firestore/eventTypes/document.update

func (*FirestoreFunction) Write

func (f *FirestoreFunction) Write(data interface{}, fn FirestoreFunc) *FirestoreFunction

Write registers the specified function to the DocumentWriteEvent for Firestore CloudEvent The provided data is used to populate the Value.Fields and OldValue.Fields of the FirestoreEvent received by the function providers/cloud.firestore/eventTypes/document.write

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"` // the path of the document
	UpdateTime time.Time   `json:"updateTime"`
}

FirestoreValue holds Firestore fields.

type FunctionRegistrar

type FunctionRegistrar struct {
	// contains filtered or unexported fields
}

FunctionRegistrar is the registrar for functions

func NewRegister

func NewRegister() *FunctionRegistrar

NewRegister creates a new registrar with all top level maps initialized nested maps are intialized when a function is registered

func (*FunctionRegistrar) AllowUnauthenticated added in v0.0.10

func (f *FunctionRegistrar) AllowUnauthenticated(t bool) *FunctionRegistrar

func (*FunctionRegistrar) Authentication

func (f *FunctionRegistrar) Authentication() *AuthenticationFunction

Authentication returns a new AuthenticationFunction with the FunctionRegistrar set to the parent

func (*FunctionRegistrar) Deploy

func (f *FunctionRegistrar) Deploy() (s string)

func (*FunctionRegistrar) DeployCloud added in v0.0.9

func (f *FunctionRegistrar) DeployCloud() (s string)

func (*FunctionRegistrar) DeployHTTP added in v0.0.9

func (f *FunctionRegistrar) DeployHTTP() (s string)

func (*FunctionRegistrar) EntryPoint

func (f *FunctionRegistrar) EntryPoint(ctx context.Context, dec *Decoder) error

The entrypoint for all functions. This is the function that is called when the function is triggered.

	 	f := register.NewRegister()
     f.PubSub("topic").Publish(&mydata, myPubsubFunc)

now f.Entrypoint can be used as the entrypoint when deploying the function

func (*FunctionRegistrar) Firestore

func (f *FunctionRegistrar) Firestore() *FirestoreFunction

Firestore returns a new FirestoreFunction with the FunctionRegistrar set to the parent

func (*FunctionRegistrar) HTTP

func (f *FunctionRegistrar) HTTP(path string, handler http.HandlerFunc) *HttpFunction

HTTP registers the given path/name to an underlying mux.Router add advanced routing options (Headers, Methods) to the returned HttpFunction The deployment script for functions registered via this method will be in the below format:

~$ gcloud functions deploy --entrypoint "Registrar.HttpEntrypoint" Registrar --trigger-http --allow-unauthenticated

and can be executed like:

~$ curl "https://REGION-PROJECT_ID.cloudfunctions.net/Registrar/{path}"

func (*FunctionRegistrar) HttpEntrypoint

func (f *FunctionRegistrar) HttpEntrypoint(w http.ResponseWriter, r *http.Request)

HttpEntrypoint is the entrypoint for http functions it will route the request to the correct function

func (*FunctionRegistrar) MiddleWare

func (f *FunctionRegistrar) MiddleWare(wares ...mux.MiddlewareFunc)

Middleware registers the given mux.MiddlewareFunc to the underlying mux.Router

func (*FunctionRegistrar) PubSub

func (f *FunctionRegistrar) PubSub(topic string) *PubSubFunction

PubSub registers a function to the specified event, or returns the existing function if one already exists

func (*FunctionRegistrar) RealtimeDB

func (f *FunctionRegistrar) RealtimeDB() *RealtimeDBFunction

RealtimeDB returns a new RealtimeDBFunction with the FunctionRegistrar set to the parent

func (*FunctionRegistrar) ServeHTTP added in v0.0.9

func (f *FunctionRegistrar) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*FunctionRegistrar) Storage

func (f *FunctionRegistrar) Storage() *StorageFunction

Storage returns a new StorageFunction with the FunctionRegistrar set to the parent

func (*FunctionRegistrar) Verbosity

func (f *FunctionRegistrar) Verbosity(level VerbosityLevel) *FunctionRegistrar

Verbosity sets the verbosity level for the deploy command

func (*FunctionRegistrar) WithProjectID

func (f *FunctionRegistrar) WithProjectID(id string) *FunctionRegistrar

WithProjectID sets the project id for the functions when deploying otherwise it will exclude the --project flag from the deploy command most often the project id is the simply the project name in kebab case eg. my-project-name

func (*FunctionRegistrar) WithRegistrar added in v0.0.9

func (f *FunctionRegistrar) WithRegistrar(name string) *FunctionRegistrar

WithRegistrar sets the entry point for the functions when deploying this is the actual name of the variable in your source code otherwise it will use the register.SharedEntryPoint again this assumes you have imported this package as register and you have registered your functions using register.Shared

Cloud Functions may fail to deploy if the name provided here is undefined or unexported in the top level of your package being deployed.

For example:

var FancyRegistrar = register.NewRegister().WithRegistrar("FancyRegistrar")

func (*FunctionRegistrar) WithRuntime

func (f *FunctionRegistrar) WithRuntime(runtime Runtime) *FunctionRegistrar

WithRuntime sets the runtime for the functions when deploying

type HttpFunction

type HttpFunction struct {
	// contains filtered or unexported fields
}

HttpFunction is a wrapper for mux.Route and the parent FunctionRegistrar

func (*HttpFunction) Headers

func (h *HttpFunction) Headers(pairs ...string) *HttpFunction

Headers registers the given headers to the underlying mux.Route

func (*HttpFunction) Host

func (h *HttpFunction) Host(host string) *HttpFunction

Host registers the given host to the underlying mux.Route

func (*HttpFunction) Methods

func (h *HttpFunction) Methods(methods ...string) *HttpFunction

Methods registers the given methods to the underlying mux.Route

func (*HttpFunction) Queries

func (h *HttpFunction) Queries(queries ...string) *HttpFunction

Queries registers the given queries to the underlying mux.Route

type LogLevel

type LogLevel int

LogLevel is a helper to log at different levels

const (
	Debug LogLevel = iota
	Info
	Warn
	Error
)

func (LogLevel) Err

func (l LogLevel) Err(msg string, err error) error

Err is a wrapper for logrus.Error

func (LogLevel) Errf

func (l LogLevel) Errf(msg string, args ...interface{}) error

Errf is a wrapper for logrus.Errorf

func (LogLevel) Msg

func (l LogLevel) Msg(msg string, fields map[string]interface{})

Msg is a wrapper for logrus.{Level}

func (LogLevel) Msgf

func (l LogLevel) Msgf(msg string, args ...interface{})

Msgf is a wrapper for logrus.{Level}f

type PubSubEventType

type PubSubEventType EventType

PubSubEventType is the event type for Pub/Sub CloudEvents

func (PubSubEventType) String

func (e PubSubEventType) String() string

String returns a minimal/readable representation of the event type

func (PubSubEventType) Type

func (e PubSubEventType) Type() EventType

Type returns the event type

func (PubSubEventType) Valid

func (p PubSubEventType) Valid() bool

Valid reports whether the PubSubEventType is valid

type PubSubFunc

type PubSubFunc func(ctx context.Context, m PubSubMessage) error

PubSubFunc is the function signature for the Pub/Sub CloudEvent

type PubSubFunction

type PubSubFunction struct {
	// contains filtered or unexported fields
}

PubSubFunction is a wrapper for the PubSubFunc and the parent FunctionRegistrar Implements the CloudEventFunction interface

func (*PubSubFunction) Event

func (a *PubSubFunction) Event() EventType

Event returns the EventType of the function: PubSubPublishEvent

func (*PubSubFunction) HandleCloudEvent

func (a *PubSubFunction) HandleCloudEvent(ctx context.Context, md *metadata.Metadata, dec *Decoder) error

HandleCloudEvent handles the PubSub CloudEvent and calls the registered PubSubFunction

func (*PubSubFunction) Name

func (a *PubSubFunction) Name() string

Name returns the name of the function: "pubsub.topic.publish/{topic}"

func (*PubSubFunction) Publish

func (p *PubSubFunction) Publish(data interface{}, fn PubSubFunc) *PubSubFunction

Publish registers the specified function to the specific topic for the Pub/Sub CloudEvent The provided data is used to populate the Data field of the PubSubMessage received by the function google.pubsub.topic.publish

func (*PubSubFunction) Resource

func (a *PubSubFunction) Resource() string

Resource returns the resource of the function: "{topic}"

type PubSubMessage

type PubSubMessage struct {
	Topic string      `json:"topic"`
	Data  interface{} `json:"data"`
}

PubSubMessage is the expected payload for Pub/Sub CloudEvents.

type RTDBEvent

type RTDBEvent struct {
	Data  interface{}
	Delta interface{}
	// contains filtered or unexported fields
}

RTDBEvent is the expected payload of a firebase Realtime Database CloudEvent

func (*RTDBEvent) Vars

func (e *RTDBEvent) Vars() map[string]string

Vars returns the map of variable name that were registered on the path that matched this function

type RealtimeDBEventType

type RealtimeDBEventType EventType

RealtimeDBEventType is the event type for Firebase Realtime Database CloudEvents

func (RealtimeDBEventType) String

func (e RealtimeDBEventType) String() string

String returns a minimal/readable representation of the event type

func (RealtimeDBEventType) Type

func (e RealtimeDBEventType) Type() EventType

Type returns the event type

func (RealtimeDBEventType) Valid

func (r RealtimeDBEventType) Valid() bool

Valid reports whether the RealtimeDBEventType is valid

type RealtimeDBFunc

type RealtimeDBFunc func(ctx context.Context, e RTDBEvent) error

RealtimeDBFunc is the function signature for firebase Realtime Database Cloud Events

type RealtimeDBFunction

type RealtimeDBFunction struct {
	// contains filtered or unexported fields
}

RealtimeDBFunction is a wrapper for the expected data, RealtimeDBFunc and the parent FunctionRegistrar Implements the CloudEventFunction interface

func (*RealtimeDBFunction) Create

func (r *RealtimeDBFunction) Create(data interface{}, fn RealtimeDBFunc) *RealtimeDBFunction

Create registers the specified function to the RefCreateEvent for firebase Realtime Database CloudEvent The provided data is used to populate .Data of the RTDBEvent received by the function providers/google.firebase.database/eventTypes/ref.create

func (*RealtimeDBFunction) Delete

func (r *RealtimeDBFunction) Delete(data interface{}, fn RealtimeDBFunc) *RealtimeDBFunction

Delete registers the specified function to the RefDeleteEvent for firebase Realtime Database CloudEvent The provided data is used to populate .Delta of the RTDBEvent received by the function providers/google.firebase.database/eventTypes/ref.delete

func (*RealtimeDBFunction) Event

func (a *RealtimeDBFunction) Event() EventType

Event returns the EventType of the function: RealtimeDBRefWriteEvent / RealtimeDBRefCreateEvent / RealtimeDBRefUpdateEvent / RealtimeDBRefDeleteEvent

func (*RealtimeDBFunction) HandleCloudEvent

func (a *RealtimeDBFunction) HandleCloudEvent(ctx context.Context, md *metadata.Metadata, dec *Decoder) error

HandleCloudEvent handles the Firebase RealtimeDB CloudEvent and calls the registered RealtimeDBFunction

func (*RealtimeDBFunction) Name

func (a *RealtimeDBFunction) Name() string

Name returns the name of the function: "rtdb.ref.{write,create,delete,update}-{path-segments}"

func (*RealtimeDBFunction) Path

func (r *RealtimeDBFunction) Path() string

Path creates a path for the RealtimeDB event that can be used for registering a function returns the path with all wildcard fields replaced with a * and saves a map of the segment positions var names for access within the function

func (*RealtimeDBFunction) Ref

Ref appends the given path to the path that the RealtimeDBFunction is executed on Meant to be chained

func (*RealtimeDBFunction) Resource

func (a *RealtimeDBFunction) Resource() string

Resource returns the resource of the function: "ref/{ref-id}/...."

func (*RealtimeDBFunction) Update

func (r *RealtimeDBFunction) Update(data interface{}, fn RealtimeDBFunc) *RealtimeDBFunction

Update registers the specified function to the RefUpdateEvent for firebase Realtime Database CloudEvent The provided data is used to populate .Data & .Delta of the RTDBEvent received by the function providers/google.firebase.database/eventTypes/ref.update

func (*RealtimeDBFunction) Write

func (r *RealtimeDBFunction) Write(data interface{}, fn RealtimeDBFunc) *RealtimeDBFunction

Write registers the specified function to the RefWriteEvent for firebase Realtime Database CloudEvent The provided data is used to populate .Data & .Delta of the RTDBEvent received by the function providers/google.firebase.database/eventTypes/ref.write

type RemoteConfigEventType

type RemoteConfigEventType EventType

RemoteConfigEventType is the event type for Firebase Remote Config CloudEvents

func (RemoteConfigEventType) String

func (e RemoteConfigEventType) String() string

String returns a minimal/readable representation of the event type

func (RemoteConfigEventType) Type

Type returns the event type

func (RemoteConfigEventType) Valid

func (r RemoteConfigEventType) Valid() bool

Valid reports whether the RemoteConfigEventType is valid

type Runtime

type Runtime string

Runtime is the runtime for the functions when deploying

const (
	Go111 Runtime = "go111"
	Go113 Runtime = "go113"
	Go116 Runtime = "go116" // default
)

type SchedulerEventType

type SchedulerEventType PubSubEventType

func (SchedulerEventType) String

func (e SchedulerEventType) String() string

String returns a minimal/readable representation of the event type

func (SchedulerEventType) Type

func (e SchedulerEventType) Type() EventType

Type returns the event type

func (SchedulerEventType) Valid

func (r SchedulerEventType) Valid() bool

Valid reports whether the RemoteConfigEventType is valid

type StorageEvent

type StorageEvent struct {
	Kind                    string                 `json:"kind"`
	ID                      string                 `json:"id"`
	SelfLink                string                 `json:"selfLink"`
	Name                    string                 `json:"name"`
	Bucket                  string                 `json:"bucket"`
	Generation              string                 `json:"generation"`
	Metageneration          string                 `json:"metageneration"`
	ContentType             string                 `json:"contentType"`
	TimeCreated             time.Time              `json:"timeCreated"`
	Updated                 time.Time              `json:"updated"`
	TemporaryHold           bool                   `json:"temporaryHold"`
	EventBasedHold          bool                   `json:"eventBasedHold"`
	RetentionExpirationTime time.Time              `json:"retentionExpirationTime"`
	StorageClass            string                 `json:"storageClass"`
	TimeStorageClassUpdated time.Time              `json:"timeStorageClassUpdated"`
	Size                    string                 `json:"size"`
	MD5Hash                 string                 `json:"md5Hash"`
	MediaLink               string                 `json:"mediaLink"`
	ContentEncoding         string                 `json:"contentEncoding"`
	ContentDisposition      string                 `json:"contentDisposition"`
	CacheControl            string                 `json:"cacheControl"`
	Metadata                map[string]interface{} `json:"metadata"`
	CRC32C                  string                 `json:"crc32c"`
	ComponentCount          int                    `json:"componentCount"`
	Etag                    string                 `json:"etag"`
	CustomerEncryption      struct {
		EncryptionAlgorithm string `json:"encryptionAlgorithm"`
		KeySha256           string `json:"keySha256"`
	}
	KMSKeyName    string `json:"kmsKeyName"`
	ResourceState string `json:"resourceState"`
}

GCSEvent is the expected payload for Google Cloud Storage CloudEvents.

Finalize:
{
	"kind":"storage#object",
	"id":"cleanflo-test-bucket/1 S Morrison.pdf/1642210177215991",
	"selfLink":"https://www.googleapis.com/storage/v1/b/cleanflo-test-bucket/o/1%20S%20Morrison.pdf",
	"name":"1 S Morrison.pdf",
	"bucket":"cleanflo-test-bucket",
	"generation":"1642210177215991",
	"metageneration":"1",
	"contentType":"application/pdf",
	"timeCreated":"2022-01-15T01:29:37.279Z",
	"updated":"2022-01-15T01:29:37.279Z"
	"storageClass":"STANDARD",
	"timeStorageClassUpdated":"2022-01-15T01:29:37.279Z",
	"size":"79734",
	"md5Hash":"+ndvErmbIgA5ccSgYOCzxg==",
	"mediaLink":"https://www.googleapis.com/download/storage/v1/b/cleanflo-test-bucket/o/1%20S%20Morrison.pdf?generation=1642210177215991&alt=media",
	"crc32c":"rZYNFQ==",
	"etag":"CPfbidLNsvUCEAE=",
}

MetadataUpdate:

{
	"kind":"storage#object",
	"id":"cleanflo-test-bucket/1 S Morrison.pdf/1642210177215991",
	"selfLink":"https://www.googleapis.com/storage/v1/b/cleanflo-test-bucket/o/1%20S%20Morrison.pdf",
	"name":"1 S Morrison.pdf",
	"bucket":"cleanflo-test-bucket",
	"generation":"1642210177215991",
	"metageneration":"3",
	"contentType":"application/pdf",
	"timeCreated":"2022-01-15T01:29:37.279Z",
	"updated":"2022-01-15T01:39:30.599Z"
	"temporaryHold":false,
	"eventBasedHold":false,
	"storageClass":"STANDARD",
	"timeStorageClassUpdated":"2022-01-15T01:29:37.279Z",
	"size":"79734",
	"md5Hash":"+ndvErmbIgA5ccSgYOCzxg==",
	"mediaLink":"https://www.googleapis.com/download/storage/v1/b/cleanflo-test-bucket/o/1%20S%20Morrison.pdf?generation=1642210177215991&alt=media",
	"metadata":{"ttt":"123"},
	"crc32c":"rZYNFQ==",
	"etag":"CPfbidLNsvUCEAM=",
	"customTime":"2022-01-18T06:00:00.000Z",
}

Delete:

{
	"kind":"storage#object",
	"id":"cleanflo-test-bucket/1 S Morrison.pdf/1642210177215991",
	"selfLink":"https://www.googleapis.com/storage/v1/b/cleanflo-test-bucket/o/1%20S%20Morrison.pdf",
	"name":"1 S Morrison.pdf",
	"bucket":"cleanflo-test-bucket",
	"generation":"1642210177215991",
	"metageneration":"3",
	"contentType":"application/pdf",
	"timeCreated":"2022-01-15T01:29:37.279Z",
	"updated":"2022-01-15T01:39:30.599Z"
	"temporaryHold":false,
	"eventBasedHold":false,
	"storageClass":"STANDARD",
	"timeStorageClassUpdated":"2022-01-15T01:29:37.279Z",
	"size":"79734",
	"md5Hash":"+ndvErmbIgA5ccSgYOCzxg==",
	"mediaLink":"https://www.googleapis.com/download/storage/v1/b/cleanflo-test-bucket/o/1%20S%20Morrison.pdf?generation=1642210177215991&alt=media",
	"metadata":{"ttt":"123"},
	"crc32c":"rZYNFQ==",
	"etag":"CPfbidLNsvUCEAM=",
	"customTime":"2022-01-18T06:00:00.000Z",
}

type StorageEventType

type StorageEventType EventType

StorageEventType is the event type for Storage CloudEvents

func (StorageEventType) String

func (e StorageEventType) String() string

String returns a minimal/readable representation of the event type

func (StorageEventType) Type

func (e StorageEventType) Type() EventType

Type returns the event type

func (StorageEventType) Valid

func (s StorageEventType) Valid() bool

Valid reports whether the StorageEventType is valid

type StorageFunc

type StorageFunc func(ctx context.Context, e StorageEvent) error

StorageFunc is the function signature for Google Cloud Storage Cloud Events

type StorageFunction

type StorageFunction struct {
	// contains filtered or unexported fields
}

StorageFunction is a wrapper for the expected data, StorageFunc and the parentFunctionRegistrar Implements the CloudEventFunction interface

func (*StorageFunction) Archive

Archive registers the specified function to the ObjectArchiveEvent for Storage CloudEvent google.storage.object.archive

func (*StorageFunction) Bucket

func (s *StorageFunction) Bucket(path string) *StorageFunction

Bucket sets the given path to the bucket that the StorageFunc is executed on

func (*StorageFunction) Delete

Delete registers the specified function to the ObjectDeleteEvent for Storage CloudEvent google.storage.object.delete

func (*StorageFunction) Event

func (a *StorageFunction) Event() EventType

Event returns the EventType of the function:

StorageObjectFinalizeEvent / StorageObjectDeleteEvent / StorageObjectArchiveEvent / StorageObjectMetadataUpdateEvent / EventTypeUserDelete

func (*StorageFunction) Finalize

func (s *StorageFunction) Finalize(fn StorageFunc) *StorageFunction

Finalize registers the specified function to the ObjectFinalizeEvent for Storage CloudEvent google.storage.object.finalize

func (*StorageFunction) HandleCloudEvent

func (a *StorageFunction) HandleCloudEvent(ctx context.Context, md *metadata.Metadata, dec *Decoder) error

HandleCloudEvent handles the Google Cloud Storage CloudEvent and calls the registered AuthenticationFunc

func (*StorageFunction) MetadataUpdate

func (s *StorageFunction) MetadataUpdate(fn StorageFunc) *StorageFunction

MetadataUpdate registers the specified function to the ObjectMetadataUpdateEvent for Storage CloudEvent google.storage.object.metadataUpdate

func (*StorageFunction) Name

func (a *StorageFunction) Name() string

Name returns the name of the function: "storageObject{Archive,Delete,Finalize,Metadata}-{bucketref}"

func (*StorageFunction) Resource

func (a *StorageFunction) Resource() string

Resource returns the resource of the function: "{bucketRef}"

type VerbosityLevel

type VerbosityLevel int

VerbosityLevel is for setting the verbosity level for the deploy command

const (
	DebugVerbosity VerbosityLevel = iota
	InfoVerbosity
	WarningVerbosity // default
	ErrorVerbosity
	CriticalVerbosity
	NoneVerbosity
)

func (VerbosityLevel) String

func (v VerbosityLevel) String() string

Directories

Path Synopsis
example module

Jump to

Keyboard shortcuts

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