package utils import ( "io/ioutil" "nCovTrack-Backend/global" "net/http" "time" ) var () func GetWhioutHeader(url string) string { return GetWithHeader(url, nil) } func GetWithHeader(url string, header map[string]string) string { client, err := global.GetHttpClient("") if err != nil { var logParams []interface{} logParams = append(logParams, "err", err) InitLogError("httpClient", logParams) panic(err) } req, _ := http.NewRequest(http.MethodGet, url, nil) for k, v := range header { req.Header.Add(k, v) } startTime := time.Now() res, err := client.Do(req) cost := time.Since(startTime) var logParams []interface{} logParams = append(logParams, "reqest", req, "cost", cost.String(), ) if err != nil { logParams = append(logParams, "errors", err) UtilLogError("requestUtil", logParams...) panic(err) } if cost.Seconds() > 1 { logParams = append(logParams, "response", res) UtilLogWarn("requestUtil", logParams...) } UtilLogInfo("requestUtil", logParams...) bodyBytes, _ := ioutil.ReadAll(res.Body) defer res.Body.Close() return string(bodyBytes) }