From 97d8147d5349dd437161c51628fc71a5eecb4a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Wed, 18 May 2022 23:37:04 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aliyun.go | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/aliyun.go b/aliyun.go index d8276f5..adc0ddf 100644 --- a/aliyun.go +++ b/aliyun.go @@ -5,23 +5,32 @@ import ( "io" ) -// AliYun 阿里云 -type AliYun struct { +// AliYunConfig 阿里云配置 +type AliYunConfig struct { AccessKeyId string AccessKeySecret string Endpoint string BucketName string - error error // 错误信息 - client *oss.Client // 驱动 - bucket *oss.Bucket // 存储空间 +} + +// AliYun 阿里云 +type AliYun struct { + AliYunConfig + error error // 错误信息 + client *oss.Client // 驱动 + bucket *oss.Bucket // 存储空间 } // NewAliYun 初始化 // https://help.aliyun.com/document_detail/32144.html -func NewAliYun(accessKeyId, accessKeySecret, endpoint, bucketName string) *AliYun { - app := &AliYun{AccessKeyId: accessKeyId, AccessKeySecret: accessKeySecret, Endpoint: endpoint, BucketName: bucketName} - app.client, app.error = oss.New(endpoint, accessKeyId, accessKeySecret) - app.bucket, app.error = app.client.Bucket(bucketName) +func NewAliYun(config *AliYunConfig) *AliYun { + app := &AliYun{} + app.AccessKeyId = config.AccessKeyId + app.AccessKeySecret = config.AccessKeySecret + app.Endpoint = config.Endpoint + app.BucketName = config.BucketName + app.client, app.error = oss.New(app.Endpoint, app.AccessKeyId, app.AccessKeySecret) + app.bucket, app.error = app.client.Bucket(app.BucketName) return app }