- Notifications
You must be signed in to change notification settings - Fork77
zabawaba99/firego
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Deprecated in favor offirebase/firebase-admin-go.
A Firebase client written in Go
go get -u gopkg.in/zabawaba99/firego.v1
Import firego
import"gopkg.in/zabawaba99/firego.v1"
Create a new firego reference
f:=firego.New("https://my-firebase-app.firebaseIO.com",nil)
with existing http client
f:=firego.New("https://my-firebase-app.firebaseIO.com",client)
By default, theFirebase reference will timeout after 30 seconds of tryingto reach a Firebase server. You can configure this value by setting the globaltimeout duration
firego.TimeoutDuration=time.Minute
You can authenticate with yourservice_account.json file by using thegolang.org/x/oauth2 package (thanks @m00sey for the snippet)
d,err:=ioutil.ReadFile("our_service_account.json")iferr!=nil {returnnil,err}conf,err:=google.JWTConfigFromJSON(d,"https://www.googleapis.com/auth/userinfo.email","https://www.googleapis.com/auth/firebase.database")iferr!=nil {returnnil,err}fb:=firego.New("https://you.firebaseio.com",conf.Client(oauth2.NoContext))// use the authenticated fb instance
f.Auth("some-token-that-was-created-for-me")f.Unauth()
VisitFireauth if you'd like to generate your own auth tokens
varvmap[string]interface{}iferr:=f.Value(&v);err!=nil {log.Fatal(err)}fmt.Printf("%s\n",v)
Take a look at Firebase'squery parametersfor more information on what each function does.
varvmap[string]interface{}iferr:=f.StartAt("a").EndAt("c").LimitToFirst(8).OrderBy("field").Value(&v);err!=nil {log.Fatal(err)}fmt.Printf("%s\n",v)
v:=map[string]string{"foo":"bar"}iferr:=f.Set(v);err!=nil {log.Fatal(err)}
v:="bar"pushedFirego,err:=f.Push(v)iferr!=nil {log.Fatal(err)}varbarstringiferr:=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)
v:=map[string]string{"foo":"bar"}iferr:=f.Update(v);err!=nil {log.Fatal(err)}
iferr:=f.Remove();err!=nil {log.Fatal(err)}
notifications:=make(chan firego.Event)iferr:=f.Watch(notifications);err!=nil {log.Fatal(err)}deferf.StopWatching()forevent:=rangenotifications {fmt.Printf("Event %#v\n",event)}fmt.Printf("Notifications have stopped")
You can use a reference to save or read data from a specified reference
userID:="bar"usersRef,err:=f.Ref("users/"+userID)iferr!=nil {log.Fatal(err)}v:=map[string]string{"id":userID}iferr:=usersRef.Set(v);err!=nil {log.Fatal(err)}
Check theGoDocs orFirebase Documentation for more details
In order to run the tests you need togo get -t ./...first to go-get the test dependencies.
Feel free to open an issue if you come across any bugs orif you'd like to request a new feature.
- Fork it
- Create your feature branch (
git checkout -b new-feature) - Commit your changes (
git commit -am 'Some cool reflection') - Push to the branch (
git push origin new-feature) - Create new Pull Request
About
Firebase Go Client
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.