forked from acoshift/go-firebase-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.go
43 lines (37 loc) · 809 Bytes
/
database.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
package admin
import (
"fmt"
_url "net/url"
_path "path"
)
// Database type
type Database struct {
app *App
}
// ServerValue
var (
ServerValueTimestamp interface{} = struct {
SV string `json:".sv"`
}{"timestamp"}
)
func newDatabase(app *App) *Database {
return &Database{
app: app,
}
}
// Ref returns a Reference for a path
func (database *Database) Ref(path string) *Reference {
path = _path.Clean(path)
return &Reference{database: database, path: path}
}
// RefFromURL returns a Reference from an url
func (database *Database) RefFromURL(url string) (*Reference, error) {
u, err := _url.Parse(url)
if err != nil {
return nil, err
}
if u.Host != database.app.databaseURL {
return nil, fmt.Errorf("firebasedatabase: invalid host %v", u.Host)
}
return database.Ref(u.Path), nil
}