forked from wuman/firego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
158 lines (133 loc) · 3.41 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package firego_test
import (
"log"
"time"
"github.com/zabawaba99/firego"
)
func ExampleFirebase_Auth() {
fb := firego.New("https://someapp.firebaseio.com", nil)
fb.Auth("my-token")
}
func ExampleFirebase_Child() {
fb := firego.New("https://someapp.firebaseio.com", nil)
childFB := fb.Child("some/child/path")
log.Printf("My new ref %s\n", childFB)
}
func ExampleFirebase_Shallow() {
fb := firego.New("https://someapp.firebaseio.com", nil)
// Set value
fb.Shallow(true)
// Remove query parameter
fb.Shallow(false)
}
func ExampleFirebase_IncludePriority() {
fb := firego.New("https://someapp.firebaseio.com", nil)
// Set value
fb.IncludePriority(true)
// Remove query parameter
fb.IncludePriority(false)
}
func ExampleFirebase_StartAt() {
fb := firego.New("https://someapp.firebaseio.com", nil)
// Set value
fb = fb.StartAt("a")
// Remove query parameter
fb = fb.StartAt("")
}
func ExampleFirebase_EndAt() {
fb := firego.New("https://someapp.firebaseio.com", nil)
// Set value
fb = fb.EndAt("a")
// Remove query parameter
fb = fb.EndAt("")
}
func ExampleFirebase_OrderBy() {
fb := firego.New("https://someapp.firebaseio.com", nil)
// Set value
fb = fb.OrderBy("a")
// Remove query parameter
fb = fb.OrderBy("")
}
func ExampleFirebase_LimitToFirst() {
fb := firego.New("https://someapp.firebaseio.com", nil)
// Set value
fb = fb.LimitToFirst(5)
// Remove query parameter
fb = fb.LimitToFirst(-1)
}
func ExampleFirebase_LimitToLast() {
fb := firego.New("https://someapp.firebaseio.com", nil)
// Set value
fb = fb.LimitToLast(8)
// Remove query parameter
fb = fb.LimitToLast(-1)
}
func ExampleFirebase_Push() {
fb := firego.New("https://someapp.firebaseio.com", nil)
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", nil)
if err := fb.Remove(); err != nil {
log.Fatal(err)
}
}
func ExampleFirebase_Set() {
fb := firego.New("https://someapp.firebaseio.com", nil)
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", nil)
if err := fb.Update("new-value"); err != nil {
log.Fatal(err)
}
}
func ExampleFirebase_Value() {
fb := firego.New("https://someapp.firebaseio.com/some/value", nil)
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", nil)
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", nil)
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()
}