firesert

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2022 License: MIT Imports: 7 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]()
}

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 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 ConfigurationCreator added in v0.1.2

type ConfigurationCreator interface {
	Create(configurationJson []byte) 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 ConfigurationJsonFileReader added in v0.1.2

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

func NewConfigurationJsonFileReader added in v0.1.2

func NewConfigurationJsonFileReader(filePathProvider FilePathProvider) *ConfigurationJsonFileReader

func (ConfigurationJsonFileReader) Read added in v0.1.2

func (this ConfigurationJsonFileReader) Read() []byte

type ConfigurationLoader added in v0.1.2

type ConfigurationLoader interface {
	Load() Configuration
}

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 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 JsonConfigurationCreator added in v0.1.2

type JsonConfigurationCreator struct{}

func (JsonConfigurationCreator) Create added in v0.1.2

func (this JsonConfigurationCreator) Create(configurationJson []byte) Configuration

type JsonConfigurationLoader added in v0.1.2

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

func NewJsonConfigurationLoader added in v0.1.2

func NewJsonConfigurationLoader(
	fileReader FileReader,
	configuratoinCreator ConfigurationCreator) *JsonConfigurationLoader

func (JsonConfigurationLoader) Load added in v0.1.2

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

Directories

Path Synopsis
tests

Jump to

Keyboard shortcuts

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