firebase

package module
v0.0.0-...-f605914 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2016 License: MIT Imports: 11 Imported by: 0

README

Go Firebase

Summary

Helper library for invoking the Firebase REST API.

Installation

Build
go get github.com/cosn/firebase
Test

Edit the firebase_test.go file and set the testUrl and testKey variables to match your Firebase account.

Then run:

go test github.com/cosn/firebase...

Usage

First import the package into your code:

import (
    "github.com/cosn/firebase"
)

To use the client, initialize it and make requests similarly to the Firebase docs:

firebase := new(firebase.Client)
firebase.Init("https://<TBD>.firebase.com", "<optional authentication token>", nil)

n := &Name { First: "Jack", Last: "Sparrow" }
jack, err_ := firebase.Child("users/jack", nil, nil).Set("name", n, nil)

Currently, the following methods are supported:

Child(path)
Push(value)
Set(path, value)
Update(path, value)
Remove(path)
Value()
Rules()
SetRules(rules)

For more details about this library, see the GoDoc documentation.

For more details about the Firebase APIs, see the Firebase official documentation.

Documentation

Overview

Package firebase impleements a RESTful client for Firebase.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TimeoutDialer

func TimeoutDialer(cTimeout time.Duration, rwTimeout time.Duration) func(net, addr string) (c net.Conn, err error)

Types

type Api

type Api interface {
	Call(method, path, auth string, body []byte, params map[string]string) ([]byte, error)
}

Api is the interface for interacting with Firebase. Consumers of this package can mock this interface for testing purposes.

type Client

type Client struct {
	// Url is the client's base URL used for all calls.
	Url string

	// Auth is authentication token used when making calls.
	// The token is optional and can also be overwritten on an individual
	// call basis via params.
	Auth string
	// contains filtered or unexported fields
}

Client is the Firebase client.

func (*Client) Child

func (c *Client) Child(path string, params map[string]string, v interface{}) (*Client, error)

Child returns a populated pointer for a given path. If the path cannot be found, a null pointer is returned.

func (*Client) Init

func (c *Client) Init(root, auth string, api Api)

Init initializes the Firebase client with a given root url and optional auth token. The initialization can also pass a mock api for testing purposes.

func (*Client) Push

func (c *Client) Push(value interface{}, params map[string]string) (*Client, error)

Push creates a new value under the current root url. A populated pointer with that value is also returned.

func (*Client) Remove

func (c *Client) Remove(path string, params map[string]string) error

Remove deletes the data at the given path.

func (*Client) Rules

func (c *Client) Rules(params map[string]string) (Rules, error)

Rules returns the security rules for the database.

func (*Client) Set

func (c *Client) Set(path string, value interface{}, params map[string]string) (*Client, error)

Set overwrites the value at the specified path and returns populated pointer for the updated path.

func (*Client) SetPath

func (c *Client) SetPath(path string) *Client

func (*Client) SetRules

func (c *Client) SetRules(rules *Rules, params map[string]string) error

SetRules overwrites the existing security rules with the new rules given.

func (*Client) Update

func (c *Client) Update(value interface{}, params map[string]string) error

Update performs a partial update with the given value at the specified path.

func (*Client) Value

func (c *Client) Value() (interface{}, error)

Value returns the value of of the current Url.

type Rules

type Rules map[string]interface{}

Rules is the structure for security rules.

Jump to

Keyboard shortcuts

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