-
Notifications
You must be signed in to change notification settings - Fork 2
/
filemigrationlog.go
77 lines (69 loc) · 1.43 KB
/
filemigrationlog.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package files_sdk
import (
"context"
"encoding/json"
"net/http"
"time"
)
type FilesMigrationLog struct {
Type string `json:"type"`
Timestamp time.Time `json:"timestamp"`
Operation string `json:"operation"`
Status string `json:"status"`
FileType string `json:"file_type"`
Path string `json:"path"`
DestPath string `json:"dest_path"`
}
type FilesMigrationLogIter struct {
context.Context
Config
FileMigration
next func() bool
more func() bool
error
current interface{}
}
func (l *FilesMigrationLogIter) Err() error {
return l.error
}
func (l *FilesMigrationLogIter) Current() interface{} {
return l.current
}
func (l *FilesMigrationLogIter) Next() bool {
return l.next()
}
func (l FilesMigrationLogIter) Init() *FilesMigrationLogIter {
l.next = func() bool {
return false
}
if l.FileMigration.LogUrl != "" {
req, err := http.NewRequestWithContext(l.Context, "GET", l.FileMigration.LogUrl, nil)
if err != nil {
l.error = err
return &l
}
resp, err := l.Config.GetHttpClient().Do(req)
if err != nil {
l.error = err
return &l
}
decoder := json.NewDecoder(resp.Body)
l.more = decoder.More
l.next = func() bool {
if l.error != nil {
return false
}
if l.more() {
var log FilesMigrationLog
if err := decoder.Decode(&log); err != nil {
l.error = err
return false
}
l.current = log
return true
}
return false
}
}
return &l
}