diff --git a/cmd/asyncfetch.go b/cmd/asyncfetch.go index a73f6294..410d67ea 100644 --- a/cmd/asyncfetch.go +++ b/cmd/asyncfetch.go @@ -46,9 +46,6 @@ func NewCmdAsyncCheck() *cobra.Command { Run: func(cmd *cobra.Command, positionalArgs []string) { bm := iqshell.GetBucketManager() - // let API choose APIHOST - bm.Cfg.ApiHost = "" - ret, err := bm.CheckAsyncFetchStatus(positionalArgs[0], positionalArgs[1]) if err != nil { fmt.Fprintf(os.Stderr, "CheckAsyncFetchStatus: %v\n", err) diff --git a/cmd/root.go b/cmd/root.go index 87fe42e0..b7f970f8 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -149,7 +149,6 @@ func initConfig() { iqshell.SetDefaultAccPath(filepath.Join(rootPath, "account.json")) iqshell.SetDefaultRsHost(storage.DefaultRsHost) iqshell.SetDefaultRsfHost(storage.DefaultRsfHost) - iqshell.SetDefaultApiHost(storage.DefaultAPIHost) iqshell.SetDefaultUcHost("https://uc.qbox.me") if rErr := viper.ReadInConfig(); rErr != nil { diff --git a/cmd/rsbatch.go b/cmd/rsbatch.go index 82397715..d2cf5a10 100644 --- a/cmd/rsbatch.go +++ b/cmd/rsbatch.go @@ -217,7 +217,8 @@ func (fc *fetchConfig) initFileExporter() { func (fc *fetchConfig) initBucketManager() { cfg := storage.Config{ - IoHost: fc.upHost, + IoHost: fc.upHost, + ApiHost: iqshell.ApiHost(), } fc.bm = iqshell.GetBucketManagerWithConfig(&cfg) } diff --git a/iqshell/config.go b/iqshell/config.go index 55027065..da417bd8 100644 --- a/iqshell/config.go +++ b/iqshell/config.go @@ -4,6 +4,7 @@ import ( "github.com/spf13/pflag" "github.com/spf13/viper" "path/filepath" + "strings" ) const ( @@ -241,10 +242,14 @@ func SetDefaultApiHost(val string) { func UcHost() string { host := viper.GetString(HOST_UC[0]) - if host != "" { - return host + if host == "" { + host = viper.GetString(HOST_UC[1]) + } + + if !strings.Contains(host, "://") { + host = Endpoint(true, host) } - return viper.GetString(HOST_UC[1]) + return host } func SetUcHost(val string) { diff --git a/iqshell/utils.go b/iqshell/utils.go index 757d9b04..d9ee0631 100644 --- a/iqshell/utils.go +++ b/iqshell/utils.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "encoding/json" "errors" + "fmt" "io" "net/url" "os" @@ -285,3 +286,17 @@ func SimpleUnescape(s *string) string { `\'`, `'`) return r.Replace(*s) } + +func Endpoint(useHttps bool, host string) string { + host = strings.TrimSpace(host) + host = strings.TrimLeft(host, "http://") + host = strings.TrimLeft(host, "https://") + if host == "" { + return "" + } + scheme := "http://" + if useHttps { + scheme = "https://" + } + return fmt.Sprintf("%s%s", scheme, host) +}