Skip to content

jgeiger/firego

 
 

Repository files navigation

Firego


Build Status Coverage Status

A Firebase client written in Go

Under Development

The API may or may not change radically within the next upcoming weeks.

Installation

go get -u github.com/CloudCom/firego

Usage

Import firego

import "github.com/CloudCom/firego"

Create a new firego reference

f := firego.New("https://my-firebase-app.firebaseIO.com")

Request Timeouts

By default, the Firebase reference will timeout after 30 seconds of trying to reach a Firebase server. You can configure this value by setting the global timeout duration

firego.TimeoutDuration = time.Minute

Auth Tokens

f.Auth("some-token-that-was-created-for-me")
f.Unauth()

Visit Fireauth if you'd like to generate your own auth tokens

Get Value

var v map[string]interface{}
if err := f.Value(&v); err != nil {
  log.Fatal(err)
}
fmt.Printf("%s\n", v)

Set Value

v := map[string]string{"foo":"bar"}
if err := f.Set(v); err != nil {
  log.Fatal(err)
}

Push Value

v := "bar"
pushedFirego, err := f.Push(v)
if err != nil {
	log.Fatal(err)
}

var bar string
if err := pushedFirego.Value(&bar); err != nil {
	log.Fatal(err)
}

// prints "https://my-firebase-app.firebaseIO.com/-JgvLHXszP4xS0AUN-nI: bar"
fmt.Printf("%s: %s\n", pushedFirego, bar)

Update Child

v := map[string]string{"foo":"bar"}
if err := f.Update(v); err != nil {
  log.Fatal(err)
}

Remove Value

if err := f.Remove(); err != nil {
  log.Fatal(err)
}

Watch a Node

notifications := make(chan firego.Event)
if err := f.Watch(notifications); err != nil {
	log.Fatal(err)
}

defer f.StopWatching()
for event := range notifications {
	fmt.Printf("Event %#v\n", event)
}
fmt.Printf("Notifications have stopped")

Check the GoDocs or Firebase Documentation for more details

Running Tests

In order to run the tests you need to go get:

  • github.com/stretchr/testify/require
  • github.com/stretchr/testify/assert

Issues Management

Feel free to open an issue if you come across any bugs or if you'd like to request a new feature.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b new-feature)
  3. Commit your changes (git commit -am 'Some cool reflection')
  4. Push to the branch (git push origin new-feature)
  5. Create new Pull Request

About

Firebase Go Client

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%