-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmindmap.go
60 lines (46 loc) · 850 Bytes
/
mindmap.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
package mindmap
type Chunk byte
type File []Chunk
func (f *File) Equals(f2 *File) bool {
return false
}
type (
network interface {
Sync(Chunk) error
}
localstore interface {
Put(Chunk) error
Has(*ID) (bool, error)
Get(*ID) (Chunk, error)
}
)
type App struct {
network network
localstore localstore
}
type ID byte
func (a *App) Upload(f File) *ID {
for _, chunk := range f {
if mustStay(chunk) {
_ = a.localstore.Put(chunk)
continue
}
a.network.Sync(chunk)
}
return new(ID)
}
func mustStay(Chunk) bool {
return false
}
func (a *App) Download(addr *ID) (*File, error) {
if found, _ := a.localstore.Has(addr); found {
chunk, _ := a.localstore.Get(addr)
f := File([]Chunk{chunk})
return &f, nil
}
// sync from network...
return new(File), nil
}
func (a *App) Pin(addr *ID) bool {
return false
}