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 }