From 2ea23e2364f742f528fb8b97657212c174d1bbd7 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期六, 21 十月 2023 14:06:59 +0800
Subject: [PATCH] 增加切换serf状态接口(调试用)
---
pkg/httpx/httpx.go | 17 +++++++++++++++--
1 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/pkg/httpx/httpx.go b/pkg/httpx/httpx.go
index 4e286fe..c909811 100644
--- a/pkg/httpx/httpx.go
+++ b/pkg/httpx/httpx.go
@@ -3,7 +3,8 @@
import (
"bytes"
"encoding/json"
- "io/ioutil"
+ "errors"
+ "io"
"net/http"
"time"
)
@@ -33,9 +34,21 @@
}
defer resp.Body.Close()
- respBytes, err := ioutil.ReadAll(resp.Body)
+ respBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return respBytes, nil
}
+
+func SendPostAndParseJson(url string, post, response interface{}) (err error) {
+ if response == nil {
+ return errors.New("response is not set")
+ }
+
+ respBytes, err := SendPost(http.Header{}, url, post)
+ if err != nil {
+ return err
+ }
+ return json.Unmarshal(respBytes, &response)
+}
--
Gitblit v1.8.0