|
@@ -106,3 +106,34 @@ func PostWithHeader(reqUrl string, payload string, headers map[string]string, ti
|
|
|
|
|
|
return b, nil
|
|
return b, nil
|
|
}
|
|
}
|
|
|
|
+func GetWithHeader(reqUrl string, headers map[string]string, timeout time.Duration) ([]byte, error) {
|
|
|
|
+ req, err := http.NewRequest(http.MethodGet, reqUrl, nil)
|
|
|
|
+ if err != nil {
|
|
|
|
+ logrus.Error(err)
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for key, val := range headers {
|
|
|
|
+ req.Header.Set(key, val)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ cli := http.Client{
|
|
|
|
+ Timeout: timeout,
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ resp, err := cli.Do(req)
|
|
|
|
+ if err != nil {
|
|
|
|
+ logrus.Error(err)
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ defer resp.Body.Close()
|
|
|
|
+
|
|
|
|
+ b, err := io.ReadAll(resp.Body)
|
|
|
|
+ if err != nil {
|
|
|
|
+ logrus.Error(err)
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return b, nil
|
|
|
|
+}
|