firesert

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2022 License: MIT Imports: 8 Imported by: 3

README

firesert

Create Go microservices that receive Pub/Sub push messages and insert their data into Firestore collections.

Very easy to use, create a working service by adding just one line of code to your main method:

firesert.Run()

Examples

Try working examples of firesert here

Getting started

Create a new Go project

mkdir firesert-example
cd firesert-example
go mod init firesert/example

Get firesert

go get github.com/jonnyorman/firesert

Add a main.go file with the following

package main

import "github.com/jonnyorman/firesert"

func main() {
	firesert.Run()
}

Add a firesert-config.json file with the following

{
    "projectID": "your-firebase-project",
    "collectionName": "FirestoreCollection"
}

Tidy and run with access to a Firebase project or emulator

    go mod tidy
    go run .

Submit a POST to the service with a Pub/Sub push body. You will see the data get inserted in the FirestoreCollection collection in your Firestore.

You can also create a struct with the data you want to insert into Firestore. Create a struct and use it:

package main

import "github.com/jonnyorman/firesert"

type DocumentModel struct {
	Prop1 string
	Prop2 int
}

func main() {
	firesert.RunTyped[DocumentModel]()
}

Environment configuration

The configuration can also be provided by the environment with the following keys:

  • projectID - PROJECT_ID
  • collectionName - COLLECTION_NAME

A combination of the firesert-config.json file and environment variables can be used. For example, the project ID could be provided as the PROJECT_ID environment variable, while the collection name is provided with the following configuration file:

{
    "collectionName": "FirestoreCollection"
}

If a configuration value is provided in both firesert-config.json and the environment, then the configuration file with take priority. For example, if the PROJECT_ID envronment varialbe has value "env-project-id" and the following firesert-config.json file is provided:

{
    "projectID": "config-project-id",
    "collectionName": "FirestoreCollection"
}

then the project ID will be "config-project-id".

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run()

func RunTyped

func RunTyped[T any]()

Types

type Application added in v0.1.2

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

func BuildApplication added in v0.1.2

func BuildApplication[T any]() Application

func NewApplication added in v0.1.2

func NewApplication(router *gin.Engine) *Application

func (Application) Run added in v0.1.2

func (this Application) Run()

type ApplicationConfigurationLoader added in v0.2.0

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

func NewApplicationConfigurationLoader added in v0.2.0

func NewApplicationConfigurationLoader(
	projectIDProvider ValueProvider,
	collectionNameProvider ValueProvider,
) *ApplicationConfigurationLoader

func (ApplicationConfigurationLoader) Load added in v0.2.0

type Configuration added in v0.1.2

type Configuration struct {
	ProjectID      string
	CollectionName string
}

func NewConfiguration added in v0.1.2

func NewConfiguration(projectID string, collectionName string) *Configuration

type ConfigurationFilePathProvider added in v0.1.2

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

func NewConfigurationFilePathProvider added in v0.1.2

func NewConfigurationFilePathProvider(fileName string) *ConfigurationFilePathProvider

func (ConfigurationFilePathProvider) Get added in v0.1.2

type ConfigurationFileReader added in v0.2.0

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

func NewConfigurationFileReader added in v0.2.0

func NewConfigurationFileReader(filePathProvider FilePathProvider) *ConfigurationFileReader

func (ConfigurationFileReader) Read added in v0.2.0

func (this ConfigurationFileReader) Read() []byte

type ConfigurationJsonFileReader added in v0.1.2

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

func NewConfigurationJsonFileReader added in v0.1.2

func NewConfigurationJsonFileReader(configurationFileReader FileReader) *ConfigurationJsonFileReader

func (ConfigurationJsonFileReader) Read added in v0.1.2

func (this ConfigurationJsonFileReader) Read() map[string]interface{}

type ConfigurationLoader added in v0.1.2

type ConfigurationLoader interface {
	Load() Configuration
}

type ConfigurationValueProvider added in v0.2.0

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

func CreateConfigurationValueProvider added in v0.2.0

func CreateConfigurationValueProvider(
	jsonKey string,
	environmentKey string,
	configurationJson map[string]interface{}) ConfigurationValueProvider

func (ConfigurationValueProvider) Get added in v0.2.0

func (this ConfigurationValueProvider) Get() (string, bool)

type DataDeserialiser added in v0.1.2

type DataDeserialiser[T any] interface {
	Deserialise(data []byte) T
}

type DataInserter added in v0.1.2

type DataInserter[T any] interface {
	Insert(data T)
}

type DataReader added in v0.1.2

type DataReader[T any] interface {
	Read(ginContext *gin.Context) T
}

type EnvironmentValueProvider added in v0.2.0

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

func NewEnvironmentValueProvider added in v0.2.0

func NewEnvironmentValueProvider(key string) *EnvironmentValueProvider

func (EnvironmentValueProvider) Get added in v0.2.0

func (this EnvironmentValueProvider) Get() (string, bool)

type FilePathProvider added in v0.1.2

type FilePathProvider interface {
	Get() string
}

type FileReader added in v0.1.2

type FileReader interface {
	Read() []byte
}

type FirestoreDataInserter added in v0.1.2

type FirestoreDataInserter[T any] struct {
	// contains filtered or unexported fields
}

func NewFirestoreDataInserter added in v0.1.2

func NewFirestoreDataInserter[T any](configuration Configuration) *FirestoreDataInserter[T]

func (FirestoreDataInserter[T]) Insert added in v0.1.2

func (this FirestoreDataInserter[T]) Insert(data T)

type GinPubSubBodyReader added in v0.1.2

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

func NewGinPubSubBodyReader added in v0.1.2

func NewGinPubSubBodyReader(
	reader Reader,
	pubSubBodyDeserialiser DataDeserialiser[PubSubBody]) *GinPubSubBodyReader

func (GinPubSubBodyReader) Read added in v0.1.2

func (this GinPubSubBodyReader) Read(ginContext *gin.Context) PubSubBody

type GinRouterBuilder added in v0.1.2

type GinRouterBuilder[T any] struct {
	// contains filtered or unexported fields
}

func NewGinRouterBuilder added in v0.1.2

func NewGinRouterBuilder[T any](requestHandler RequestHandler[T]) *GinRouterBuilder[T]

func (GinRouterBuilder[T]) Build added in v0.1.2

func (this GinRouterBuilder[T]) Build() *gin.Engine

type HttpRequestBodyDataReader added in v0.1.2

type HttpRequestBodyDataReader[T any] struct {
	// contains filtered or unexported fields
}

func NewHttpRequestBodyDataReader added in v0.1.2

func NewHttpRequestBodyDataReader[T any](
	pubSubBodyReader PubSubBodyReader,
	dataDeserialiser DataDeserialiser[T]) *HttpRequestBodyDataReader[T]

func (HttpRequestBodyDataReader[T]) Read added in v0.1.2

func (this HttpRequestBodyDataReader[T]) Read(ginContext *gin.Context) T

type IoReaderGenerator added in v0.1.2

type IoReaderGenerator interface {
	Generate(payload string) io.Reader
}

type IoutilReader added in v0.1.2

type IoutilReader struct{}

func (IoutilReader) Read added in v0.1.2

func (this IoutilReader) Read(ioReader io.Reader) []byte

type JsonDataDeserialiser added in v0.1.2

type JsonDataDeserialiser[T any] struct{}

func (JsonDataDeserialiser[T]) Deserialise added in v0.1.2

func (this JsonDataDeserialiser[T]) Deserialise(data []byte) T

type JsonReader added in v0.2.0

type JsonReader interface {
	Read() map[string]interface{}
}

type JsonValueProvider added in v0.2.0

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

func NewJsonValueProvider added in v0.2.0

func NewJsonValueProvider(key string) *JsonValueProvider

func (JsonValueProvider) Get added in v0.2.0

func (this JsonValueProvider) Get() (string, bool)

type PubSubBody

type PubSubBody struct {
	Message      pubsub.Message
	Subscription string
}

type PubSubBodyReader added in v0.1.2

type PubSubBodyReader interface {
	Read(ginContext *gin.Context) PubSubBody
}

type PubSubPushRequestHandler added in v0.1.2

type PubSubPushRequestHandler[T any] struct {
	// contains filtered or unexported fields
}

func (PubSubPushRequestHandler[T]) Handle added in v0.1.2

func (this PubSubPushRequestHandler[T]) Handle(ginContext *gin.Context)

type Reader added in v0.1.2

type Reader interface {
	Read(ioReader io.Reader) []byte
}

type RequestHandler added in v0.1.2

type RequestHandler[T any] interface {
	Handle(ginContext *gin.Context)
}

type RouterBuilder added in v0.1.2

type RouterBuilder interface {
	Build() *gin.Engine
}

type ValueProvider added in v0.2.0

type ValueProvider interface {
	Get() (string, bool)
}

Directories

Path Synopsis
tests

Jump to

Keyboard shortcuts

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