Documentation ¶
Index ¶
- func AppRestParamSign(version, appKey, method, timestamp, content, appSecret string, token *string) string
- type AppClientError
- type AppRestBuild
- type AppRestConfig
- type AppRestEvent
- func (event *AppRestEvent) RequestRead(data []byte)
- func (event *AppRestEvent) RequestStart(method, url string)
- func (event *AppRestEvent) ResponseCheck(_ error)
- func (event *AppRestEvent) ResponseFinish(err error)
- func (event *AppRestEvent) ResponseHeader(httpCode int, httpHeader map[string][]string)
- func (event *AppRestEvent) ResponseRead(data []byte)
- type AppRestRequestId
- type JsonData
- type JsonDataDefault
- type JsonDataToType
- type JsonKey
- type JsonResult
- type JsonValid
- type RestApi
- type RestBuild
- type RestCallerInfo
- type RestClient
- type RestClientError
- type RestClientManager
- type RestConfig
- type RestEvent
- type RestEventNoop
- func (event *RestEventNoop) RequestRead(_ []byte)
- func (event *RestEventNoop) RequestStart(_, _ string)
- func (event *RestEventNoop) ResponseCheck(_ error)
- func (event *RestEventNoop) ResponseFinish(_ error)
- func (event *RestEventNoop) ResponseHeader(_ int, _ map[string][]string)
- func (event *RestEventNoop) ResponseRead(_ []byte)
- type RestJsonResult
- type RestRequestReader
- type RestResult
- type RestTokenApi
- type ToJsonData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppRestParamSign ¶ added in v0.0.17
func AppRestParamSign(version, appKey, method, timestamp, content, appSecret string, token *string) string
AppRestParamSign 参数签名生成
Types ¶
type AppClientError ¶ added in v0.0.25
func NewAppClientError ¶ added in v0.0.23
func NewAppClientError(code string, subCode string, msg string) *AppClientError
NewAppClientError 错误创建
func (*AppClientError) Error ¶ added in v0.0.25
func (err *AppClientError) Error() string
type AppRestBuild ¶
type AppRestBuild struct { Timeout time.Duration //指定接口超时时间,默认0,跟全局一致 Path string //接口路径 HttpMethod string Method string }
AppRestBuild 内部接口配置
func (*AppRestBuild) BuildRequest ¶
func (clt *AppRestBuild) BuildRequest(ctx context.Context, client *RestClient, _ int, param interface{}, _ *RestCallerInfo) *RestResult
BuildRequest 执行请求
func (*AppRestBuild) CheckJsonResult ¶ added in v0.0.6
func (clt *AppRestBuild) CheckJsonResult(body string) error
type AppRestConfig ¶
type AppRestConfig struct { Name string AppKey string AppSecret string AppUrl string EventCreate func(ctx context.Context) RestEvent }
AppRestConfig 回收宝内部服务配置
func (*AppRestConfig) GetName ¶ added in v0.0.4
func (clf *AppRestConfig) GetName() string
type AppRestEvent ¶ added in v0.0.4
type AppRestEvent struct {
// contains filtered or unexported fields
}
AppRestEvent 接口事件实现
func NewAppRestEvent ¶ added in v0.0.4
func (*AppRestEvent) RequestRead ¶ added in v0.0.4
func (event *AppRestEvent) RequestRead(data []byte)
func (*AppRestEvent) RequestStart ¶ added in v0.0.4
func (event *AppRestEvent) RequestStart(method, url string)
func (*AppRestEvent) ResponseCheck ¶ added in v0.0.6
func (event *AppRestEvent) ResponseCheck(_ error)
func (*AppRestEvent) ResponseFinish ¶ added in v0.0.6
func (event *AppRestEvent) ResponseFinish(err error)
func (*AppRestEvent) ResponseHeader ¶ added in v0.0.4
func (event *AppRestEvent) ResponseHeader(httpCode int, httpHeader map[string][]string)
func (*AppRestEvent) ResponseRead ¶ added in v0.0.4
func (event *AppRestEvent) ResponseRead(data []byte)
type AppRestRequestId ¶ added in v0.0.30
AppRestRequestId 新增请求header的x-request-id
type JsonData ¶ added in v0.0.6
JsonData JSON数据
func NewJsonData ¶ added in v0.0.6
NewJsonData 创建一个正常JSON数据
func NewJsonDataFromError ¶ added in v0.0.6
NewJsonDataFromError 创建一个错误JSON数据
func (*JsonData) JsonDataDefault ¶ added in v0.0.40
func (hand *JsonData) JsonDataDefault() interface{}
func (*JsonData) ToJsonData ¶ added in v0.0.47
func (*JsonData) UnmarshalJSON ¶ added in v0.0.35
type JsonDataDefault ¶ added in v0.0.40
type JsonDataDefault interface {
JsonDataDefault() interface{}
}
type JsonDataToType ¶ added in v0.0.35
type JsonDataToType interface {
JsonDataToType(field string, result ToJsonData) interface{}
}
type JsonKey ¶ added in v0.0.11
type JsonKey struct { Path string //获取路径 ToType func(result *gjson.Result) interface{} //转换为指定类型 Tag string //校验用TAG *JsonValid //JSON校验结构 }
JsonKey JSON获取KEY
type JsonResult ¶
type JsonResult struct {
// contains filtered or unexported fields
}
JsonResult JSON结果集
func NewJsonResult ¶
func NewJsonResult(jsonBody string, basePath string) *JsonResult
NewJsonResult 解析一个JSON字符串为JSON结果 @param jsonBody JSON内容 @param basePath 从某个节点获取,传入空字符串表示根节点获取
func NewJsonResultFromError ¶
func NewJsonResultFromError(err error) *JsonResult
NewJsonResultFromError 创建一个错误JSON结果
func (*JsonResult) GetData ¶ added in v0.0.6
func (res *JsonResult) GetData(key interface{}) *JsonData
GetData 从JSON中获取数据 @param dataKey 传入string 表示不校验直接获取某节点数据,传空获取所有数据
type JsonValid ¶ added in v0.0.11
type JsonValid struct { //上下文通过此结构透传,如果放到 GetStruct 跟 GetData 上参数太多,实用不方便 Context context.Context // contains filtered or unexported fields }
JsonValid JSON校验结构
type RestApi ¶
type RestApi interface { ConfigBuilds(ctx context.Context) (map[int]RestBuild, error) ConfigName(ctx context.Context) (string, error) }
RestApi 接口定义
type RestBuild ¶
type RestBuild interface {
BuildRequest(ctx context.Context, config *RestClient, key int, param interface{}, callerInfo *RestCallerInfo) *RestResult
}
RestBuild 执行请求
type RestCallerInfo ¶
type RestClient ¶
type RestClient struct { Api RestApi // contains filtered or unexported fields }
RestClient 请求
func (*RestClient) Do ¶
func (client *RestClient) Do(ctx context.Context, key int, param interface{}) chan *RestResult
Do 执行请求
func (*RestClient) GetConfig ¶
func (client *RestClient) GetConfig(ctx context.Context) (RestConfig, error)
GetConfig 获取当前使用配置
func (*RestClient) GetTransport ¶
func (client *RestClient) GetTransport() *http.Transport
GetTransport 公共的Transport
type RestClientError ¶
RestClientError 错误信息
func NewRestClientError ¶
func NewRestClientError(code string, msg string) *RestClientError
NewRestClientError 错误创建
func (*RestClientError) Error ¶
func (err *RestClientError) Error() string
type RestClientManager ¶ added in v0.0.19
type RestClientManager struct {
// contains filtered or unexported fields
}
func NewRestClientManager ¶ added in v0.0.19
func NewRestClientManager(transport ...*http.Transport) *RestClientManager
NewRestClientManager 新建REST客户端
func (*RestClientManager) NewApi ¶ added in v0.0.19
func (c *RestClientManager) NewApi(api RestApi) *RestClient
func (*RestClientManager) SetRestConfig ¶ added in v0.0.19
func (c *RestClientManager) SetRestConfig(config RestConfig) *RestClientManager
SetRestConfig 设置外部接口配置
type RestEvent ¶ added in v0.0.4
type RestEvent interface { RequestStart(method, url string) //开始请求时回调 RequestRead(p []byte) //成功时读取请求数据回调 ResponseHeader(HttpCode int, header map[string][]string) //成功返回HEADER时回调 ResponseRead(p []byte) //成功时读取请求内容 ResponseFinish(err error) //内容读取完时回调,不存在错误时err为nil ResponseCheck(err error) //检测返回内容是否正常,正常时err为nil }
RestEvent 事件接口,用于暴露对外请求的时的信息
type RestEventNoop ¶ added in v0.0.5
type RestEventNoop struct{}
RestEventNoop 默认事件处理
func NewRestEventNoop ¶ added in v0.0.27
func NewRestEventNoop() *RestEventNoop
func (*RestEventNoop) RequestRead ¶ added in v0.0.5
func (event *RestEventNoop) RequestRead(_ []byte)
func (*RestEventNoop) RequestStart ¶ added in v0.0.5
func (event *RestEventNoop) RequestStart(_, _ string)
func (*RestEventNoop) ResponseCheck ¶ added in v0.0.6
func (event *RestEventNoop) ResponseCheck(_ error)
func (*RestEventNoop) ResponseFinish ¶ added in v0.0.6
func (event *RestEventNoop) ResponseFinish(_ error)
func (*RestEventNoop) ResponseHeader ¶ added in v0.0.5
func (event *RestEventNoop) ResponseHeader(_ int, _ map[string][]string)
func (*RestEventNoop) ResponseRead ¶ added in v0.0.5
func (event *RestEventNoop) ResponseRead(_ []byte)
type RestJsonResult ¶ added in v0.0.6
type RestRequestReader ¶ added in v0.0.4
type RestRequestReader struct {
// contains filtered or unexported fields
}
RestRequestReader 对请求io.Reader封装,用于读取内容时事件回调
func NewRestRequestReader ¶ added in v0.0.4
func NewRestRequestReader(reader io.Reader, event RestEvent) *RestRequestReader
type RestResult ¶
type RestResult struct {
// contains filtered or unexported fields
}
RestResult 请求接口后返回数据结构
func NewRestBodyResult ¶ added in v0.0.5
func NewRestBodyResult(build RestBuild, body string, response *http.Response, event RestEvent) *RestResult
NewRestBodyResult 创建外部已经读取Response BODY的请求结果 @param response 可以为nil @param event 可以为nil
func NewRestResult ¶
func NewRestResult(build RestBuild, response *http.Response, event RestEvent) *RestResult
NewRestResult 创建一个正常请求结果 @param event 可以为nil
func NewRestResultFromError ¶
func NewRestResultFromError(err error, event RestEvent) *RestResult
NewRestResultFromError 创建一个错误的请求结果
func (*RestResult) Header ¶ added in v0.0.30
func (res *RestResult) Header() (error, *http.Header)
Header 获取返回HEADER
func (*RestResult) JsonResult ¶ added in v0.0.6
func (res *RestResult) JsonResult(path ...string) *JsonResult
JsonResult 将结果转为JSON字符串
type RestTokenApi ¶
RestTokenApi 带TOKEN的接口定义
type ToJsonData ¶ added in v0.0.47
type ToJsonData interface {
ToJsonData() *JsonData
}