From 704bd5deec2580ac4fe0c12bb6333c9533fdc4a0 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Wed, 4 Jan 2017 22:53:53 -0800 Subject: [PATCH 1/5] Fix .Shallow() Before this change, the library would set ?shallow="true" (note the extra quotes), which would silently fail (because the .Iterator() method has no error return path). After this change, .Shallow() works and returns errors as expected. --- firebase.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/firebase.go b/firebase.go index cec8ba9..d827033 100644 --- a/firebase.go +++ b/firebase.go @@ -328,12 +328,19 @@ func (c *client) Iterator(d Destination) <-chan *KeyedValue { } func (c *client) Shallow() ([]string, error) { - c.params = c.newParamMap("shallow", "true") - ch := c.Iterator(nil) - keySlice := []string{} - for kv := range ch { - keySlice = append(keySlice, kv.Key) + results := make(map[string]bool) + + err := c.clientWithNewParam("shallow", true).Value(&results) + if err != nil { + return nil, err } + + keySlice := make([]string, 0, len(results)) + + for k, _ := range results { + keySlice = append(keySlice, k) + } + return keySlice, nil } From 41ce10f931e70a8990d8231d7709dce96bbb576a Mon Sep 17 00:00:00 2001 From: Islam Sharabash Date: Tue, 14 Feb 2017 12:53:03 -0800 Subject: [PATCH 2/5] Adding original StatusCode to FirebaseError --- firebase.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/firebase.go b/firebase.go index d827033..ae4fa16 100644 --- a/firebase.go +++ b/firebase.go @@ -76,7 +76,8 @@ type ServerValue struct { } type FirebaseError struct { - Message string `json:"error"` + Message string `json:"error"` + StatusCode int } func (f *FirebaseError) Error() string { @@ -508,6 +509,7 @@ func (f *f) Call(method, path, auth string, body interface{}, params map[string] if res.StatusCode >= 400 { err := &FirebaseError{} decoder.Decode(err) + err.StatusCode = res.StatusCode return err } From 01f24b464da3a979fc251105bff6ee8c85edf509 Mon Sep 17 00:00:00 2001 From: Islam Sharabash Date: Tue, 21 Feb 2017 16:10:49 -0800 Subject: [PATCH 3/5] Adding ability to set auth on client after creation --- firebase.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/firebase.go b/firebase.go index ae4fa16..fe95447 100644 --- a/firebase.go +++ b/firebase.go @@ -202,6 +202,7 @@ type Client interface { // Query functions. They map directly to the Firebase operations. // https://www.firebase.com/docs/rest/guide/retrieving-data.html#section-rest-queries + Auth(auth string) Client OrderBy(prop string) Client EqualTo(value string) Client StartAt(value string) Client @@ -381,6 +382,12 @@ func (c *client) clientWithNewParam(key string, value interface{}) *client { // Query functions. They map directly to the Firebase operations. // https://www.firebase.com/docs/rest/guide/retrieving-data.html#section-rest-queries +func (c *client) Auth(auth string) Client { + newC := c.clientWithNewParam("auth", auth) + newC.auth = "" + return newC +} + func (c *client) OrderBy(prop string) Client { newC := c.clientWithNewParam("orderBy", prop) newC.Order = prop From ecec5fee22ef16ebbcaeb29933bc654e46351f6f Mon Sep 17 00:00:00 2001 From: Islam Sharabash Date: Mon, 6 Mar 2017 10:09:58 -0800 Subject: [PATCH 4/5] Fixing implementation of replacing auth param in firebase client --- firebase.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/firebase.go b/firebase.go index fe95447..905eb28 100644 --- a/firebase.go +++ b/firebase.go @@ -360,12 +360,17 @@ const ( KeyProp = "$key" ) -// These are some shenanigans, golang. Shenanigans I say. -func (c *client) newParamMap(key string, value interface{}) map[string]string { - ret := make(map[string]string, len(c.params)+1) +func (c *client) copyParamMap() map[string]string { + ret := make(map[string]string, len(c.params)) for key, value := range c.params { ret[key] = value } + return ret +} + +// These are some shenanigans, golang. Shenanigans I say. +func (c *client) newParamMap(key string, value interface{}) map[string]string { + ret := c.copyParamMap() jsonVal, _ := json.Marshal(value) ret[key] = string(jsonVal) return ret @@ -383,9 +388,12 @@ func (c *client) clientWithNewParam(key string, value interface{}) *client { // Query functions. They map directly to the Firebase operations. // https://www.firebase.com/docs/rest/guide/retrieving-data.html#section-rest-queries func (c *client) Auth(auth string) Client { - newC := c.clientWithNewParam("auth", auth) - newC.auth = "" - return newC + return &client{ + api: c.api, + auth: auth, + url: c.url, + params: c.copyParamMap(), + } } func (c *client) OrderBy(prop string) Client { From 8539a999e7e161e19ce0df0323238ed1a5972587 Mon Sep 17 00:00:00 2001 From: Islam Sharabash Date: Mon, 18 Sep 2017 14:15:24 -0700 Subject: [PATCH 5/5] Increase readWriteTimeout to 1 minute When running the migrator on Gaurav's production data this timeout was hit often because he has ~40mb of data in firebase. Set the timeout to a minute to avoid that case. --- firebase.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase.go b/firebase.go index 905eb28..609980f 100644 --- a/firebase.go +++ b/firebase.go @@ -263,7 +263,7 @@ type f struct{} var ( connectTimeout = time.Duration(30 * time.Second) // timeout for http connection - readWriteTimeout = time.Duration(10 * time.Second) // timeout for http read/write + readWriteTimeout = time.Duration(60 * time.Second) // timeout for http read/write ) // httpClient is the HTTP client used to make calls to Firebase with the default API