Compare commits
50 Commits
3bb8dc0660
...
master
Author | SHA1 | Date | |
---|---|---|---|
d9316b26c8 | |||
4da6028308 | |||
cd667a868d | |||
59a8ce9a9d | |||
e5ff8dcdf3 | |||
62d3c792ce | |||
fdbec81b1c | |||
b6aaa49ab6 | |||
cc32decb80 | |||
739a50167e | |||
024caeea25 | |||
fb758a6ad4 | |||
27e02a3570 | |||
eb2302301f | |||
54ad5d7873 | |||
3ac08b5e9e | |||
f80576d8a8 | |||
6916755206 | |||
4febd7fa95 | |||
86977c5117 | |||
6f37d3cad3 | |||
54aef081d9 | |||
09e47648bc | |||
0057825613 | |||
049f9cca4f | |||
ede74d9508 | |||
b3ce41b3b0 | |||
ce8f34cc81 | |||
2d69d673ec | |||
696d31b0f2 | |||
67651bbe90 | |||
473367da9f | |||
f44b90c10b | |||
7d7c9fc8d5 | |||
691482d6a8 | |||
30c1cc67c2 | |||
04f782ac07 | |||
f766b4c7e3 | |||
7cb9e6b02c | |||
bc59aba0ec | |||
24fe4c9adc | |||
091571128e | |||
f8a6482e0a | |||
1326ec76a8 | |||
0ced660ca2 | |||
4f3252f57f | |||
bbb96188a1 | |||
59a6455270 | |||
14fa48d6f1 | |||
4e0e9f8375 |
88
define.go
88
define.go
@ -13,14 +13,18 @@ package rpc
|
||||
//
|
||||
// Date : 14:08 2022/6/29
|
||||
type Service struct {
|
||||
Flag string `json:"flag" yaml:"flag"` // 服务标识, 全局唯一
|
||||
Domain string `json:"domain" yaml:"domain"` // 域名服务
|
||||
CodeField string `json:"code_field" yaml:"code_field"` // 状态码字段
|
||||
MessageField string `json:"message_field" yaml:"message_field"` // 消息字段
|
||||
DataField string `json:"data_field" yaml:"data_field"` // 数据字段
|
||||
SuccessCodeList []string `json:"success_code_list" yaml:"success_code_list"` // 成功的值
|
||||
ApiTable map[string]interface{} `json:"api_table" yaml:"api_table"` // api列表
|
||||
ApiRetry ApiRetry `json:"api_retry" yaml:"api_retry"` // 重试策略
|
||||
Flag string `json:"flag" yaml:"flag" ini:"flag"` // 服务标识, 全局唯一
|
||||
Description string `json:"description" yaml:"description" ini:"description"` // 服务描述
|
||||
Domain string `json:"domain" yaml:"domain" ini:"domain"` // 域名服务
|
||||
MockEnable bool `json:"mock_enable" yaml:"mock_enable" ini:"mock_enable"` // 是否可用mock,默认false
|
||||
MockPath string `json:"mock_path" yaml:"mock_path" ini:"mock_path"` // mock数据的存储路径,不配置默认为 ./{service_flag}
|
||||
CodeField string `json:"code_field" yaml:"code_field" ini:"code_field"` // 状态码字段
|
||||
MessageField string `json:"message_field" yaml:"message_field" ini:"message_field"` // 消息字段
|
||||
DataField string `json:"data_field" yaml:"data_field" ini:"data_field"` // 数据字段
|
||||
SuccessCodeList []string `json:"success_code_list" yaml:"success_code_list" ini:"success_code_list"` // 成功的值
|
||||
SuccessHttpCodeList []int `json:"success_http_code_list" yaml:"success_http_code_list" ini:"success_http_code_list"` // 任务成功的http状态码, 不配置默认只有200(优先级高, 会覆盖)
|
||||
ApiTable map[string]*Api `json:"api_table" yaml:"api_table" ini:"api_table"` // api列表
|
||||
ApiRetry ApiRetry `json:"api_retry" yaml:"api_retry" ini:"api_retry"` // 重试策略
|
||||
}
|
||||
|
||||
// Api 接口的数据结构
|
||||
@ -29,18 +33,20 @@ type Service struct {
|
||||
//
|
||||
// Date : 14:18 2022/6/29
|
||||
type Api struct {
|
||||
URI string `json:"uri" yaml:"uri"` // 接口地址
|
||||
Method string `json:"method" yaml:"method"` // 请求方法 GET / POST / PUT 等
|
||||
CodeField string `json:"code_field" yaml:"code_field"` // 状态码字段
|
||||
MessageField string `json:"message_field" yaml:"message_field"` // 消息字段
|
||||
DataField string `json:"data_field" yaml:"data_field"` // 数据字段(优先级高, 会覆盖)
|
||||
SuccessCodeList []string `json:"success_code_list" yaml:"success_code_list"` // 成功的值(优先级高, 会覆盖)
|
||||
SuccessHttpCodeList []int `json:"success_http_code_list" yaml:"success_http_code_list"` // 任务成功的http状态码, 不配置默认只有200(优先级高, 会覆盖)
|
||||
Header map[string]string `json:"header" yaml:"header"` // 传入的header
|
||||
Cookie map[string]string `json:"cookie" yaml:"cookie"` // 传入的cookie
|
||||
BindURIParamList []string `json:"bind_uri_param_list" yaml:"bind_uri_param_list"` // 绑定到URI的参数列表
|
||||
Timeout ApiTimeout `json:"timeout" yaml:"timeout"`
|
||||
Retry ApiRetry `json:"retry" yaml:"retry"` // 重试策略
|
||||
Flag string `json:"flag" yaml:"flag" ini:"flag"` // URI标识
|
||||
MockEnable bool `json:"mock_enable" yaml:"mock_enable" ini:"mock_enable"` // 当前接口是否可用mock服务
|
||||
Description string `json:"description" yaml:"description" ini:"description"` // 接口描述
|
||||
URI string `json:"uri" yaml:"uri" ini:"uri"` // 接口地址
|
||||
Method string `json:"method" yaml:"method" ini:"method"` // 请求方法 GET / POST / PUT 等
|
||||
CodeField string `json:"code_field" yaml:"code_field" ini:"code_field"` // 状态码字段
|
||||
MessageField string `json:"message_field" yaml:"message_field" ini:"message_field"` // 消息字段
|
||||
DataField string `json:"data_field" yaml:"data_field" ini:"data_field"` // 数据字段(优先级高, 会覆盖)
|
||||
SuccessCodeList []string `json:"success_code_list" yaml:"success_code_list" ini:"success_code_list"` // 成功的值(优先级高, 会覆盖)
|
||||
SuccessHttpCodeList []int `json:"success_http_code_list" yaml:"success_http_code_list" ini:"success_http_code_list"` // 任务成功的http状态码, 不配置默认只有200(优先级高, 会覆盖)
|
||||
Header map[string]string `json:"header" yaml:"header" ini:"header"` // 传入的header
|
||||
BindURIParamList []string `json:"bind_uri_param_list" yaml:"bind_uri_param_list" ini:"bind_uri_param_list"` // 绑定到URI的参数列表
|
||||
Timeout ApiTimeout `json:"timeout" yaml:"timeout" ini:"timeout"` // 超时配置
|
||||
Retry ApiRetry `json:"retry" yaml:"retry" ini:"timeout"` // 重试策略
|
||||
}
|
||||
|
||||
// ApiTimeout 超时配置
|
||||
@ -49,8 +55,8 @@ type Api struct {
|
||||
//
|
||||
// Date : 15:08 2022/6/29
|
||||
type ApiTimeout struct {
|
||||
Read int `json:"read" yaml:"read"` // 读取超时时间
|
||||
Connect int `json:"connect" yaml:"connect"` // 连接超时时间
|
||||
Read int `json:"read" yaml:"read" ini:"read"` // 读取超时时间
|
||||
Connect int `json:"connect" yaml:"connect" ini:"connect"` // 连接超时时间
|
||||
}
|
||||
|
||||
// ApiRetry 接口重试
|
||||
@ -59,10 +65,36 @@ type ApiTimeout struct {
|
||||
//
|
||||
// Date : 15:10 2022/6/29
|
||||
type ApiRetry struct {
|
||||
ConnectTimeout bool `json:"connect_timeout" yaml:"connect_timeout"` // 连接超时是否重试
|
||||
ReadTimeout bool `json:"read_timeout" yaml:"read_timeout"` // 读取超时是否重试
|
||||
BusinessCodeFail bool `json:"business_code_fail" yaml:"business_code_fail"` // 业务状态码错误是否重试
|
||||
HttpCodeFail bool `json:"http_code_fail"` // http状态码异常是否重试
|
||||
Count int `json:"count" yaml:"count"` // 重试次数
|
||||
Frequency int `json:"frequency" yaml:"frequency"` // 重试频率, 单位 : ms
|
||||
ConnectTimeout bool `json:"connect_timeout" yaml:"connect_timeout" ini:"connect_timeout"` // 连接超时是否重试
|
||||
ReadTimeout bool `json:"read_timeout" yaml:"read_timeout" ini:"read_timeout"` // 读取超时是否重试
|
||||
BusinessCodeFail bool `json:"business_code_fail" yaml:"business_code_fail" ini:"business_code_fail"` // 业务状态码错误是否重试
|
||||
HttpCodeFail bool `json:"http_code_fail" yaml:"http_code_fail" ini:"http_code_fail"` // http状态码异常是否重试
|
||||
Count int `json:"count" yaml:"count" ini:"count"` // 重试次数
|
||||
Frequency int `json:"frequency" yaml:"frequency" ini:"frequency"` // 重试频率, 单位 : ms
|
||||
}
|
||||
|
||||
// responseDaFieldConfig 响应数据的字段配置
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:07 2022/7/1
|
||||
type responseDaFieldConfig struct {
|
||||
Code string
|
||||
Message string
|
||||
Data string
|
||||
}
|
||||
|
||||
const (
|
||||
// DefaultConnectTimeout 默认连接超时
|
||||
DefaultConnectTimeout = 100
|
||||
// DefaultReadTimeout 默认读取超时
|
||||
DefaultReadTimeout = 300
|
||||
// DefaultCodeField 默认状态码字段
|
||||
DefaultCodeField = "code"
|
||||
// DefaultMessageField 默认描述字段
|
||||
DefaultMessageField = "message"
|
||||
// DefaultDataField 默认数据字段
|
||||
DefaultDataField = "data"
|
||||
// SpecialFiledVal 特殊的 code / message / data配置
|
||||
SpecialFiledVal = "-"
|
||||
)
|
||||
|
54
etc/goproxy.yaml
Normal file
54
etc/goproxy.yaml
Normal file
@ -0,0 +1,54 @@
|
||||
flag: goproxy
|
||||
description: "包下载信息统计服务"
|
||||
domain: https://goproxy.cn/
|
||||
mock_enable: false
|
||||
mock_path:
|
||||
code_field: '-'
|
||||
message_field: '-'
|
||||
data_field: '-'
|
||||
success_code_list: []
|
||||
success_http_code_list:
|
||||
- 200
|
||||
api_table:
|
||||
package_info:
|
||||
description: "获取包的下载信息"
|
||||
flag: package_info
|
||||
uri: /stats/{{package_name}}
|
||||
method: GET
|
||||
bind_uri_param_list:
|
||||
- package_name
|
||||
timeout:
|
||||
read: 50000
|
||||
connect: 50000
|
||||
retry:
|
||||
connect_timeout: false
|
||||
read_timeout: false
|
||||
business_code_fail: false
|
||||
httpcodefail: false
|
||||
count: 0
|
||||
frequency: 0
|
||||
package_version_info:
|
||||
description: "获取包指定版本的下载信息"
|
||||
flag: package_version_info
|
||||
uri: /stats/{{package_name}}@{{package_version}}
|
||||
method: GET
|
||||
bind_uri_param_list:
|
||||
- package_name
|
||||
- package_version
|
||||
timeout:
|
||||
read: 50000
|
||||
connect: 50000
|
||||
retry:
|
||||
connect_timeout: false
|
||||
read_timeout: false
|
||||
business_code_fail: false
|
||||
httpcodefail: false
|
||||
count: 0
|
||||
frequency: 0
|
||||
api_retry:
|
||||
connect_timeout: false
|
||||
read_timeout: false
|
||||
business_code_fail: false
|
||||
httpcodefail: false
|
||||
count: 0
|
||||
frequency: 0
|
56
go.mod
56
go.mod
@ -1,10 +1,56 @@
|
||||
module git.zhangdeman.cn/zhangdeman/rpc
|
||||
|
||||
go 1.17
|
||||
go 1.21
|
||||
|
||||
toolchain go1.21.4
|
||||
|
||||
require (
|
||||
github.com/ddliu/go-httpclient v0.6.9 // indirect
|
||||
go.uber.org/atomic v1.9.0 // indirect
|
||||
go.uber.org/multierr v1.8.0 // indirect
|
||||
go.uber.org/zap v1.21.0 // indirect
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20231014142840-445c6407db92
|
||||
github.com/ddliu/go-httpclient v0.7.1
|
||||
github.com/gin-gonic/gin v1.9.1
|
||||
github.com/tidwall/gjson v1.17.0
|
||||
go.uber.org/zap v1.26.0
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/Jeffail/gabs v1.4.0 // indirect
|
||||
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 // indirect
|
||||
github.com/bytedance/sonic v1.10.2 // indirect
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
|
||||
github.com/chenzhuoyu/iasm v0.9.1 // indirect
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-ini/ini v1.67.0 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.16.0 // indirect
|
||||
github.com/goccy/go-json v0.10.2 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/leodido/go-urn v1.2.4 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/mozillazg/go-pinyin v0.20.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
github.com/tidwall/pretty v1.2.1 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
go.uber.org/atomic v1.11.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
golang.org/x/arch v0.6.0 // indirect
|
||||
golang.org/x/crypto v0.15.0 // indirect
|
||||
golang.org/x/net v0.18.0 // indirect
|
||||
golang.org/x/sys v0.14.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
215
go.sum
215
go.sum
@ -1,53 +1,250 @@
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20230211164227-256094968151 h1:j537bRLQL1FlkdXTIaT9Ecjx5eogkPsGiTOWIEFQlc8=
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20230211164227-256094968151/go.mod h1:SyRTkOz6gxUVn3S/Qtkf+rhKV0I1ym8lwsT8YjggYFs=
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20231014142840-445c6407db92 h1:p1GVRYJc3NNoZeLs4CukitAbM3O/ALNq3l31cnbBQDM=
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20231014142840-445c6407db92/go.mod h1:6OBeuwKy2J1TjdAwStEyC6aYC3kStmJiCg1eFC7g0fk=
|
||||
github.com/Jeffail/gabs v1.4.0 h1://5fYRRTq1edjfIrQGvdkcd22pkYUrHZ5YC/H2GJVAo=
|
||||
github.com/Jeffail/gabs v1.4.0/go.mod h1:6xMvQMK4k33lb7GUUpaAPh6nKMmemQeg5d4gn7/bOXc=
|
||||
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 h1:OYA+5W64v3OgClL+IrOD63t4i/RW7RqrAVl9LTZ9UqQ=
|
||||
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394/go.mod h1:Q8n74mJTIgjX4RBBcHnJ05h//6/k6foqmgE45jTQtxg=
|
||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
|
||||
github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM=
|
||||
github.com/bytedance/sonic v1.10.2 h1:GQebETVBxYB7JGWJtLBi07OVzWwt+8dWA00gEVW2ZFE=
|
||||
github.com/bytedance/sonic v1.10.2/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4=
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0=
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA=
|
||||
github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
|
||||
github.com/chenzhuoyu/iasm v0.9.1 h1:tUHQJXo3NhBqw6s33wkGn9SP3bvrWLdlVIJ3hQBL7P0=
|
||||
github.com/chenzhuoyu/iasm v0.9.1/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/ddliu/go-httpclient v0.6.9 h1:/3hsBVpcgCJwqm1dkVlnAJ9NWuYInbRc+i9FyUXX/LE=
|
||||
github.com/ddliu/go-httpclient v0.6.9/go.mod h1:zM9P0OxV4OGGz1pt/ibuj0ooX2SWH9a6MvXZLbT0JMc=
|
||||
github.com/ddliu/go-httpclient v0.7.1 h1:COWYBalfbaFNe6e0eQU38++vCD5kzLh1H1RFs3xcn9g=
|
||||
github.com/ddliu/go-httpclient v0.7.1/go.mod h1:uwipe9x9SYGk4JhBemO7+dD87QbiY224y0DLB9OY0Ik=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||
github.com/gin-gonic/gin v1.8.2 h1:UzKToD9/PoFj/V4rvlKqTRKnQYyz8Sc1MJlv4JHPtvY=
|
||||
github.com/gin-gonic/gin v1.8.2/go.mod h1:qw5AYuDrzRTnhvusDsrov+fDIxp9Dleuu12h8nfB398=
|
||||
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
|
||||
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
|
||||
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
|
||||
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
|
||||
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
|
||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||
github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
|
||||
github.com/go-playground/validator/v10 v10.11.2 h1:q3SHpufmypg+erIExEKUmsgmhDTyhcJ38oeKGACXohU=
|
||||
github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVLvdmjPAeV8BQlHtMnw9D7s=
|
||||
github.com/go-playground/validator/v10 v10.16.0 h1:x+plE831WK4vaKHO/jpgUGsvLKIqRRkz6M78GuJAfGE=
|
||||
github.com/go-playground/validator/v10 v10.16.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
|
||||
github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||
github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA=
|
||||
github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
|
||||
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc=
|
||||
github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
|
||||
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
|
||||
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
|
||||
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
|
||||
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
|
||||
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
|
||||
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/mozillazg/go-pinyin v0.20.0 h1:BtR3DsxpApHfKReaPO1fCqF4pThRwH9uwvXzm+GnMFQ=
|
||||
github.com/mozillazg/go-pinyin v0.20.0/go.mod h1:iR4EnMMRXkfpFVV5FMi4FNB6wGq9NV6uDWbUuPhP4Yc=
|
||||
github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=
|
||||
github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek=
|
||||
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
|
||||
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
|
||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
||||
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
|
||||
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
|
||||
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
|
||||
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM=
|
||||
github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/gjson v1.17.0 h1:/Jocvlh98kcTfpN2+JzGQWQcqrPQwDrVEMApx/M5ZwM=
|
||||
github.com/tidwall/gjson v1.17.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
|
||||
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||
github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo=
|
||||
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
|
||||
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
|
||||
github.com/ugorji/go/codec v1.2.9 h1:rmenucSohSTiyL09Y+l2OCk+FrMxGMzho2+tjr5ticU=
|
||||
github.com/ugorji/go/codec v1.2.9/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
|
||||
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
|
||||
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
|
||||
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
|
||||
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
|
||||
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
|
||||
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
|
||||
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
||||
go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8=
|
||||
go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
|
||||
go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8=
|
||||
go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw=
|
||||
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
|
||||
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
|
||||
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
|
||||
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
|
||||
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
|
||||
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
|
||||
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
|
||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||
golang.org/x/arch v0.6.0 h1:S0JTfE48HbRj80+4tbvZDYsJ3tGv6BUU3XxyZ7CirAc=
|
||||
golang.org/x/arch v0.6.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
|
||||
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
|
||||
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
|
||||
golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA=
|
||||
golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
|
||||
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
|
||||
golang.org/x/net v0.6.0 h1:L4ZwwTvKW9gr0ZMS1yrHD9GZhIuVjOBBnaKH+SPQK0Q=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
|
||||
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
|
||||
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
|
||||
golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
||||
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
|
||||
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
|
||||
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
||||
|
139
httpclient.go
Normal file
139
httpclient.go
Normal file
@ -0,0 +1,139 @@
|
||||
// Package rpc ...
|
||||
//
|
||||
// Description : rpc ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2023-02-14 14:33
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/util"
|
||||
|
||||
"github.com/ddliu/go-httpclient"
|
||||
)
|
||||
|
||||
var (
|
||||
// HttpClient http 客户端
|
||||
HttpClient *httpClient
|
||||
)
|
||||
|
||||
func init() {
|
||||
HttpClient = &httpClient{}
|
||||
}
|
||||
|
||||
type httpClient struct {
|
||||
}
|
||||
|
||||
// Send 统一发送请求方法
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 14:37 2023/2/14
|
||||
func (hc *httpClient) Send(requestURL string, method string, header map[string]string, param map[string]interface{}, options httpclient.Map) ([]byte, error) {
|
||||
var (
|
||||
err error
|
||||
response *httpclient.Response
|
||||
c *httpclient.HttpClient
|
||||
)
|
||||
if nil == param {
|
||||
param = make(map[string]interface{})
|
||||
}
|
||||
if nil == header {
|
||||
header = make(map[string]string)
|
||||
}
|
||||
if nil == options {
|
||||
options = map[interface{}]interface{}{}
|
||||
}
|
||||
c = httpclient.NewHttpClient()
|
||||
c.Headers = header
|
||||
c.WithOptions(options)
|
||||
byteData, _ := json.Marshal(param)
|
||||
paramMap := map[string]string{}
|
||||
for k, v := range param {
|
||||
paramMap[k] = fmt.Sprintf("%v", v)
|
||||
}
|
||||
switch strings.ToUpper(method) {
|
||||
case http.MethodGet:
|
||||
response, err = c.Get(requestURL, paramMap)
|
||||
case http.MethodConnect:
|
||||
response, err = c.Connect(requestURL, paramMap)
|
||||
case http.MethodHead:
|
||||
response, err = c.Head(requestURL)
|
||||
case http.MethodOptions:
|
||||
response, err = c.Options(requestURL, paramMap)
|
||||
case http.MethodPatch:
|
||||
response, err = c.Patch(requestURL, paramMap)
|
||||
case http.MethodPut:
|
||||
response, err = c.Put(requestURL, bytes.NewReader(byteData))
|
||||
case http.MethodDelete:
|
||||
response, err = c.Delete(requestURL, paramMap)
|
||||
case http.MethodPost:
|
||||
response, err = c.Post(requestURL, bytes.NewReader(byteData))
|
||||
case http.MethodTrace:
|
||||
response, err = c.Trace(requestURL, paramMap)
|
||||
default:
|
||||
return nil, errors.New(method + " is not invalid")
|
||||
}
|
||||
if nil != err {
|
||||
return nil, errors.New(" request send fail : " + err.Error())
|
||||
}
|
||||
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("%v : %v", response.StatusCode, response.Status)
|
||||
}
|
||||
|
||||
return hc.getResponseBody(response)
|
||||
}
|
||||
|
||||
// getResponseBody ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 15:12 2023/2/14
|
||||
func (hc *httpClient) getResponseBody(response *httpclient.Response) ([]byte, error) {
|
||||
var (
|
||||
responseBody []byte
|
||||
err error
|
||||
gzipInstance *gzip.Reader
|
||||
buf bytes.Buffer
|
||||
)
|
||||
if responseBody, err = io.ReadAll(response.Body); nil != err {
|
||||
return nil, err
|
||||
}
|
||||
// 判断返回值是否经过gzip压缩
|
||||
responseGzip := response.Header.Get("content-encoding")
|
||||
if strings.ToLower(responseGzip) == "gzip" {
|
||||
// 压缩过的数据,在处理response body
|
||||
if gzipInstance, err = gzip.NewReader(bytes.NewReader(responseBody)); nil != err {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
_ = gzipInstance.Close()
|
||||
}()
|
||||
if _, err = io.Copy(&buf, gzipInstance); nil != err {
|
||||
return nil, err
|
||||
}
|
||||
responseBody = buf.Bytes()
|
||||
}
|
||||
// 判断是否为gbk编码,若是,转为utf8
|
||||
isGBK := strings.Contains(strings.ToLower(response.Header.Get("content-type")), "gbk")
|
||||
if isGBK {
|
||||
return []byte(util.String.Convert(string(responseBody), "gbk", "utf-8")), nil
|
||||
}
|
||||
// 判断是否为gb2312,若是,转为utf8
|
||||
isGB2312 := strings.Contains(strings.ToLower(response.Header.Get("content-type")), "gb2312")
|
||||
if isGB2312 {
|
||||
return []byte(util.String.Convert(string(responseBody), "gb2312", "utf-8")), nil
|
||||
}
|
||||
return responseBody, nil
|
||||
}
|
97
result.go
Normal file
97
result.go
Normal file
@ -0,0 +1,97 @@
|
||||
// Package rpc ...
|
||||
//
|
||||
// Description : rpc ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2022-06-30 18:33c
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/util"
|
||||
"github.com/tidwall/gjson"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// parseResponseBody 解析响应body, 支持 json + xml + ini + yaml
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:36 2022/6/30
|
||||
func parseResponseBody(responseType string, body []byte, receiver interface{}) error {
|
||||
responseType = strings.ToLower(responseType)
|
||||
if strings.Contains(responseType, "json") {
|
||||
return parser.ParseJSON(body, receiver)
|
||||
}
|
||||
if strings.Contains(responseType, "xml") {
|
||||
return parser.ParseXml(body, receiver)
|
||||
}
|
||||
if strings.Contains(responseType, "yaml") || strings.Contains(responseType, "yml") {
|
||||
return parser.ParseYaml(body, receiver)
|
||||
}
|
||||
if strings.Contains(responseType, "ini") {
|
||||
return parser.ParseIni(body, receiver)
|
||||
}
|
||||
|
||||
// 适配 text/plan
|
||||
if strings.Contains(responseType, "plain") {
|
||||
if !gjson.Valid(string(body)) {
|
||||
return errors.New("text/plain 类型数据仅支持通过JSON解析")
|
||||
}
|
||||
return parser.ParseJSON(body, receiver)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var parser *result
|
||||
|
||||
func init() {
|
||||
parser = &result{}
|
||||
parser = &result{}
|
||||
}
|
||||
|
||||
type result struct {
|
||||
}
|
||||
|
||||
// ParseJSON 解析JSON数据
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:34 2022/6/30
|
||||
func (r *result) ParseJSON(inputContent []byte, receiver interface{}) error {
|
||||
return util.JSON.UnmarshalWithNumber(inputContent, receiver)
|
||||
}
|
||||
|
||||
// ParseYaml 解析yaml数据
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:34 2022/6/30
|
||||
func (r *result) ParseYaml(inputContent []byte, receiver interface{}) error {
|
||||
decoder := yaml.NewDecoder(bytes.NewReader(inputContent))
|
||||
return decoder.Decode(receiver)
|
||||
}
|
||||
|
||||
// ParseXml 解析xml数据
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:35 2022/6/30
|
||||
func (r *result) ParseXml(inputContent []byte, receiver interface{}) error {
|
||||
return xml.Unmarshal(inputContent, receiver)
|
||||
}
|
||||
|
||||
// ParseIni 解析ini
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 11:11 2022/7/1
|
||||
func (r *result) ParseIni(inputContent []byte, receiver interface{}) error {
|
||||
|
||||
return nil
|
||||
}
|
618
rpc.go
618
rpc.go
@ -8,8 +8,26 @@
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/util"
|
||||
|
||||
"github.com/ddliu/go-httpclient"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@ -23,7 +41,15 @@ var (
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 15:23 2022/6/29
|
||||
func InitRPC(serviceTable map[string]Service, loggerInstance *zap.Logger) error {
|
||||
func InitRPC(serviceTable map[string]*Service, loggerInstance *zap.Logger) error {
|
||||
if nil == serviceTable {
|
||||
serviceTable = make(map[string]*Service)
|
||||
}
|
||||
for _, item := range serviceTable {
|
||||
if item.ApiTable == nil {
|
||||
item.ApiTable = make(map[string]*Api)
|
||||
}
|
||||
}
|
||||
Request = &request{
|
||||
logger: loggerInstance,
|
||||
serviceTable: serviceTable,
|
||||
@ -32,8 +58,596 @@ func InitRPC(serviceTable map[string]Service, loggerInstance *zap.Logger) error
|
||||
return nil
|
||||
}
|
||||
|
||||
// InitRPCFromCfgDir 使用RPC配置文件路径初始化RPC
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:41 2022/7/1
|
||||
func InitRPCFromCfgDir(cfgDir string, logger *zap.Logger) error {
|
||||
serviceTable := make(map[string]*Service)
|
||||
filepathNames, _ := filepath.Glob(filepath.Join(cfgDir, "*"))
|
||||
for i := range filepathNames {
|
||||
var (
|
||||
serviceInfo Service
|
||||
err error
|
||||
)
|
||||
|
||||
if err = util.File.ReadAnyFileContent(filepathNames[i], &serviceInfo); nil != err {
|
||||
return err
|
||||
}
|
||||
if len(serviceInfo.MockPath) == 0 {
|
||||
// 填充默认的mock数据存储路径
|
||||
serviceInfo.MockPath = util.Project.BuildPath("mock")
|
||||
}
|
||||
serviceTable[serviceInfo.Flag] = &serviceInfo
|
||||
}
|
||||
return InitRPC(serviceTable, logger)
|
||||
}
|
||||
|
||||
// InitRPCFromCfgFile 从配置文件初始化RPC服务
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:42 2022/7/1
|
||||
func InitRPCFromCfgFile(cfgFile string, logger *zap.Logger) error {
|
||||
var (
|
||||
serviceTable map[string]*Service
|
||||
err error
|
||||
)
|
||||
if err = util.File.ReadAnyFileContent(cfgFile, &serviceTable); nil != err {
|
||||
return err
|
||||
}
|
||||
return InitRPC(serviceTable, logger)
|
||||
}
|
||||
|
||||
type request struct {
|
||||
logger *zap.Logger
|
||||
serviceTable map[string]Service
|
||||
serviceTable map[string]*Service
|
||||
lock *sync.RWMutex
|
||||
}
|
||||
|
||||
// AddService 新增一个服务
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:13 2022/6/29
|
||||
func (r *request) AddService(serviceInfo *Service) error {
|
||||
if nil == serviceInfo {
|
||||
return errors.New("service info is nil")
|
||||
}
|
||||
if nil == serviceInfo.SuccessCodeList {
|
||||
serviceInfo.SuccessCodeList = []string{"0"}
|
||||
}
|
||||
if nil == serviceInfo.SuccessHttpCodeList {
|
||||
serviceInfo.SuccessHttpCodeList = []int{http.StatusOK}
|
||||
}
|
||||
if len(serviceInfo.CodeField) == 0 {
|
||||
serviceInfo.CodeField = DefaultCodeField
|
||||
}
|
||||
if len(serviceInfo.DataField) == 0 {
|
||||
serviceInfo.DataField = DefaultDataField
|
||||
}
|
||||
if len(serviceInfo.MessageField) == 0 {
|
||||
serviceInfo.MessageField = DefaultMessageField
|
||||
}
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
if _, exist := r.serviceTable[serviceInfo.Flag]; exist {
|
||||
return errors.New(serviceInfo.Flag + " already exist")
|
||||
}
|
||||
r.serviceTable[serviceInfo.Flag] = serviceInfo
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetServiceInfo ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 11:32 2022/6/30
|
||||
func (r *request) GetServiceInfo(serviceFlag string) (*Service, error) {
|
||||
var (
|
||||
serviceInfo *Service
|
||||
exist bool
|
||||
)
|
||||
|
||||
r.lock.RLock()
|
||||
defer r.lock.RUnlock()
|
||||
if serviceInfo, exist = r.serviceTable[serviceFlag]; !exist {
|
||||
return nil, errors.New(serviceFlag + " -> 服务不存在")
|
||||
}
|
||||
return serviceInfo, nil
|
||||
}
|
||||
|
||||
// RemoveService 删除一个service
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 11:46 2022/6/30
|
||||
func (r *request) RemoveService(serviceFlag string) {
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
delete(r.serviceTable, serviceFlag)
|
||||
}
|
||||
|
||||
// AddServiceApi 向一个service中增加Api
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 11:26 2022/6/30
|
||||
func (r *request) AddServiceApi(serviceFlag string, apiConfig *Api) error {
|
||||
var (
|
||||
serviceInfo *Service
|
||||
err error
|
||||
)
|
||||
|
||||
if serviceInfo, err = r.GetServiceInfo(serviceFlag); nil != err {
|
||||
return err
|
||||
}
|
||||
if len(apiConfig.SuccessCodeList) == 0 {
|
||||
apiConfig.SuccessCodeList = serviceInfo.SuccessCodeList
|
||||
}
|
||||
if len(apiConfig.SuccessHttpCodeList) == 0 {
|
||||
apiConfig.SuccessHttpCodeList = serviceInfo.SuccessHttpCodeList
|
||||
}
|
||||
if len(apiConfig.CodeField) == 0 {
|
||||
apiConfig.CodeField = serviceInfo.CodeField
|
||||
}
|
||||
if len(apiConfig.DataField) == 0 {
|
||||
apiConfig.DataField = serviceInfo.DataField
|
||||
}
|
||||
if len(apiConfig.MessageField) == 0 {
|
||||
apiConfig.MessageField = serviceInfo.MessageField
|
||||
}
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
if nil == serviceInfo.ApiTable {
|
||||
serviceInfo.ApiTable = make(map[string]*Api)
|
||||
}
|
||||
serviceInfo.ApiTable[apiConfig.Flag] = apiConfig
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetServiceApi 获取服务api配置
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 11:53 2022/6/30
|
||||
func (r *request) GetServiceApi(serviceFlag string, apiFlag string) (*Service, *Api, error) {
|
||||
var (
|
||||
serviceInfo *Service
|
||||
err error
|
||||
exist bool
|
||||
apiInfo *Api
|
||||
)
|
||||
if serviceInfo, err = r.GetServiceInfo(serviceFlag); nil != err {
|
||||
return nil, nil, err
|
||||
}
|
||||
r.lock.RLock()
|
||||
defer r.lock.RUnlock()
|
||||
if apiInfo, exist = serviceInfo.ApiTable[apiFlag]; !exist {
|
||||
return nil, nil, errors.New(serviceFlag + " : " + apiFlag + " -> api")
|
||||
}
|
||||
return serviceInfo, apiInfo, nil
|
||||
}
|
||||
|
||||
// RemoveServiceApi 删除服务下的一个api
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 12:02 2022/6/30
|
||||
func (r *request) RemoveServiceApi(serviceFlag string, apiFlag string) {
|
||||
var (
|
||||
serviceInfo *Service
|
||||
err error
|
||||
)
|
||||
if serviceInfo, _, err = r.GetServiceApi(serviceFlag, apiFlag); nil != err {
|
||||
// 不存在无需处理
|
||||
return
|
||||
}
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
delete(serviceInfo.ApiTable, apiFlag)
|
||||
}
|
||||
|
||||
// Get ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 14:25 2022/6/30
|
||||
func (r *request) Get() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Send 统一的发送请求方法
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 14:24 2022/6/30
|
||||
func (r *request) Send(ctx *gin.Context, serviceFlag string, apiFlag string, parameter map[string]interface{}, header map[string]string, receiver interface{}) error {
|
||||
var (
|
||||
serviceConfig *Service
|
||||
apiConfig *Api
|
||||
err error
|
||||
fullURL string
|
||||
client *httpclient.HttpClient
|
||||
body []byte
|
||||
response *httpclient.Response
|
||||
responseBody []byte
|
||||
code, message, data string
|
||||
mockFilePath string
|
||||
)
|
||||
|
||||
// 日志数据
|
||||
logDataList := []zap.Field{
|
||||
zap.String("service_flag", serviceFlag),
|
||||
zap.String("service_api_flag", apiFlag),
|
||||
zap.Any("input_param", parameter),
|
||||
}
|
||||
defer func() {
|
||||
// 记录请求日志
|
||||
r.loggerRequest(ctx, logDataList...)
|
||||
}()
|
||||
if serviceConfig, apiConfig, err = r.GetServiceApi(serviceFlag, apiFlag); nil != err {
|
||||
logDataList = append(logDataList, zap.Any("read_api_config_fail", err.Error()))
|
||||
return err
|
||||
}
|
||||
logDataList = append(logDataList,
|
||||
zap.Any("api_config", apiConfig),
|
||||
zap.Any("service_mock_enable", serviceConfig.MockEnable),
|
||||
zap.Any("api_mock_enable", apiConfig.MockEnable),
|
||||
)
|
||||
|
||||
if responseBody, mockFilePath, err = r.getMockData(serviceConfig, apiConfig); nil == err {
|
||||
logDataList = append(logDataList, zap.Any("mock_file_path", mockFilePath))
|
||||
} else {
|
||||
logDataList = append(logDataList,
|
||||
zap.Any("mock_file_path", mockFilePath),
|
||||
zap.Any("mock_disable_reason", err.Error()),
|
||||
)
|
||||
// 完整的请求地址
|
||||
fullURL, body = r.getFullURLAndBody(serviceConfig, apiConfig, parameter)
|
||||
|
||||
logDataList = append(logDataList, zap.String("full_utl", fullURL))
|
||||
fullHeader := make(map[string]string)
|
||||
for k, v := range apiConfig.Header {
|
||||
fullHeader[k] = v
|
||||
}
|
||||
for k, v := range header {
|
||||
fullHeader[k] = v
|
||||
}
|
||||
// 获取客户端
|
||||
client = r.GetHttpClient(fullHeader, apiConfig.Timeout)
|
||||
var bodyReader io.Reader
|
||||
if nil != body {
|
||||
logDataList = append(logDataList, zap.String("request_body", string(body)))
|
||||
bodyReader = bytes.NewReader(body)
|
||||
}
|
||||
|
||||
requestStartTime := time.Now().UnixNano() / 1e6
|
||||
requestFinishTime := int64(0)
|
||||
|
||||
logDataList = append(logDataList, zap.Int64("start_time", requestStartTime))
|
||||
if response, err = client.Do(apiConfig.Method, fullURL, apiConfig.Header, bodyReader); nil != err {
|
||||
requestFinishTime = time.Now().UnixNano() / 1e6
|
||||
logDataList = append(logDataList, zap.Int64("finish_time", requestFinishTime))
|
||||
logDataList = append(logDataList, zap.Int64("used_time", requestFinishTime-requestStartTime))
|
||||
logDataList = append(logDataList, zap.String("request_fail_reason", err.Error()))
|
||||
return err
|
||||
}
|
||||
|
||||
requestFinishTime = time.Now().UnixNano() / 1e6
|
||||
logDataList = append(logDataList, zap.Int64("finish_time", requestFinishTime))
|
||||
logDataList = append(logDataList, zap.Int64("used_time", requestFinishTime-requestStartTime))
|
||||
logDataList = append(logDataList, zap.Any("response_header", response.Header))
|
||||
logDataList = append(logDataList, zap.Any("response_http_code", response.StatusCode))
|
||||
|
||||
if responseBody, err = r.getResponseBody(response); nil != err {
|
||||
logDataList = append(logDataList, zap.String("read_body_fail_reason", err.Error()))
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
logDataList = append(logDataList, zap.Any("response_body", string(responseBody)))
|
||||
|
||||
responseFieldCfg := r.getCodeAndMessageAndDataField(serviceConfig, apiConfig)
|
||||
successHttpCodeList, successBusinessCodeList := r.getSuccessHttpCodeAndSuccessBusinessCode(serviceConfig, apiConfig)
|
||||
if !r.httpCodeIsSuccess(response.StatusCode, successHttpCodeList) {
|
||||
return fmt.Errorf("HTTP状态码异常 : %v -> %v", response.StatusCode, response.Status)
|
||||
}
|
||||
|
||||
// 解析响应的业务数据
|
||||
code, message, data = r.getCodeAndMessageAndData(responseBody, responseFieldCfg)
|
||||
if !r.codeIsSuccess(code, successBusinessCodeList) {
|
||||
return fmt.Errorf("业务状态码异常 : %v -> %v", code, message)
|
||||
}
|
||||
|
||||
if nil == receiver {
|
||||
// 数据接收指针为 nil , 则认为状态码为成功既是成功
|
||||
return nil
|
||||
}
|
||||
if err = parseResponseBody(response.Header.Get("Content-Type"), []byte(data), receiver); nil != err {
|
||||
logDataList = append(logDataList, zap.Any("response_body_parse_fail_reason", err.Error()))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// getMockData 获取mock数据
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 14:29 2022/10/14
|
||||
func (r *request) getMockData(serviceConfig *Service, apiConfig *Api) ([]byte, string, error) {
|
||||
mockFilePath := util.Project.BuildPath(serviceConfig.MockPath, serviceConfig.Flag, apiConfig.Flag+".json")
|
||||
if !serviceConfig.MockEnable || !apiConfig.MockEnable {
|
||||
// 未启用mock服务
|
||||
return nil, mockFilePath, errors.New("mock is forbidden")
|
||||
}
|
||||
var (
|
||||
err error
|
||||
mockData []byte
|
||||
)
|
||||
if _, err = os.Stat(mockFilePath); nil != err {
|
||||
return nil, mockFilePath, errors.New("get mock fileInfo fail : " + err.Error())
|
||||
}
|
||||
if mockData, err = ioutil.ReadFile(mockFilePath); nil != err {
|
||||
return nil, mockFilePath, errors.New("read mock file content fail :" + err.Error())
|
||||
}
|
||||
return mockData, mockFilePath, nil
|
||||
}
|
||||
|
||||
// getResponseBody 获取响应体
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 3:10 2022/10/4
|
||||
func (r *request) getResponseBody(response *httpclient.Response) ([]byte, error) {
|
||||
var (
|
||||
responseBody []byte
|
||||
err error
|
||||
gzipInstance *gzip.Reader
|
||||
buf bytes.Buffer
|
||||
)
|
||||
if responseBody, err = io.ReadAll(response.Body); nil != err {
|
||||
return nil, err
|
||||
}
|
||||
// 判断返回值是否经过gzip压缩
|
||||
responseGzip := response.Header.Get("content-encoding")
|
||||
if strings.ToLower(responseGzip) == "gzip" {
|
||||
// 压缩过的数据,在处理response body
|
||||
if gzipInstance, err = gzip.NewReader(bytes.NewReader(responseBody)); nil != err {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
_ = gzipInstance.Close()
|
||||
}()
|
||||
if _, err = io.Copy(&buf, gzipInstance); nil != err {
|
||||
return nil, err
|
||||
}
|
||||
responseBody = buf.Bytes()
|
||||
}
|
||||
// 判断是否为gbk编码,若是,转为utf8
|
||||
isGBK := strings.Contains(strings.ToLower(response.Header.Get("content-type")), "gbk")
|
||||
if isGBK {
|
||||
return []byte(util.String.Convert(string(responseBody), "gbk", "utf-8")), nil
|
||||
}
|
||||
// 判断是否为gb2312,若是,转为utf8
|
||||
isGB2312 := strings.Contains(strings.ToLower(response.Header.Get("content-type")), "gb2312")
|
||||
if isGB2312 {
|
||||
return []byte(util.String.Convert(string(responseBody), "gb2312", "utf-8")), nil
|
||||
}
|
||||
return responseBody, nil
|
||||
}
|
||||
|
||||
// GetHttpClient 获取client实例
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:00 2022/6/30
|
||||
func (r *request) GetHttpClient(header map[string]string, timeout ApiTimeout) *httpclient.HttpClient {
|
||||
client := httpclient.NewHttpClient()
|
||||
if timeout.Connect <= 0 {
|
||||
timeout.Connect = DefaultConnectTimeout
|
||||
}
|
||||
|
||||
if timeout.Read <= 0 {
|
||||
timeout.Read = DefaultReadTimeout
|
||||
}
|
||||
client.WithHeaders(header)
|
||||
client.WithOption(httpclient.OPT_CONNECTTIMEOUT_MS, timeout.Connect)
|
||||
client.WithOption(httpclient.OPT_TIMEOUT_MS, timeout.Read)
|
||||
return client
|
||||
}
|
||||
|
||||
// getFullURL ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:23 2022/6/30
|
||||
func (r *request) getFullURLAndBody(serviceConfig *Service, apiConfig *Api, parameter map[string]interface{}) (string, []byte) {
|
||||
fullURL := strings.TrimRight(serviceConfig.Domain, "/") + "/" + strings.TrimLeft(apiConfig.URI, "/")
|
||||
for name, val := range parameter {
|
||||
paramTpl := "{{" + name + "}}"
|
||||
if !strings.Contains(fullURL, paramTpl) {
|
||||
continue
|
||||
}
|
||||
fullURL = strings.ReplaceAll(fullURL, paramTpl, fmt.Sprintf("%v", val))
|
||||
// 替换到URL的参数, 从body删除
|
||||
delete(parameter, name)
|
||||
}
|
||||
parameterPair := make([]string, 0)
|
||||
var body []byte
|
||||
switch strings.ToUpper(apiConfig.Method) {
|
||||
case http.MethodGet:
|
||||
fallthrough
|
||||
case http.MethodHead:
|
||||
fallthrough
|
||||
case http.MethodOptions:
|
||||
fallthrough
|
||||
case http.MethodConnect:
|
||||
fallthrough
|
||||
case http.MethodPatch:
|
||||
fallthrough
|
||||
case http.MethodTrace:
|
||||
for name, val := range parameter {
|
||||
var valStr string
|
||||
_ = util.ConvertAssign(&valStr, val)
|
||||
parameterPair = append(parameterPair, fmt.Sprintf("%v=%v", name, valStr))
|
||||
}
|
||||
case http.MethodPost:
|
||||
fallthrough
|
||||
case http.MethodPut:
|
||||
fallthrough
|
||||
case http.MethodDelete:
|
||||
body, _ = json.Marshal(parameter)
|
||||
}
|
||||
query := strings.Join(parameterPair, "&")
|
||||
if len(query) == 0 {
|
||||
return fullURL, body
|
||||
}
|
||||
return fullURL + "?" + query, body
|
||||
}
|
||||
|
||||
// validateResponseHttpCode 验证http状态码
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:18 2022/6/30
|
||||
func (r *request) validateResponseHttpCode(apiConfig *Api, response *httpclient.Response) error {
|
||||
// 判断状态码
|
||||
isHttpSuccess := false
|
||||
for _, successCode := range apiConfig.SuccessHttpCodeList {
|
||||
if successCode == response.StatusCode {
|
||||
isHttpSuccess = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !isHttpSuccess {
|
||||
return fmt.Errorf("http响应状态码异常 -> %v", response.StatusCode)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// getCodeAndMessageAndData 读取业务状态码 + 文案 + 数据
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:20 2022/6/30
|
||||
func (r *request) getCodeAndMessageAndData(responseBody []byte, responseFieldCfg responseDaFieldConfig) (string, string, string) {
|
||||
var (
|
||||
code = SpecialFiledVal
|
||||
message = SpecialFiledVal
|
||||
data string
|
||||
)
|
||||
if responseFieldCfg.Code != SpecialFiledVal {
|
||||
code = gjson.Get(string(responseBody), responseFieldCfg.Code).String()
|
||||
}
|
||||
if responseFieldCfg.Message != SpecialFiledVal {
|
||||
message = gjson.Get(string(responseBody), responseFieldCfg.Message).String()
|
||||
}
|
||||
if responseFieldCfg.Data == SpecialFiledVal {
|
||||
data = string(responseBody)
|
||||
} else {
|
||||
data = gjson.Get(string(responseBody), responseFieldCfg.Data).String()
|
||||
}
|
||||
return code, message, data
|
||||
}
|
||||
|
||||
// codeIsSuccess 判断业务状态码是否为成功
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:27 2022/6/30
|
||||
func (r *request) codeIsSuccess(input string, successCodeList []string) bool {
|
||||
if input == SpecialFiledVal {
|
||||
// 不需要验证状态码,直接返回成功
|
||||
return true
|
||||
}
|
||||
for _, item := range successCodeList {
|
||||
if item == input {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// httpCodeIsSuccess http状态码是否为成功
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:31 2022/6/30
|
||||
func (r *request) httpCodeIsSuccess(input int, successCodeList []int) bool {
|
||||
for _, item := range successCodeList {
|
||||
if item == input {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// getSuccessHttpCodeAndSuccessBusinessCode 获取成功的http 和 业务状态码列表
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 16:48 2022/7/1
|
||||
func (r *request) getSuccessHttpCodeAndSuccessBusinessCode(serviceInfo *Service, apiInfo *Api) ([]int, []string) {
|
||||
var (
|
||||
successHttpCodeList = apiInfo.SuccessHttpCodeList
|
||||
successBusinessCodeList = apiInfo.SuccessCodeList
|
||||
)
|
||||
|
||||
if len(apiInfo.SuccessHttpCodeList) == 0 {
|
||||
successHttpCodeList = serviceInfo.SuccessHttpCodeList
|
||||
}
|
||||
|
||||
if len(apiInfo.SuccessHttpCodeList) == 0 {
|
||||
successBusinessCodeList = serviceInfo.SuccessCodeList
|
||||
}
|
||||
|
||||
if len(successHttpCodeList) == 0 {
|
||||
successHttpCodeList = []int{http.StatusOK}
|
||||
}
|
||||
|
||||
if len(successBusinessCodeList) == 0 {
|
||||
successBusinessCodeList = []string{"0"}
|
||||
}
|
||||
return successHttpCodeList, successBusinessCodeList
|
||||
}
|
||||
|
||||
// getCodeAndMessageAndDataField 获取三个字段信息
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 16:54 2022/7/1
|
||||
func (r *request) getCodeAndMessageAndDataField(serviceInfo *Service, apiInfo *Api) responseDaFieldConfig {
|
||||
cfg := responseDaFieldConfig{
|
||||
Code: apiInfo.CodeField,
|
||||
Message: apiInfo.MessageField,
|
||||
Data: apiInfo.DataField,
|
||||
}
|
||||
if len(cfg.Code) == 0 {
|
||||
cfg.Code = serviceInfo.CodeField
|
||||
}
|
||||
|
||||
if len(cfg.Message) == 0 {
|
||||
cfg.Message = serviceInfo.MessageField
|
||||
}
|
||||
|
||||
if len(cfg.Data) == 0 {
|
||||
cfg.Data = serviceInfo.DataField
|
||||
}
|
||||
|
||||
return cfg
|
||||
}
|
||||
|
||||
// loggerRequest 记录请求日志
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:54 2022/7/1
|
||||
func (r *request) loggerRequest(ctx *gin.Context, dataList ...zap.Field) {
|
||||
if nil == r.logger {
|
||||
// 未设置日志实例
|
||||
return
|
||||
}
|
||||
r.logger.Info("API接口请求日志记录", dataList...)
|
||||
}
|
||||
|
51
rpc_test.go
Normal file
51
rpc_test.go
Normal file
@ -0,0 +1,51 @@
|
||||
// Package rpc ...
|
||||
//
|
||||
// Description : rpc ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2022-07-01 16:00
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestInitRPC(t *testing.T) {
|
||||
/*proxyServiceInfo := &Service{
|
||||
Flag: "goproxy",
|
||||
Domain: "https://goproxy.cn/",
|
||||
CodeField: "-",
|
||||
MessageField: "-",
|
||||
DataField: "-",
|
||||
SuccessCodeList: []string{},
|
||||
SuccessHttpCodeList: []int{http.StatusOK},
|
||||
ApiTable: map[string]*Api{
|
||||
"package_info": {
|
||||
Flag: "package_info",
|
||||
URI: "/stats/{{package_name}}",
|
||||
Method: http.MethodGet,
|
||||
BindURIParamList: []string{"package_name"},
|
||||
Timeout: ApiTimeout{
|
||||
Connect: 5000,
|
||||
Read: 5000,
|
||||
},
|
||||
},
|
||||
},
|
||||
ApiRetry: ApiRetry{},
|
||||
}*/
|
||||
if err := InitRPCFromCfgDir("/Users/zhangdeman/project/go-project/rpc/etc", nil); nil != err {
|
||||
panic(err.Error())
|
||||
}
|
||||
var result map[string]interface{}
|
||||
if err := Request.Send(nil, "goproxy", "package_info", map[string]interface{}{
|
||||
"package_name": "golang.org/x/text",
|
||||
}, &result); nil != err {
|
||||
fmt.Println("请求出现异常 : " + err.Error())
|
||||
return
|
||||
}
|
||||
byteData, _ := json.Marshal(result)
|
||||
fmt.Println(string(byteData))
|
||||
}
|
Reference in New Issue
Block a user