Skip to content

Commit 9312794

Browse files
authored
Merge pull request #320 from YangSen-qn/dev
uc host check scheme
2 parents b27b4bb + cf567ce commit 9312794

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

cmd/asyncfetch.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ func NewCmdAsyncCheck() *cobra.Command {
4646
Run: func(cmd *cobra.Command, positionalArgs []string) {
4747
bm := iqshell.GetBucketManager()
4848

49-
// let API choose APIHOST
50-
bm.Cfg.ApiHost = ""
51-
5249
ret, err := bm.CheckAsyncFetchStatus(positionalArgs[0], positionalArgs[1])
5350
if err != nil {
5451
fmt.Fprintf(os.Stderr, "CheckAsyncFetchStatus: %v\n", err)

cmd/root.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ func initConfig() {
149149
iqshell.SetDefaultAccPath(filepath.Join(rootPath, "account.json"))
150150
iqshell.SetDefaultRsHost(storage.DefaultRsHost)
151151
iqshell.SetDefaultRsfHost(storage.DefaultRsfHost)
152-
iqshell.SetDefaultApiHost(storage.DefaultAPIHost)
153152
iqshell.SetDefaultUcHost("https://uc.qbox.me")
154153

155154
if rErr := viper.ReadInConfig(); rErr != nil {

cmd/rsbatch.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ func (fc *fetchConfig) initFileExporter() {
217217
func (fc *fetchConfig) initBucketManager() {
218218

219219
cfg := storage.Config{
220-
IoHost: fc.upHost,
220+
IoHost: fc.upHost,
221+
ApiHost: iqshell.ApiHost(),
221222
}
222223
fc.bm = iqshell.GetBucketManagerWithConfig(&cfg)
223224
}

iqshell/config.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/spf13/pflag"
55
"github.com/spf13/viper"
66
"path/filepath"
7+
"strings"
78
)
89

910
const (
@@ -241,10 +242,14 @@ func SetDefaultApiHost(val string) {
241242

242243
func UcHost() string {
243244
host := viper.GetString(HOST_UC[0])
244-
if host != "" {
245-
return host
245+
if host == "" {
246+
host = viper.GetString(HOST_UC[1])
247+
}
248+
249+
if !strings.Contains(host, "://") {
250+
host = Endpoint(true, host)
246251
}
247-
return viper.GetString(HOST_UC[1])
252+
return host
248253
}
249254

250255
func SetUcHost(val string) {

iqshell/utils.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/base64"
66
"encoding/json"
77
"errors"
8+
"fmt"
89
"io"
910
"net/url"
1011
"os"
@@ -285,3 +286,17 @@ func SimpleUnescape(s *string) string {
285286
`\'`, `'`)
286287
return r.Replace(*s)
287288
}
289+
290+
func Endpoint(useHttps bool, host string) string {
291+
host = strings.TrimSpace(host)
292+
host = strings.TrimLeft(host, "http://")
293+
host = strings.TrimLeft(host, "https://")
294+
if host == "" {
295+
return ""
296+
}
297+
scheme := "http://"
298+
if useHttps {
299+
scheme = "https://"
300+
}
301+
return fmt.Sprintf("%s%s", scheme, host)
302+
}

0 commit comments

Comments
 (0)