-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtask.go
56 lines (46 loc) · 1012 Bytes
/
task.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
/**
* File: task.go
* Author: Ming Cheng<mingcheng@outlook.com>
*
* Created Date: Saturday, July 6th 2019, 10:56:26 pm
* Last Modified: Sunday, July 7th 2019, 7:05:57 am
*
* http://www.opensource.org/licenses/MIT
*/
package obsync
import (
"context"
"fmt"
)
type Task struct {
FilePath string
Key string
Overrides bool
Client *BucketSync
}
func (t *Task) Put(ctx context.Context) (err error) {
if t.Client == nil {
return fmt.Errorf("the client is nil")
}
if (*t.Client).Exists(ctx, t.Key) && !t.Overrides {
return fmt.Errorf("%s is already exists", t.Key)
}
return (*t.Client).Put(ctx, t.FilePath, t.Key)
}
func NewTask(key, path string, overrides bool, config BucketConfig) (task *Task, err error) {
fn, err := GetBucketSyncFunc(config.Type)
if err != nil {
return nil, err
}
client, err := fn(config)
if err != nil {
return nil, err
}
task = &Task{
Key: key,
FilePath: path,
Overrides: overrides,
Client: &client,
}
return task, nil
}