-
Notifications
You must be signed in to change notification settings - Fork 18
/
main.go
68 lines (57 loc) · 1.75 KB
/
main.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
package main
import (
"fmt"
"os"
"aliyun-oss-website-action/config"
"aliyun-oss-website-action/operation"
"aliyun-oss-website-action/utils"
)
func main() {
defer utils.TimeCost()()
if config.Folder == "/" {
fmt.Println("You should not upload the root directory, use ./ instead. 通常来说, 你不应该上传根目录, 也许你是要配置 ./")
os.Exit(1)
}
if !config.SkipSetting {
operation.SetStaticWebsiteConfig()
} else {
fmt.Println("skip setting static pages related configuration")
}
var incremental *operation.IncrementalConfig
if config.IsIncremental {
fmt.Println("---- [incremental] ---->")
incremental, _ = operation.GetRemoteIncrementalConfig(config.Bucket)
fmt.Println("<---- [incremental end] ----")
fmt.Println()
}
if !config.IsIncremental || incremental == nil {
// TODO: delete after upload
fmt.Println("---- [delete] ---->")
deleteErrs := operation.DeleteObjects(config.Bucket)
utils.LogErrors(deleteErrs)
fmt.Println("<---- [delete end] ----")
fmt.Println()
}
records := utils.WalkDir(config.Folder)
fmt.Println("---- [upload] ---->")
uploaded, uploadErrs := operation.UploadObjects(config.Folder, config.Bucket, records, incremental)
utils.LogErrors(uploadErrs)
fmt.Println("<---- [upload end] ----")
fmt.Println()
if config.IsIncremental && incremental != nil {
fmt.Println("---- [delete] ---->")
deleteErrs := operation.DeleteObjectsIncremental(config.Bucket, incremental)
utils.LogErrors(deleteErrs)
fmt.Println("<---- [delete end] ----")
fmt.Println()
}
if config.IsIncremental {
fmt.Println("---- [incremental] ---->")
operation.UploadIncrementalConfig(config.Bucket, uploaded)
fmt.Println("<---- [incremental end] ----")
fmt.Println()
}
if len(uploadErrs) > 0 {
os.Exit(1)
}
}