mirror of
				https://github.com/xiaoqidun/gocos.git
				synced 2025-11-04 14:59:37 +08:00 
			
		
		
		
	This commit is contained in:
		
							
								
								
									
										19
									
								
								gocos.go
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								gocos.go
									
									
									
									
									
								
							@@ -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)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user