package utils

import (
	"fmt"
	"io/ioutil"
	"net/http"
)

func HttpGet(url string, params map[string]string) (result []byte, err error) {
	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	q := req.URL.Query()
	for k, v := range params {
		q.Add(k, v)
	}
	req.URL.RawQuery = q.Encode()
	fmt.Println(req.URL.String())
	var resp *http.Response

	resp, err = http.DefaultClient.Do(req)
	if err != nil || resp == nil {
		return
	}
	output, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return
	}
	result = output
	defer func() {
		if resp != nil {
			resp.Body.Close()
		}
	}()
	return
}
