zhangqian
2023-08-15 f5461743f6542e6b4a793117e05777769f9c3377
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)
}