Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Mar 31, 2019. It is now read-only.
/firegoPublic archive

Firebase Go Client

License

NotificationsYou must be signed in to change notification settings

zabawaba99/firego

Repository files navigation

Deprecated in favor offirebase/firebase-admin-go.


Build StatusCoverage Status

A Firebase client written in Go

Installation

go get -u gopkg.in/zabawaba99/firego.v1

Usage

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)

Request Timeouts

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

Authentication

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

Legacy Tokens

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

VisitFireauth if you'd like to generate your own auth tokens

Get Value

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

Querying

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)

Set Value

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

Push Value

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)

Update Child

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

Remove Value

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

Watch a Node

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")

Change reference

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

Running Tests

In order to run the tests you need togo get -t ./...first to go-get the test dependencies.

Issues Management

Feel free to open an issue if you come across any bugs orif 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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors19

Languages


[8]ページ先頭

©2009-2026 Movatter.jp