forked from zabawaba99/firego
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample_test.go
118 lines (98 loc) · 2.45 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package firego_test
import (
"log"
"time"
"github.com/CloudCom/firego"
)
func ExampleFirebase_Auth() {
fb := firego.New("https://someapp.firebaseio.com")
fb.Auth("my-token")
}
func ExampleFirebase_Child() {
fb := firego.New("https://someapp.firebaseio.com")
childFB := fb.Child("some/child/path")
log.Printf("My new ref %s\n", childFB)
}
func ExampleFirebase_Shallow() {
fb := firego.New("https://someapp.firebaseio.com")
// turn on
fb.Shallow(true)
// turn off
fb.Shallow(false)
}
func ExampleFirebase_IncludePriority() {
fb := firego.New("https://someapp.firebaseio.com")
// turn on
fb.IncludePriority(true)
// turn off
fb.IncludePriority(false)
}
func ExampleFirebase_Push() {
fb := firego.New("https://someapp.firebaseio.com")
newRef, err := fb.Push("my-value")
if err != nil {
log.Fatal(err)
}
log.Printf("My new ref %s\n", newRef)
}
func ExampleFirebase_Remove() {
fb := firego.New("https://someapp.firebaseio.com/some/value")
if err := fb.Remove(); err != nil {
log.Fatal(err)
}
}
func ExampleFirebase_Set() {
fb := firego.New("https://someapp.firebaseio.com")
v := map[string]interface{}{
"foo": "bar",
"bar": 1,
"bez": []string{"hello", "world"},
}
if err := fb.Set(v); err != nil {
log.Fatal(err)
}
}
func ExampleFirebase_Update() {
fb := firego.New("https://someapp.firebaseio.com/some/value")
if err := fb.Update("new-value"); err != nil {
log.Fatal(err)
}
}
func ExampleFirebase_Value() {
fb := firego.New("https://someapp.firebaseio.com/some/value")
var v interface{}
if err := fb.Value(v); err != nil {
log.Fatal(err)
}
log.Printf("My value %v\n", v)
}
func ExampleFirebase_Watch() {
fb := firego.New("https://someapp.firebaseio.com/some/value")
notifications := make(chan firego.Event)
if err := fb.Watch(notifications); err != nil {
log.Fatal(err)
}
for event := range notifications {
log.Println("Event Received")
log.Printf("Type: %s\n", event.Type)
log.Printf("Path: %s\n", event.Path)
log.Printf("Data: %v\n", event.Data)
if event.Type == firego.EventTypeError {
log.Print("Error occurred, loop ending")
}
}
}
func ExampleFirebase_StopWatching() {
fb := firego.New("https://someapp.firebaseio.com/some/value")
notifications := make(chan firego.Event)
if err := fb.Watch(notifications); err != nil {
log.Fatal(err)
}
go func() {
for _ = range notifications {
}
log.Println("Channel closed")
}()
time.Sleep(10 * time.Millisecond) // let go routine start
fb.StopWatching()
}