feat(错误提示): 添加错误提示
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
xiaoqidun 2020-12-24 11:49:24 +08:00
parent 7503222aad
commit a7b5361054

View File

@ -2,6 +2,7 @@ package main
import ( import (
"context" "context"
"errors"
"github.com/tencentyun/cos-go-sdk-v5" "github.com/tencentyun/cos-go-sdk-v5"
"io/fs" "io/fs"
"log" "log"
@ -13,7 +14,6 @@ import (
) )
const ( const (
CodeErr = 1
SecretID = "secret_id" SecretID = "secret_id"
SecretKey = "secret_key" SecretKey = "secret_key"
BucketURL = "bucket_url" BucketURL = "bucket_url"
@ -23,6 +23,11 @@ const (
PathSeparator = "/" PathSeparator = "/"
) )
func ErrExit(err error) {
log.Println(err.Error())
os.Exit(1)
}
func GetConfig(key string) string { func GetConfig(key string) string {
key = "PLUGIN_" + strings.ToUpper(key) key = "PLUGIN_" + strings.ToUpper(key)
return os.Getenv(key) return os.Getenv(key)
@ -59,8 +64,7 @@ func main() {
stripPrefix = GetConfig(StripPrefix) stripPrefix = GetConfig(StripPrefix)
) )
if !VarIsEmpty(secretID, secretKey, bucketURL, source, target) { if !VarIsEmpty(secretID, secretKey, bucketURL, source, target) {
os.Exit(CodeErr) ErrExit(errors.New("input error"))
return
} }
sourceFiles := make([]string, 0, 0) sourceFiles := make([]string, 0, 0)
if err = filepath.WalkDir(source, func(path string, d fs.DirEntry, err error) error { if err = filepath.WalkDir(source, func(path string, d fs.DirEntry, err error) error {
@ -69,8 +73,7 @@ func main() {
} }
return nil return nil
}); err != nil { }); err != nil {
os.Exit(CodeErr) ErrExit(err)
return
} }
sourceLen := len(sourceFiles) sourceLen := len(sourceFiles)
if sourceLen == 0 { if sourceLen == 0 {
@ -81,8 +84,7 @@ func main() {
} }
u, err := url.Parse(bucketURL) u, err := url.Parse(bucketURL)
if err != nil { if err != nil {
os.Exit(CodeErr) ErrExit(err)
return
} }
cosClient := cos.NewClient( cosClient := cos.NewClient(
&cos.BaseURL{ &cos.BaseURL{
@ -105,8 +107,7 @@ func main() {
ACLHeaderOptions: &cos.ACLHeaderOptions{}, ACLHeaderOptions: &cos.ACLHeaderOptions{},
ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{}, ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{},
}); err != nil { }); err != nil {
os.Exit(CodeErr) ErrExit(err)
return
} }
log.Printf("source:%s target:%s\r\n", local, remote) log.Printf("source:%s target:%s\r\n", local, remote)
} }