GithubHelp home page GithubHelp logo

firead's Introduction

firead

Create Go microservices that read Firestore documents.

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

Either read documents with a string ID:

firead.RunStringId()

Or read documents with an int ID:

firead.RunIntId()

Examples

Try working examples of firead here

Getting started

Create a new Go project

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

Get firead

go get github.com/jonnyorman/firead

Add a main.go file with the following

package main

import "github.com/jonnyorman/firead"

func main() {
	firead.RunStringId()
}

Add a firead-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 GET to the service's /{id} path, replaceing {id} with the ID of the document you want to read. You will get a 200 response with the document in the response body.

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

package main

import "github.com/jonnyorman/firead"

type DocumentModel struct {
	Prop1 string
	Prop2 int
}

func main() {
	firead.RunTypedStringId[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 firead-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 firead-config.json and the environment, then the configuration file with take priority. For example, if the PROJECT_ID envronment variable has value "env-project-id" and the following firead-config.json file is provided:

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

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

Running integration tests

To run integration tests in Docker against a local Firebase emulator, run the following:

  • For typed documents with int IDs: make test-firead-int-id-typed
  • For untyped documents with int IDs: make test-firead-int-id-untyped
  • For typed documents with string IDs: make test-firead-string-id-typed
  • For untyped documents with string IDs: make test-firead-string-id-untyped

firead's People

Contributors

jonnyorman avatar

Watchers

 avatar

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.