From 3967104c57e85b90a2e331ebcca05674300eddc1 Mon Sep 17 00:00:00 2001 From: flywukong <2229306838@qq.com> Date: Thu, 12 Oct 2023 11:10:46 +0800 Subject: [PATCH] fix: remove debug log and fix resume upload progress --- cmd/cmd_account.go | 5 ++--- cmd/cmd_object.go | 31 ++++++++++++++++--------------- cmd/cmd_policy.go | 2 +- cmd/main.go | 5 +++++ go.mod | 4 ++-- go.sum | 6 ++++-- 6 files changed, 30 insertions(+), 23 deletions(-) diff --git a/cmd/cmd_account.go b/cmd/cmd_account.go index c387f79..95318ee 100644 --- a/cmd/cmd_account.go +++ b/cmd/cmd_account.go @@ -254,7 +254,6 @@ func importKey(ctx *cli.Context) error { if err != nil { return toCmdErr(err) } - fmt.Println("- You must REMEMBER your password! Without the password, it's impossible to decrypt the key!") // encrypt the private key encryptContent, err = EncryptKey(key, password, EncryptScryptN, EncryptScryptP) @@ -274,7 +273,7 @@ func importKey(ctx *cli.Context) error { // if it is the first keystore, set it as the default key checkAndWriteDefaultKey(homeDir, convertAddressToLower(key.Address.String())) - fmt.Printf("key address: %s, encrypted key file: %s \n", key.Address, keyFilePath) + fmt.Printf("imported account: %s, keystore: %s \n", key.Address, keyFilePath) return nil } @@ -428,7 +427,7 @@ func createAccount(ctx *cli.Context) error { // if it is the first keystore, set it as the default key checkAndWriteDefaultKey(homeDir, convertAddressToLower(key.Address.String())) - fmt.Printf("created new account: {%s} \n", account.GetAddress()) + fmt.Printf("created new account: {%s}, keystore: %s \n", account.GetAddress(), keyFilePath) return nil } diff --git a/cmd/cmd_object.go b/cmd/cmd_object.go index 9abca99..707837b 100644 --- a/cmd/cmd_object.go +++ b/cmd/cmd_object.go @@ -13,9 +13,8 @@ import ( "cosmossdk.io/math" "github.com/bnb-chain/greenfield-go-sdk/client" - "github.com/bnb-chain/greenfield/sdk/types" - sdktypes "github.com/bnb-chain/greenfield-go-sdk/types" + "github.com/bnb-chain/greenfield/sdk/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/urfave/cli/v2" ) @@ -486,26 +485,28 @@ func uploadFile(bucketName, objectName, filePath, urlInfo string, ctx *cli.Conte opt.DisableResumable = false } - if opt.DisableResumable { - progressReader := &ProgressReader{ - Reader: reader, - Total: objectSize, - StartTime: time.Now(), - LastPrinted: time.Now(), - } + progressReader := &ProgressReader{ + Reader: reader, + Total: objectSize, + StartTime: time.Now(), + LastPrinted: time.Now(), + } - // if print big file progress, the printing progress should be delayed to obtain a more accurate display. - if objectSize > progressDelayPrintSize { - progressReader.LastPrinted = time.Now().Add(2 * time.Second) - } + // if print big file progress, the printing progress should be delayed to obtain a more accurate display. + if objectSize > progressDelayPrintSize { + progressReader.LastPrinted = time.Now().Add(3 * time.Second) + } + if opt.DisableResumable { + fmt.Println("uploading is beginning...") if err = gnfdClient.PutObject(c, bucketName, objectName, objectSize, progressReader, opt); err != nil { return toCmdErr(err) } } else { + fmt.Println("resumable uploading is beginning...") if err = gnfdClient.PutObject(c, bucketName, objectName, - objectSize, reader, opt); err != nil { + objectSize, progressReader, opt); err != nil { return toCmdErr(err) } } @@ -524,7 +525,7 @@ func uploadFile(bucketName, objectName, filePath, urlInfo string, ctx *cli.Conte for { select { case <-timeout: - return toCmdErr(errors.New("object not sealed after 1 hour")) + return toCmdErr(errors.New("object not sealed after one hour")) case <-ticker.C: count++ headObjOutput, queryErr := gnfdClient.HeadObject(c, bucketName, objectName) diff --git a/cmd/cmd_policy.go b/cmd/cmd_policy.go index 7a8dbc3..f09db82 100644 --- a/cmd/cmd_policy.go +++ b/cmd/cmd_policy.go @@ -127,7 +127,7 @@ the resource url can be the follow types: 3) grn:g:owneraddress:groupname, it indicates the group policy Examples: -$ gnfd-cmd policy rm --groupId 111 grn:o::gnfd-bucket/gnfd-object`, +$ gnfd-cmd policy ls --groupId 111 grn:o::gnfd-bucket/gnfd-object`, Flags: []cli.Flag{ &cli.Uint64Flag{ Name: groupIDFlag, diff --git a/cmd/main.go b/cmd/main.go index cea26ca..8dfa3dd 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -7,12 +7,17 @@ import ( "os" "path/filepath" + "github.com/rs/zerolog" "github.com/urfave/cli/v2" "github.com/urfave/cli/v2/altsrc" ) var globalContext, _ = context.WithCancel(context.Background()) +func init() { + zerolog.SetGlobalLevel(zerolog.InfoLevel) +} + func main() { homeDir, err := os.UserHomeDir() if err != nil { diff --git a/go.mod b/go.mod index 7945791..634349e 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( github.com/bnb-chain/greenfield-go-sdk v1.0.0 github.com/cosmos/cosmos-sdk v0.47.3 github.com/ethereum/go-ethereum v1.10.26 + github.com/rs/zerolog v1.29.1 github.com/urfave/cli/v2 v2.10.2 golang.org/x/term v0.9.0 ) @@ -25,7 +26,7 @@ require ( github.com/armon/go-metrics v0.4.1 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect - github.com/bnb-chain/greenfield-common/go v0.0.0-20230830120314-a54ffd6da39f // indirect + github.com/bnb-chain/greenfield-common/go v0.0.0-20230906132736-eb2f0efea228 // indirect github.com/btcsuite/btcd v0.23.3 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect github.com/btcsuite/btcd/btcutil v1.1.2 // indirect @@ -107,7 +108,6 @@ require ( github.com/prysmaticlabs/prysm v0.0.0-20220124113610-e26cde5e091b // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rjeczalik/notify v0.9.1 // indirect - github.com/rs/zerolog v1.29.1 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sasha-s/go-deadlock v0.3.1 // indirect github.com/sirupsen/logrus v1.9.3 // indirect diff --git a/go.sum b/go.sum index 6986f83..5f36ac5 100644 --- a/go.sum +++ b/go.sum @@ -160,10 +160,12 @@ github.com/bnb-chain/greenfield-cometbft v1.0.0 h1:0r6hOJWD/+es0gxP/exKuN/krgXAr github.com/bnb-chain/greenfield-cometbft v1.0.0/go.mod h1:f35mk/r5ab6yvzlqEWZt68LfUje68sYgMpVlt2CUYMk= github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1 h1:XcWulGacHVRiSCx90Q8Y//ajOrLNBQWR/KDB89dy3cU= github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1/go.mod h1:ey1CiK4bYo1RBNJLRiVbYr5CMdSxci9S/AZRINLtppI= -github.com/bnb-chain/greenfield-common/go v0.0.0-20230830120314-a54ffd6da39f h1:zJvB2wCd80DQ9Nh/ZNQiP8MrHygSpDoav7OzHyIi/pM= -github.com/bnb-chain/greenfield-common/go v0.0.0-20230830120314-a54ffd6da39f/go.mod h1:it3JJVHeG9Wp4QED2GkY/7V9Qo3BuPdoC5/4/U6ecJM= +github.com/bnb-chain/greenfield-common v0.0.8 h1:OGRXHurdjPhdgAmLzMzNccFvsS0aIb4a/03IuqHYeME= +github.com/bnb-chain/greenfield-common v0.0.8/go.mod h1:XW4HfxK9D61fLflqfp4OUqtVJuRaf6j8LSygmIs2EAk= github.com/bnb-chain/greenfield-cosmos-sdk v1.0.0 h1:hWRvYunA4Um19gwL1SVfMwN9l431ROC7XZ+A5+xM/Bk= github.com/bnb-chain/greenfield-cosmos-sdk v1.0.0/go.mod h1:y3hDhQhil5hMIhwBTpu07RZBF30ZITkoE+GHhVZChtY= +github.com/bnb-chain/greenfield-common/go v0.0.0-20230906132736-eb2f0efea228 h1:WywBaew30hZuqDTOQbkRV3uBg6XHjNIE1s3AXVXbG+8= +github.com/bnb-chain/greenfield-common/go v0.0.0-20230906132736-eb2f0efea228/go.mod h1:K9jK80fbahciC+FAvrch8Qsbw9ZkvVgjfKsqrzPTAVA= github.com/bnb-chain/greenfield-cosmos-sdk/api v0.0.0-20230816082903-b48770f5e210 h1:GHPbV2bC+gmuO6/sG0Tm8oGal3KKSRlyE+zPscDjlA8= github.com/bnb-chain/greenfield-cosmos-sdk/api v0.0.0-20230816082903-b48770f5e210/go.mod h1:vhsZxXE9tYJeYB5JR4hPhd6Pc/uPf7j1T8IJ7p9FdeM= github.com/bnb-chain/greenfield-cosmos-sdk/math v0.0.0-20230816082903-b48770f5e210 h1:FLVOn4+OVbsKi2+YJX5kmD27/4dRu4FW7xCXFhzDO5s=