2020-08-03 14:38:20 +08:00
|
|
|
# gaore-common-sdk-go
|
|
|
|
|
2020-08-06 17:29:29 +08:00
|
|
|
### 目录架构
|
|
|
|
```
|
|
|
|
├── README.md
|
|
|
|
├── sdk
|
|
|
|
│ ├── auth `认证类`
|
|
|
|
│ ├── client.go `客户端主入口类`
|
|
|
|
│ ├── config.go
|
|
|
|
│ ├── requests `请求类`
|
|
|
|
│ ├── responses `响应类`
|
|
|
|
│ └── utils `工具类`
|
|
|
|
└── services
|
|
|
|
└── jedi
|
|
|
|
```
|
|
|
|
|
|
|
|
### 服务端认证调用事例
|
|
|
|
|
|
|
|
调用 `auth.UnSign` 方法,提供`*http.Request`请求实例,以及`signer.Signer` 签名器(签名器需要包括凭据)
|
|
|
|
即可完成整个验签过程
|
|
|
|
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/astaxie/beego"
|
|
|
|
"github.com/astaxie/beego/context"
|
|
|
|
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/auth"
|
|
|
|
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/auth/credentials"
|
|
|
|
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/auth/signers"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
// 过滤器
|
|
|
|
beego.InsertFilter("/api/*", beego.BeforeRouter, func(context *context.Context) {
|
|
|
|
httpRequest := context.Request
|
|
|
|
err := auth.UnSign(httpRequest, signers.NewAccessKeySigner(&credentials.AccessKeyCredential{
|
|
|
|
AccessKeyId: "aaaaaa",
|
|
|
|
AccessKeySecret: "bbbbbb",
|
|
|
|
AccessKeyFrom: context.Input.Param("access_from"),
|
|
|
|
}))
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
resp := response.NewJsonByDefaultFailed()
|
|
|
|
resp.Msg = err.Error()
|
|
|
|
resp.Code = 10086
|
|
|
|
|
|
|
|
var (
|
|
|
|
hasIndent = beego.BConfig.RunMode != beego.PROD
|
|
|
|
)
|
|
|
|
context.Output.Status = 500
|
|
|
|
context.Output.JSON(resp, hasIndent, false)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
```
|