Documentation ¶
Overview ¶
Package firebase gives a thin wrapper around the firebase REST API. It tries to mirror the Official firebase API somewhat closely. https://www.firebase.com/docs/web/api/
Index ¶
Constants ¶
const (
KeyProp = "$key"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Api ¶
type Api interface {
Call(method, path, auth string, body interface{}, params map[string]string, dest interface{}) error
}
Api is the internal interface for interacting with Firebase. Consumers of this package can mock this interface for testing purposes, regular consumers can just use the default implementation and can ignore this completely. Arguments are as follows:
- `method`: The http method for this call
- `path`: The full firebase url to call
- `body`: Data to be marshalled to JSON (it's the responsibility of Call to do the marshalling and unmarshalling)
- `params`: Additional parameters to be passed to firebase
- `dest`: The object to save the unmarshalled response body to. It's up to this method to unmarshal correctly, the default implemenation just uses `json.Unmarshal`
type Client ¶
type Client interface { // Returns the absolute URL path for the client String() string // Returns the last part of the URL path for the client. Key() string //Gets the value referenced by the client and unmarshals it into // the passed in destination. Value(destination interface{}) error // Iterator returns a channel that will emit objects in order defined by // Client#OrderBy Iterator(d Destination) <-chan *KeyedValue // Shallow returns a list of keys at a particular location // Only supports objects, unlike the REST artument which supports // literals. If the location is a literal, use Client#Value() Shallow() ([]string, error) // Child returns a reference to the child specified by `path`. This does not // actually make a request to firebase, but you can then manipulate the reference // by calling one of the other methods (such as `Value`, `Update`, or `Set`). Child(path string) Client // Query functions. They map directly to the Firebase operations. // https://www.firebase.com/docs/rest/guide/retrieving-data.html#section-rest-queries OrderBy(prop string) Client EqualTo(value string) Client StartAt(value string) Client EndAt(value string) Client LimitToFirst(value int) Client LimitToLast(value int) Client // Creates a new value under this reference. // Returns a reference to the newly created value. // https://www.firebase.com/docs/web/api/firebase/push.html Push(value interface{}, params map[string]string) (Client, error) // Overwrites the value at the specified path and returns a reference // that points to the path specified by `path` Set(path string, value interface{}, params map[string]string) (Client, error) // Update performs a partial update with the given value at the specified path. // Returns an error if the update could not be performed. // https://www.firebase.com/docs/web/api/firebase/update.html Update(path string, value interface{}, params map[string]string) error // Remove deletes the data at the current reference. // https://www.firebase.com/docs/web/api/firebase/remove.html Remove(path string, params map[string]string) error // Rules returns the security rules for the database. // https://www.firebase.com/docs/rest/api/#section-security-rules Rules(params map[string]string) (*Rules, error) // SetRules overwrites the existing security rules with the new rules given. // https://www.firebase.com/docs/rest/api/#section-security-rules SetRules(rules *Rules, params map[string]string) error }
type Destination ¶
type Destination func() interface{}
A function that provides an interface to copy decoded data into in Client#Iterator
type FirebaseError ¶
type FirebaseError struct {
Message string `json:"error"`
}
func (*FirebaseError) Error ¶
func (f *FirebaseError) Error() string
type KeyedValue ¶
type KeyedValue struct { avltree.Pair OrderBy string }
func (*KeyedValue) Compare ¶
func (a *KeyedValue) Compare(b avltree.Interface) int
func (*KeyedValue) GetComparable ¶
func (p *KeyedValue) GetComparable() reflect.Value
type ServerValue ¶
type ServerValue struct {
Value string `json:".sv"`
}
var ServerTimestamp ServerValue = ServerValue{"timestamp"}
Use this value to represent a Firebase server timestamp in a data structure. This should be used when you're sending data to Firebase, as opposed to the Timestamp type.
type Timestamp ¶
Timestamp is a time.Time with support for going from and to firebase ServerValue.TIMESTAMP fields.
Thanks to Gal Ben-Haim for the inspiration https://medium.com/coding-and-deploying-in-the-cloud/time-stamps-in-golang-abcaf581b72f