-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupcloud.go
More file actions
66 lines (61 loc) · 1.51 KB
/
Copy pathupcloud.go
File metadata and controls
66 lines (61 loc) · 1.51 KB
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
package main
import (
"fmt"
"strings"
"sync"
"github.com/cnbattle/upcloud/config"
"github.com/cnbattle/upcloud/utils"
"github.com/panjf2000/ants/v2"
)
func main() {
platform := config.GetEnvForPanic("UP_CLOUD_PLATFORM")
commInterface, err := selectInterFace(platform)
if err != nil {
fmt.Println("selectInterFace error:", err)
return
}
err = commInterface.Init()
if err != nil {
fmt.Println("commInterface.Init error:", err)
return
}
// 获取已存在文件列表
fmt.Println("Start to clear data.")
getAll, err := commInterface.GetAll()
if len(getAll) > 0 {
// 删除已存在文件
_ = commInterface.DelAll(getAll)
}
// 上传新的文件
fmt.Println("Start uploading data.")
files := utils.Local(config.GetEnvForPanic("UP_CLOUD_PATH"))
pool, _ := ants.NewPool(config.GetDefaultEnvToInt("UP_CLOUD_POOL_SIZE", 10))
defer pool.Release()
var wg sync.WaitGroup
for _, file := range files {
wg.Add(1)
local := file.Local
upKey := file.UpKey
err = pool.Submit(func() {
err := commInterface.Upload(local, upKey)
if err != nil {
fmt.Println("commInterface.Upload error:", err)
}
fmt.Print(".")
wg.Done()
})
if err != nil {
fmt.Println("pool.Submit error:", err)
}
}
wg.Wait()
fmt.Println()
fmt.Println("Start refreshing CDN data.")
prefetch := config.GetEnvForPanic("UP_CLOUD_PREFETCH_URLS")
err = commInterface.Prefetch(strings.Split(prefetch, ","))
if err != nil {
fmt.Println("commInterface.Prefetch error:", err)
return
}
fmt.Print("Successful !!!")
}