An open API service indexing awesome lists of open source software.

https://github.com/qbhy/goal-aliyun

阿里云 sdk
https://github.com/qbhy/goal-aliyun

Last synced: about 1 month ago
JSON representation

阿里云 sdk

Awesome Lists containing this project

README

        

# goal-aliyun
这是一个 goal 的阿里云 sdk,基于 [denverdino/aliyungo](https://github.com/denverdino/aliyungo) 封装,支持多应用

## 安装 - install
```shell
$ go get github.com/qbhy/goal-aliyun
```

## 配置 - configuration
```go
// config/aliyun.go
package config

import (
"github.com/denverdino/aliyungo/oss"
"github.com/goal-web/contracts"
"github.com/qbhy/goal-aliyun/config"
)

func init() {
configs["aliyun"] = func(env contracts.Env) interface{} {
return &config.Config{
Keys: config.Keys{ // 统一密钥配置
Default: "default",
Keys: map[string]config.Key{
"default": {
AccessKeyId: env.GetString("aliyun.access.id"),
AccessKeySecret: env.GetString("aliyun.access.secret"),
},
},
},

// oss 对象存储配置
Oss: config.OssConfig{
Default: "default",
Disks: map[string]*config.Oss{
"default": {
//Key: nil,
KeyName: "default", // 如果设置了 key ,则优先使用 key,否则可以通过 KeyName 指定 keys 配置中的 key
Region: oss.Shanghai,
Bucket: env.GetString("oss.bucket"),
Endpoint: env.GetString("oss.endpoint"),
Debug: env.GetBool("oss.debug"),
},
},
},

// 阿里云短信配置
Sms: config.SmsConfig{
DefaultSms: "default",
Sms: map[string]*config.Sms{
"default": {
//Key: nil,
KeyName: "default", // 如果设置了 key ,则优先使用 key,否则可以通过 KeyName 指定 keys 配置中的 key
},
},

// 阿里大于短信配置
DefaultDYSms: "default",
DYSms: map[string]*config.DYSms{
"default": {
//Key: nil,
KeyName: "default", // 如果设置了 key ,则优先使用 key,否则可以通过 KeyName 指定 keys 配置中的 key
},
},
},

// 阿里云移动推送配置
Push: config.PushConfig{
Default: "default",
Channels: map[string]*config.Push{
"default": {
//Key: nil,
KeyName: "default", // 如果设置了 key ,则优先使用 key,否则可以通过 KeyName 指定 keys 配置中的 key
},
},
},

// 阿里云 cdn 配置
Cdn: config.CdnConfig{
Default: "default",
Disks: map[string]*config.Cdn{
"default": {
//Key: nil,
KeyName: "default", // 如果设置了 key ,则优先使用 key,否则可以通过 KeyName 指定 keys 配置中的 key
Endpoint: env.GetString("aliyun.cdn.endpoint"),
},
},
},
}
}
}

```

## 使用 - usage
注册服务
```go
// main.go
import (
"github.com/goal-web/application"
aliyun "github.com/qbhy/goal-aliyun"
)

func main() {
var app = application.Singleton()

app.RegisterServices(
// other service
aliyun.ServiceProvider{},
)
// ...
}
```
使用
```go
// app/controllers/account/login.go
package account

import (
"fmt"
"github.com/denverdino/aliyungo/sms"
"github.com/goal-web/validation"
"github.com/goal-web/example/app/http/requests/account"
"github.com/goal-web/contracts"
)

// SendSmsCode 发送验证码
func SendSmsCode(request *account.SendSmsRequest, smsClient *sms.Client) interface{} {
validation.VerifyForm(request)

var sendErr = smsClient.SingleSendSms(&sms.SingleSendSmsArgs{
SignName: "your sign",
TemplateCode: "your template",
RecNum: "your number",
ParamString: "your param",
})

if sendErr != nil {
fmt.Println(sendErr)
}

return http.Ok()
}
// ...
```

## 契约 - contract
### 工厂 - Factory
```go
type Factory interface {
Key(name ...string) (id string, secret string, exists bool)
Push(name ...string) *push.Client
Oss(name ...string) *oss.Client
Cdn(name ...string) *cdn.CdnClient
Sms(name ...string) *sms.Client
DYSms(name ...string) *sms.DYSmsClient
}
```

## 相关链接
[goal-web](https://github.com/goal-web/goal)
[qbhy/goal-alipay](https://github.com/qbhy/goal-alipay)
[qbhy/goal-wechat](https://github.com/qbhy/goal-wechat)
[qbhy/goal-aliyun](https://github.com/qbhy/goal-aliyun)
[denverdino/aliyungo](https://github.com/denverdino/aliyungo)
[email protected]