delete sign value
This commit is contained in:
parent
27327e0788
commit
37e6a0154a
102
README.md
102
README.md
@ -1,6 +1,6 @@
|
||||
# gaore-common-sdk-go
|
||||
|
||||
### 目录架构
|
||||
### 1.目录架构
|
||||
```
|
||||
├── README.md
|
||||
├── sdk
|
||||
@ -13,14 +13,23 @@
|
||||
└── 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"
|
||||
@ -28,7 +37,7 @@ import (
|
||||
"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() {
|
||||
@ -55,3 +64,88 @@ func init() {
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
### 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