You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-library/vendor/github.com/qiniu/go-sdk/v7/storage/uploader_base.go

57 lines
1.6 KiB

2 years ago
package storage
12 months ago
import (
"github.com/qiniu/go-sdk/v7/internal/hostprovider"
"time"
)
// retryMax: 为 0使用默认值每个域名只请求一次
// hostFreezeDuration: 为 0使用默认值50ms ~ 100ms
func getUpHost(config *Config, retryMax int, hostFreezeDuration time.Duration, ak, bucket string) (upHost string, err error) {
2 years ago
region := config.GetRegion()
if region == nil {
12 months ago
if region, err = GetRegionWithOptions(ak, bucket, UCApiOptions{
RetryMax: retryMax,
HostFreezeDuration: hostFreezeDuration,
}); err != nil {
2 years ago
return "", err
}
2 years ago
}
2 years ago
host := region.SrcUpHosts[0]
2 years ago
if config.UseCdnDomains {
2 years ago
host = region.CdnUpHosts[0]
2 years ago
}
2 years ago
upHost = endpoint(config.UseHTTPS, host)
2 years ago
return
}
2 years ago
12 months ago
// retryMax: 为 0使用默认值每个域名只请求一次
// hostFreezeDuration: 为 0使用默认值50ms ~ 100ms
func getUpHostProvider(config *Config, retryMax int, hostFreezeDuration time.Duration, ak, bucket string) (hostprovider.HostProvider, error) {
2 years ago
region := config.GetRegion()
var err error
if region == nil {
12 months ago
if region, err = GetRegionWithOptions(ak, bucket, UCApiOptions{
RetryMax: retryMax,
HostFreezeDuration: hostFreezeDuration,
}); err != nil {
2 years ago
return nil, err
}
}
hosts := make([]string, 0, 0)
if config.UseCdnDomains && len(region.CdnUpHosts) > 0 {
hosts = append(hosts, region.CdnUpHosts...)
} else if len(region.SrcUpHosts) > 0 {
hosts = append(hosts, region.SrcUpHosts...)
}
for i := 0; i < len(hosts); i++ {
hosts[i] = endpoint(config.UseHTTPS, hosts[i])
}
return hostprovider.NewWithHosts(hosts), nil
}