mirror of
https://github.com/xiaoqidun/gocos.git
synced 2024-12-03 19:19:13 +08:00
This commit is contained in:
parent
7503222aad
commit
a7b5361054
19
gocos.go
19
gocos.go
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"io/fs"
|
||||
"log"
|
||||
@ -13,7 +14,6 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
CodeErr = 1
|
||||
SecretID = "secret_id"
|
||||
SecretKey = "secret_key"
|
||||
BucketURL = "bucket_url"
|
||||
@ -23,6 +23,11 @@ const (
|
||||
PathSeparator = "/"
|
||||
)
|
||||
|
||||
func ErrExit(err error) {
|
||||
log.Println(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func GetConfig(key string) string {
|
||||
key = "PLUGIN_" + strings.ToUpper(key)
|
||||
return os.Getenv(key)
|
||||
@ -59,8 +64,7 @@ func main() {
|
||||
stripPrefix = GetConfig(StripPrefix)
|
||||
)
|
||||
if !VarIsEmpty(secretID, secretKey, bucketURL, source, target) {
|
||||
os.Exit(CodeErr)
|
||||
return
|
||||
ErrExit(errors.New("input error"))
|
||||
}
|
||||
sourceFiles := make([]string, 0, 0)
|
||||
if err = filepath.WalkDir(source, func(path string, d fs.DirEntry, err error) error {
|
||||
@ -69,8 +73,7 @@ func main() {
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
os.Exit(CodeErr)
|
||||
return
|
||||
ErrExit(err)
|
||||
}
|
||||
sourceLen := len(sourceFiles)
|
||||
if sourceLen == 0 {
|
||||
@ -81,8 +84,7 @@ func main() {
|
||||
}
|
||||
u, err := url.Parse(bucketURL)
|
||||
if err != nil {
|
||||
os.Exit(CodeErr)
|
||||
return
|
||||
ErrExit(err)
|
||||
}
|
||||
cosClient := cos.NewClient(
|
||||
&cos.BaseURL{
|
||||
@ -105,8 +107,7 @@ func main() {
|
||||
ACLHeaderOptions: &cos.ACLHeaderOptions{},
|
||||
ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{},
|
||||
}); err != nil {
|
||||
os.Exit(CodeErr)
|
||||
return
|
||||
ErrExit(err)
|
||||
}
|
||||
log.Printf("source:%s target:%s\r\n", local, remote)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user