From 09e47648bcdd68c967b8ef6fe6619a2d95a54da5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Fri, 1 Jul 2022 17:19:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rpc_test.go | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 rpc_test.go diff --git a/rpc_test.go b/rpc_test.go new file mode 100644 index 0000000..8c4dc02 --- /dev/null +++ b/rpc_test.go @@ -0,0 +1,54 @@ +// Package rpc ... +// +// Description : rpc ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2022-07-01 16:00 +package rpc + +import ( + "encoding/json" + "fmt" + "net/http" + "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 := InitRPC(map[string]*Service{ + "goproxy": proxyServiceInfo, + }, 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)) +}