-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
59 lines (48 loc) · 1.13 KB
/
types.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
package meta
import (
"context"
"errors"
"strings"
)
type Meta interface {
NewVersion(context.Context, *File, string) (*FileVersion, error)
NewPart(context.Context, *File, *FileVersion, *Part) error
UpdateStatus(context.Context, *File, *FileVersion) error
GetVersion(context.Context, *File) (*FileVersion, error)
}
type File struct {
Bucket string `json:"bucket"`
Key string `json:"key"`
}
func (f File) String() string {
return strings.Join([]string{f.Bucket, f.Key}, "/")
}
func FileFromString(s string) (File, error) {
parts := strings.SplitN(s, "/", 2)
if len(parts) != 2 {
return File{}, errors.New("invalid file format")
}
return File{Bucket: parts[0], Key: parts[1]}, nil
}
type FileVersion struct {
Version int `json:"version"`
ContentType string `json:"content_type"`
Status Status `json:"status"`
Parts []Part `json:"parts"`
}
type Part struct {
Servers []int `json:"servers"`
Index int `json:"index"`
}
type FilePart struct {
Bucket string
Key string
Version int
Part int
}
type Status string
const (
StatusLoading = "loading"
StatusReady = "ready"
StatusError = "error"
)