-
Notifications
You must be signed in to change notification settings - Fork 623
/
tasks.go
64 lines (47 loc) 路 1.3 KB
/
tasks.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
package filetransfer
import (
"context"
"fmt"
)
type TaskType int
const (
UploadTask TaskType = iota
DownloadTask
)
// Task is a task to upload/download a file
type Task struct {
// FileKind is the category of file being uploaded or downloaded
FileKind RunFileKind
// Type is the type of task (upload or download)
Type TaskType
// Path is the local path to the file
Path string
// Name is the name of the file
Name string
// Url is the endpoint to upload to/download from
Url string
// Headers to send on the upload
Headers []string
// Size is the size of the file
Size int64
// Error, if any.
Err error
// Callback to execute after completion (success or failure).
CompletionCallback func(*Task)
// ProgressCallback is a callback to execute on progress updates
ProgressCallback func(int, int)
// This can be used to cancel the file upload or download if it is no longer needed.
Context context.Context
}
func (ut *Task) SetProgressCallback(callback func(int, int)) {
ut.ProgressCallback = callback
}
func (ut *Task) SetCompletionCallback(callback func(*Task)) {
ut.CompletionCallback = callback
}
func (ut *Task) String() string {
return fmt.Sprintf(
"Task{FileKind: %d, Type: %d, Path: %s, Name: %s, Url: %s, Size: %d}",
ut.FileKind, ut.Type, ut.Path, ut.Name, ut.Url, ut.Size,
)
}