From f1fac196f75722a6319432dff3953273fec99136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sun, 1 Aug 2021 21:13:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AF=B7=E6=B1=82=E7=9A=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84=E4=B8=8E=E5=93=8D=E5=BA=94?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- request/curl.go | 12 ++++++++ request/define.go | 48 +++++++++++++++++++++++++++++ request/param.go | 15 --------- request/restful.go | 77 ---------------------------------------------- 4 files changed, 60 insertions(+), 92 deletions(-) create mode 100644 request/curl.go create mode 100644 request/define.go delete mode 100644 request/param.go delete mode 100644 request/restful.go diff --git a/request/curl.go b/request/curl.go new file mode 100644 index 0000000..0fb0fc2 --- /dev/null +++ b/request/curl.go @@ -0,0 +1,12 @@ +// Package request... +// +// Description : http 请求 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2021-08-01 8:47 下午 +package request + +func Send(apiMethod *APIMethod) { + +} diff --git a/request/define.go b/request/define.go new file mode 100644 index 0000000..0493c8d --- /dev/null +++ b/request/define.go @@ -0,0 +1,48 @@ +// Package request... +// +// Description : 定义请求的数据结构 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2021-08-01 8:28 下午 +package request + +// APIMethod 定义API请求的信息 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 8:29 下午 2021/8/1 +type APIMethod struct { + ServiceDomain string `json:"service_domain"` // 调用服务的域名 + URI string `json:"uri"` // 调用的URI + Method string `json:"method"` // 请求方法 + ISRestfulURI bool `json:"is_restful_uri"` // 是否为restful uri + Header map[string]string `json:"header"` // 请求header + +} + +// ResponseConfig ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 8:32 下午 2021/8/1 +type ResponseConfig struct { + ISJson bool `json:"is_json"` // 响应数据是否为json + CodeKey string `json:"code_key"` // 代表业务Code的Key + MessageKey string `json:"message_key"` // 描述业务code的key + DataKey string `json:"data_key"` // 返回数据的key + SuccessRule string `json:"success_rule"` // 请求成功的规则, http_code / business_code http状态码或者业务状态码, 如果是通过http code 判断是否为请求成功 code key / message key 配置无效 + SuccessCode []string `json:"success_code"` // 哪些状态码被认为是请求成功 +} + +// APIResponse API响应数据 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 8:54 下午 2021/8/1 +type APIResponse struct { + Data string `json:"data"` // 响应数据 + Cost int64 `json:"cost"` // 接口耗时 + StartRequestTime int64 `json:"start_request_time"` // 开始请求时间 + FinishRequestTime int64 `json:"finish_request_time"` // 完成请求时间 +} diff --git a/request/param.go b/request/param.go deleted file mode 100644 index 487796b..0000000 --- a/request/param.go +++ /dev/null @@ -1,15 +0,0 @@ -// Package request 请求转发参数处理 -// -// Author go_developer@163.com<白茶清欢> -package request - -// ExtractParameterRule抽取参数提取的规则 -// -// Author go_developer@163.com<白茶清欢> -type ExtractParameterRule struct { - RequestParameterName string // 入参参数名称 - ForwardParameterName string // 转发参数名称 - ValueType string // 值的数据类型 - Required bool // 是否必须存在 - DefaultValue interface{} // 默认值 -} diff --git a/request/restful.go b/request/restful.go deleted file mode 100644 index cfbb310..0000000 --- a/request/restful.go +++ /dev/null @@ -1,77 +0,0 @@ -// Package request ... -// -// Author: go_developer@163.com<白茶清欢> -// -// Description: -// -// File: restful.go -// -// Version: 1.0.0 -// -// Date: 2021/07/07 20:11:57 -package request - -import ( - "fmt" - "strings" -) - -// URIConfig 构建URI的配置 -// -// Author : go_developer@163.com<白茶清欢> -type URIConfig struct { - Template string // url模版 - IsRestful bool // 是否是restful url - Left string // 左侧分隔符,针对restful生效 - Right string // 右侧分隔符,针对restful生效 - RemoveURIParam bool // 移除已经适配到URI里面的参数, 针对restful生效 -} - -// NewDefaultNormalURIConfig构建普通URL配置 -// -// Author : go_developer@163.com<白茶清欢> -func NewDefaultNormalURIConfig(urlTemplate string) *URIConfig { - return &URIConfig{ - Template: urlTemplate, - IsRestful: false, - Left: "", - Right: "", - RemoveURIParam: false, - } -} - -// NewDefaultNormalURIConfig 构建普通 restful URL配置 -// -// Author : go_developer@163.com<白茶清欢> -func NewDefaultRestfullURIConfig(urlTemplate string, left string, right string, removeURIParam bool) *URIConfig { - return &URIConfig{ - Template: urlTemplate, - IsRestful: true, - Left: left, - Right: right, - RemoveURIParam: removeURIParam, - } -} - -// BuildRestfulURL 构建 restful URI -// -// Author : go_developer@163.com<白茶清欢> -// -// Date : 2021/07/07 20:14:54 -func BuildURL(uriConfig *URIConfig, parameter map[string]interface{}) (string, map[string]interface{}) { - if !uriConfig.IsRestful { - return uriConfig.Template, parameter - } - uri := uriConfig.Template - finalParameter := make(map[string]interface{}) - for field, val := range parameter { - if strings.Contains(uri, uriConfig.Left+field+uriConfig.Right) { - uri = strings.ReplaceAll(uri, uriConfig.Left+field+uriConfig.Right, fmt.Sprintf("%v", val)) - if uriConfig.RemoveURIParam { - continue - } - } - finalParameter[field] = val - } - return uri, finalParameter -}