7
0

delete sign value

This commit is contained in:
liangzy 2020-08-06 17:29:29 +08:00
parent aba6d728e3
commit 27327e0788
2 changed files with 70 additions and 3 deletions

View File

@ -1,2 +1,57 @@
# gaore-common-sdk-go # gaore-common-sdk-go
### 目录架构
```
├── 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)
}
})
}
```

View File

@ -4,8 +4,10 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strings"
) )
type AcsResponse interface { type AcsResponse interface {
@ -86,12 +88,22 @@ func Unmarshal(response AcsResponse, httpResponse *http.Response, format string)
if err != nil { if err != nil {
return return
} }
if !response.IsSuccess() {
err = errors.New(fmt.Sprintf("%d %s", response.GetHttpStatus(), response.GetHttpContentString())) if _, isCommonResponse := response.(CommonResponse); isCommonResponse {
return return
} }
if _, isCommonResponse := response.(CommonResponse); isCommonResponse { if !response.IsSuccess() {
if contentType, ok := response.GetHttpHeaders()["Content-Type"]; ok {
for _, v := range contentType {
if strings.Contains(v, requests.Json) {
json.Unmarshal(response.GetHttpContentBytes(), response)
break
}
}
}
err = errors.New(fmt.Sprintf("%d %s", response.GetHttpStatus(), response.GetHttpContentString()))
return return
} }