增加request方法
This commit is contained in:
parent
31fb310058
commit
82aa9d1e32
@ -60,4 +60,5 @@ type ApiResponse struct {
|
||||
HttpCode int `json:"http_code"` // http状态码
|
||||
Body []byte `json:"body"` // 响应体
|
||||
BodyType string `json:"body_type"` // 响应体数据类型
|
||||
Exception *Exception `json:"exception"` // 异常信息
|
||||
}
|
||||
|
@ -36,6 +36,8 @@ const (
|
||||
ResponseDataNotFound = "404004"
|
||||
// DomainInvalid 域名设置错误, 必须是 http:// 或者 https:// 开头
|
||||
DomainInvalid = "400001"
|
||||
// RequestMethodNotSupport 请求方法不支持
|
||||
RequestMethodNotSupport = "405001"
|
||||
)
|
||||
|
||||
// exceptionTable ...
|
||||
@ -51,6 +53,7 @@ var exceptionTable = map[string]string{
|
||||
ResponseMessageNotFound: "基于配置无法获取响应体状态码, 请检查 response_code_message 的配置, 当前配置 {response_code_message}",
|
||||
ResponseDataNotFound: "基于配置无法获取响应体状态码, 请检查 {response_code_data} 的配置, 当前配置 {response_code_data}",
|
||||
DomainInvalid: "api域名配置非法, 必须以 http:// 或者 https:// 开头, 当前配置 {domain}",
|
||||
RequestMethodNotSupport: "当前请求方法 {method} 不支持, 请核对相关配置",
|
||||
}
|
||||
|
||||
// NewException 实力化异常
|
||||
|
124
curl/request.go
Normal file
124
curl/request.go
Normal file
@ -0,0 +1,124 @@
|
||||
// Package curl ...
|
||||
//
|
||||
// Author: go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
// File: request.go
|
||||
//
|
||||
// Version: 1.0.0
|
||||
//
|
||||
// Date: 2022/05/01 21:25:03
|
||||
package curl
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Request 发送请求
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2022/05/01 21:26:02
|
||||
func Request(apiConfig *ApiRequestConfig, param map[string]interface{}) *ApiResponse {
|
||||
apiConfig.Method = strings.ToUpper(apiConfig.Method)
|
||||
switch apiConfig.Method {
|
||||
case http.MethodGet:
|
||||
return GET(apiConfig, param)
|
||||
case http.MethodPost:
|
||||
return POST(apiConfig, param)
|
||||
case http.MethodPut:
|
||||
return PUT(apiConfig, param)
|
||||
case http.MethodDelete:
|
||||
return DELETE(apiConfig, param)
|
||||
case http.MethodConnect:
|
||||
return Connect(apiConfig, param)
|
||||
case http.MethodOptions:
|
||||
return OPTION(apiConfig, param)
|
||||
case http.MethodTrace:
|
||||
return Trace(apiConfig, param)
|
||||
case http.MethodPatch:
|
||||
return Patch(apiConfig, param)
|
||||
default:
|
||||
return &ApiResponse{
|
||||
RequestConfig: apiConfig,
|
||||
HttpCode: 0,
|
||||
Body: nil,
|
||||
BodyType: "",
|
||||
Exception: NewException(RequestMethodNotSupport, map[string]string{"method": apiConfig.Method}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GET ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date: 2022/05/01 21:29:09
|
||||
func GET(apiConfig *ApiRequestConfig, param map[string]interface{}) *ApiResponse {
|
||||
return nil
|
||||
}
|
||||
|
||||
// POST post请求
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2022/05/01 21:31:36
|
||||
func POST(apiConfig *ApiRequestConfig, param map[string]interface{}) *ApiResponse {
|
||||
return nil
|
||||
}
|
||||
|
||||
// PUT put请求
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2022/05/01 21:31:52
|
||||
func PUT(apiConfig *ApiRequestConfig, param map[string]interface{}) *ApiResponse {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DELETE delete请求
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2022/05/01 21:32:08
|
||||
func DELETE(apiConfig *ApiRequestConfig, param map[string]interface{}) *ApiResponse {
|
||||
return nil
|
||||
}
|
||||
|
||||
// OPTION option请求
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2022/05/01 21:32:18
|
||||
func OPTION(apiConfig *ApiRequestConfig, param map[string]interface{}) *ApiResponse {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Patch patch请求
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2022/05/01 21:36:12
|
||||
func Patch(apiConfig *ApiRequestConfig, param map[string]interface{}) *ApiResponse {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Trace trace请求
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2022/05/01 21:36:24
|
||||
func Trace(apiConfig *ApiRequestConfig, param map[string]interface{}) *ApiResponse {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Connect connect请求
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2022/05/01 21:36:39
|
||||
func Connect(apiConfig *ApiRequestConfig, param map[string]interface{}) *ApiResponse {
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user