- 修复阿里云初始化
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details

master v1.0.8
李光春 2 years ago
parent fa93945a4c
commit 063f9f85ee

@ -19,25 +19,43 @@ type AliYunConfig struct {
// AliYun 阿里云
type AliYun struct {
AliYunConfig
error error // 错误信息
client *oss.Client // 驱动
bucket *oss.Bucket // 存储空间
endpointError error // 错误信息
endpointEcsError error // 错误信息
endpointAccelerateError error // 错误信息
accessKeyId string // 账号信息
accessKeySecret string // 账号信息
bucketName string // 存储空间名称
endpoint string // 地域节点
error error // 错误信息
client *oss.Client // 驱动
bucket *oss.Bucket // 存储空间
endpointEcsInfo struct {
error error // 错误信息
endpoint string // 地域节点
client *oss.Client // 驱动
bucket *oss.Bucket // 存储空间
} // 外网访问
endpointInfo struct {
error error // 错误信息
endpoint string // 地域节点
client *oss.Client // 驱动
bucket *oss.Bucket // 存储空间
} // 内网访问
endpointAccelerateInfo struct {
error error // 错误信息
endpoint string // 地域节点
client *oss.Client // 驱动
bucket *oss.Bucket // 存储空间
} // 传输加速域名访问
}
// NewAliYun 初始化
// https://help.aliyun.com/document_detail/32144.html
func NewAliYun(config *AliYunConfig) (*AliYun, error) {
app := &AliYun{}
app.AccessKeyId = config.AccessKeyId
app.AccessKeySecret = config.AccessKeySecret
app.Endpoint = config.Endpoint
app.EndpointEcs = config.EndpointEcs
app.EndpointAccelerate = config.EndpointAccelerate
app.BucketName = config.BucketName
app.accessKeyId = config.AccessKeyId
app.accessKeySecret = config.AccessKeySecret
app.bucketName = config.BucketName
app.endpointEcsInfo.endpoint = config.Endpoint
app.endpointInfo.endpoint = config.EndpointEcs
app.endpointAccelerateInfo.endpoint = config.EndpointAccelerate
wg := sync.WaitGroup{}
wg.Add(3)
@ -47,13 +65,22 @@ func NewAliYun(config *AliYunConfig) (*AliYun, error) {
wg.Wait()
// 判断结果
if app.endpointEcsError == nil {
if app.endpointEcsInfo.error == nil {
app.endpoint = app.endpointEcsInfo.endpoint
app.client = app.endpointEcsInfo.client
app.bucket = app.endpointEcsInfo.bucket
return app, nil
}
if app.endpointError == nil {
if app.endpointInfo.error == nil {
app.endpoint = app.endpointInfo.endpoint
app.client = app.endpointInfo.client
app.bucket = app.endpointInfo.bucket
return app, nil
}
if app.endpointAccelerateError == nil {
if app.endpointAccelerateInfo.error == nil {
app.endpoint = app.endpointAccelerateInfo.endpoint
app.client = app.endpointAccelerateInfo.client
app.bucket = app.endpointAccelerateInfo.bucket
return app, nil
}
@ -63,60 +90,60 @@ func NewAliYun(config *AliYunConfig) (*AliYun, error) {
func (c *AliYun) configEndpoint(wg *sync.WaitGroup) {
defer wg.Done()
if c.Endpoint == "" {
c.endpointError = errors.New("没有配置")
if c.endpointInfo.endpoint == "" {
c.endpointInfo.error = errors.New("没有配置")
return
}
// 创建链接
c.client, c.endpointError = oss.New(c.Endpoint, c.AccessKeyId, c.AccessKeySecret)
if c.endpointError != nil {
c.endpointInfo.client, c.endpointInfo.error = oss.New(c.endpointInfo.endpoint, c.accessKeyId, c.accessKeySecret)
if c.endpointInfo.error != nil {
return
}
// 填写存储空间名称
c.bucket, c.endpointError = c.client.Bucket(c.BucketName)
if c.endpointError != nil {
c.endpointInfo.bucket, c.endpointInfo.error = c.client.Bucket(c.bucketName)
if c.endpointInfo.error != nil {
return
}
// 判断存储空间是否存在
_, c.endpointError = c.client.IsBucketExist(c.BucketName)
if c.endpointError != nil {
_, c.endpointInfo.error = c.client.IsBucketExist(c.bucketName)
if c.endpointInfo.error != nil {
return
}
c.endpointError = nil
c.endpointInfo.error = nil
return
}
func (c *AliYun) configEndpointEcs(wg *sync.WaitGroup) {
defer wg.Done()
if c.EndpointEcs == "" {
c.endpointEcsError = errors.New("没有配置")
if c.endpointEcsInfo.endpoint == "" {
c.endpointEcsInfo.error = errors.New("没有配置")
return
}
// 创建链接
c.client, c.endpointEcsError = oss.New(c.EndpointEcs, c.AccessKeyId, c.AccessKeySecret)
if c.endpointEcsError != nil {
c.endpointEcsInfo.client, c.endpointEcsInfo.error = oss.New(c.endpointEcsInfo.endpoint, c.accessKeyId, c.accessKeySecret)
if c.endpointEcsInfo.error != nil {
return
}
// 填写存储空间名称
c.bucket, c.endpointEcsError = c.client.Bucket(c.BucketName)
if c.endpointEcsError != nil {
c.endpointEcsInfo.bucket, c.endpointEcsInfo.error = c.client.Bucket(c.bucketName)
if c.endpointEcsInfo.error != nil {
return
}
// 判断存储空间是否存在
_, c.endpointEcsError = c.client.IsBucketExist(c.BucketName)
if c.endpointEcsError != nil {
_, c.endpointEcsInfo.error = c.client.IsBucketExist(c.bucketName)
if c.endpointEcsInfo.error != nil {
return
}
c.endpointEcsError = nil
c.endpointEcsInfo.error = nil
return
}
@ -124,30 +151,30 @@ func (c *AliYun) configEndpointEcs(wg *sync.WaitGroup) {
func (c *AliYun) configEndpointAccelerate(wg *sync.WaitGroup) {
defer wg.Done()
if c.EndpointAccelerate == "" {
c.endpointAccelerateError = errors.New("没有配置")
if c.endpointAccelerateInfo.endpoint == "" {
c.endpointAccelerateInfo.error = errors.New("没有配置")
return
}
// 创建链接
c.client, c.endpointAccelerateError = oss.New(c.EndpointAccelerate, c.AccessKeyId, c.AccessKeySecret)
if c.endpointAccelerateError != nil {
c.endpointAccelerateInfo.client, c.endpointAccelerateInfo.error = oss.New(c.endpointAccelerateInfo.endpoint, c.accessKeyId, c.accessKeySecret)
if c.endpointAccelerateInfo.error != nil {
return
}
// 填写存储空间名称
c.bucket, c.endpointAccelerateError = c.client.Bucket(c.BucketName)
if c.endpointAccelerateError != nil {
c.endpointAccelerateInfo.bucket, c.endpointAccelerateInfo.error = c.client.Bucket(c.bucketName)
if c.endpointAccelerateInfo.error != nil {
return
}
// 判断存储空间是否存在
_, c.endpointAccelerateError = c.client.IsBucketExist(c.BucketName)
if c.endpointAccelerateError != nil {
_, c.endpointAccelerateInfo.error = c.client.IsBucketExist(c.bucketName)
if c.endpointAccelerateInfo.error != nil {
return
}
c.endpointAccelerateError = nil
c.endpointAccelerateInfo.error = nil
return
}

@ -1,3 +1,3 @@
package gostorage
const Version = "1.0.7"
const Version = "1.0.8"

Loading…
Cancel
Save