You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dingdanxia/request.go

45 lines
793 B

2 years ago
package dingdanxia
2 years ago
import (
"context"
"go.dtapp.net/gorequest"
)
2 years ago
// 请求接口
4 months ago
func (c *Client) request(ctx context.Context, url string, param gorequest.Params, method string) (gorequest.Response, error) {
2 years ago
// 公共参数
4 months ago
param.Set("apikey", c.GetApiKey())
2 years ago
// 创建请求
4 months ago
client := gorequest.NewHttp()
2 years ago
// 设置请求地址
client.SetUri(url)
// 设置方式
client.SetMethod(method)
// 设置格式
client.SetContentTypeForm()
4 months ago
// 设置参数
client.SetParams(param)
1 year ago
2 years ago
// 发起请求
2 years ago
request, err := client.Request(ctx)
2 years ago
if err != nil {
return gorequest.Response{}, err
}
2 years ago
// 记录日志
4 months ago
if c.gormLog.status {
go c.gormLog.client.Middleware(ctx, request)
2 years ago
}
3 months ago
if c.mongoLog.status {
go c.mongoLog.client.Middleware(ctx, request)
}
2 years ago
return request, err
}