github.com/qiniu/go-sdk/v7@v7.27.0/storage/uploader_base.go (about) 1 package storage 2 3 import ( 4 "errors" 5 "time" 6 7 "github.com/qiniu/go-sdk/v7/internal/hostprovider" 8 ) 9 10 // retryMax: 为 0,使用默认值,每个域名只请求一次 11 // hostFreezeDuration: 为 0,使用默认值:50ms ~ 100ms 12 func getUpHost(config *Config, retryMax int, hostFreezeDuration time.Duration, ak, bucket string) (upHost string, err error) { 13 region := config.GetRegion() 14 if region == nil { 15 if region, err = GetRegionWithOptions(ak, bucket, UCApiOptions{ 16 RetryMax: retryMax, 17 HostFreezeDuration: hostFreezeDuration, 18 AccelerateUploading: config.AccelerateUploading, 19 }); err != nil { 20 return "", err 21 } 22 } 23 24 if region == nil { 25 return "", errors.New("can't get region with bucket:" + bucket) 26 } 27 28 if config.UseCdnDomains || config.AccelerateUploading { 29 if len(region.CdnUpHosts) == 0 { 30 return "", errors.New("can't get region cdn host with bucket:" + bucket) 31 } 32 33 return endpoint(config.UseHTTPS, region.CdnUpHosts[0]), nil 34 } 35 36 if len(region.SrcUpHosts) == 0 { 37 return "", errors.New("can't get region src host with bucket:" + bucket) 38 } 39 40 return endpoint(config.UseHTTPS, region.SrcUpHosts[0]), nil 41 } 42 43 // retryMax: 为 0,使用默认值,每个域名只请求一次 44 // hostFreezeDuration: 为 0,使用默认值:50ms ~ 100ms 45 func getUpHostProvider(config *Config, retryMax int, hostFreezeDuration time.Duration, ak, bucket string) (hostprovider.HostProvider, error) { 46 region := config.GetRegion() 47 var err error 48 if region == nil { 49 if region, err = GetRegionWithOptions(ak, bucket, UCApiOptions{ 50 RetryMax: retryMax, 51 HostFreezeDuration: hostFreezeDuration, 52 AccelerateUploading: config.AccelerateUploading, 53 }); err != nil { 54 return nil, err 55 } 56 } 57 58 hosts := make([]string, 0) 59 if config.UseCdnDomains && len(region.CdnUpHosts) > 0 { 60 hosts = append(hosts, region.CdnUpHosts...) 61 } else if len(region.SrcUpHosts) > 0 { 62 hosts = append(hosts, region.SrcUpHosts...) 63 } 64 65 for i := 0; i < len(hosts); i++ { 66 hosts[i] = endpoint(config.UseHTTPS, hosts[i]) 67 } 68 69 return hostprovider.NewWithHosts(hosts), nil 70 }