delete sign value
This commit is contained in:
parent
27327e0788
commit
37e6a0154a
146
README.md
146
README.md
@ -1,6 +1,6 @@
|
||||
# gaore-common-sdk-go
|
||||
|
||||
### 目录架构
|
||||
### 1.目录架构
|
||||
```
|
||||
├── README.md
|
||||
├── sdk
|
||||
@ -13,45 +13,139 @@
|
||||
└── services
|
||||
└── jedi
|
||||
```
|
||||
### 2.引入
|
||||
```go
|
||||
go get -u golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk
|
||||
```
|
||||
或 Go Module
|
||||
```go
|
||||
import "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk"
|
||||
```
|
||||
|
||||
### 服务端认证调用事例
|
||||
### 3.服务端认证调用事例
|
||||
|
||||
调用 `auth.UnSign` 方法,提供`*http.Request`请求实例,以及`signer.Signer` 签名器(签名器需要包括凭据)
|
||||
即可完成整个验签过程
|
||||
|
||||
这里以`beego`为例 :
|
||||
```go
|
||||
package main
|
||||
package applications
|
||||
|
||||
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"
|
||||
|
||||
"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"
|
||||
"golib.gaore.com/GaoreGo/grlogs"
|
||||
)
|
||||
|
||||
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"),
|
||||
}))
|
||||
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
|
||||
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)
|
||||
}
|
||||
})
|
||||
var (
|
||||
hasIndent = beego.BConfig.RunMode != beego.PROD
|
||||
)
|
||||
context.Output.Status = 500
|
||||
context.Output.JSON(resp, hasIndent, false)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
### 4.sdk编写
|
||||
|
||||
在`services`目录下以服务归类新建文件夹, 如`jedi`为短信服务,以 `RpcRequest` 和 `BaseResponse` 以基类写好请求子类和响应子类。一个请求接口对应一对请求和响应类。
|
||||
|
||||
```go
|
||||
import "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk"
|
||||
|
||||
type Client struct {
|
||||
sdk.Client
|
||||
}
|
||||
|
||||
func NewClientWithAccessKey(accesskey, secrect, source string) (client *Client, err error) {
|
||||
client = &Client{}
|
||||
err = client.InitWithAccessKey(accesskey, secrect, source)
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Client) Test(req *DemoTestRequest) (response *DemoTestResponse, err error) {
|
||||
response = CreateDemoTestResponse()
|
||||
err = c.DoAction(req, response)
|
||||
return
|
||||
}
|
||||
```
|
||||
|
||||
请求类,对参数用标签解释, 如 `position:"Query" field:"param_1" default:""` , 有三个字段 `position` , `field`, `default`
|
||||
|
||||
- `position` 为标志该参数为请求体对应的位置, `Query` query参数, `Body` post请求体参数, `Head`请求头参数
|
||||
|
||||
- `field` 解释成参数实际名称
|
||||
|
||||
- `default` 默认值
|
||||
|
||||
```go
|
||||
type DemoTestRequest struct {
|
||||
*requests.RpcRequest
|
||||
Param1 string `position:"Query" field:"param_1" default:"" `
|
||||
Param2 int `position:"Query" field:"param_2" default:"10086" `
|
||||
Param3 bool `position:"Query" field:"param_3" default:"false" `
|
||||
}
|
||||
```
|
||||
对应解释成http请求为:
|
||||
```go
|
||||
GET param_1=111¶m_2=10086¶m_3=false
|
||||
```
|
||||
|
||||
```go
|
||||
package jedi
|
||||
|
||||
import (
|
||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
|
||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses"
|
||||
)
|
||||
|
||||
type DemoTestRequest struct {
|
||||
*requests.RpcRequest
|
||||
Param1 string `position:"Query" field:"param_1" default:"" `
|
||||
Param2 int `position:"Query" field:"param_2" default:"10086" `
|
||||
Param3 bool `position:"Query" field:"param_3" default:"false" `
|
||||
}
|
||||
|
||||
func CreateDemoTestRequest() (req *DemoTestRequest) {
|
||||
req = &DemoTestRequest{RpcRequest: &requests.RpcRequest{}}
|
||||
req.InitWithApiInfo(HOST, VERSION, "/api/sms/Index")
|
||||
req.Method = requests.GET
|
||||
return
|
||||
}
|
||||
|
||||
type DemoTestResponse struct {
|
||||
*responses.BaseResponse
|
||||
Data DemoTestResponseData `json:"data"`
|
||||
}
|
||||
|
||||
type DemoTestResponseData struct {
|
||||
Account string `json:"account"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
func CreateDemoTestResponse() *DemoTestResponse {
|
||||
return &DemoTestResponse{
|
||||
BaseResponse: &responses.BaseResponse{},
|
||||
}
|
||||
}
|
||||
|
||||
```
|
Loading…
Reference in New Issue
Block a user