-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage.go
62 lines (41 loc) · 810 Bytes
/
storage.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
package main
import (
"io/ioutil"
"firebase.google.com/go/v4/storage"
)
func getWorldList(client *storage.Client) ([]string, error) {
bucket, err := client.DefaultBucket()
if err != nil {
return nil, err
}
iter := bucket.Objects(ctx, nil)
var names []string
for {
attrs, err := iter.Next()
if err != nil {
break
}
if attrs == nil {
break
}
names = append(names, attrs.Name)
}
return names, nil
}
func downloadWorld(client *storage.Client, name string) ([]byte, error) {
bucket, err := client.DefaultBucket()
if err != nil {
return nil, err
}
obj := bucket.Object(name)
file, err := obj.NewReader(ctx)
if err != nil {
return nil, err
}
defer file.Close()
data, err := ioutil.ReadAll(file)
if err != nil {
return nil, err
}
return data, nil
}