package ipc import ( "bytes" "io/ioutil" "net/http" "time" "basic.com/valib/logger.git" ) func HttpGet(url string, parama []byte) (body []byte, err error) { return request("GET", url, parama) } func HttpPost(url string, parama []byte) (body []byte, err error) { return request("POST", url, parama) } func request(method string, url string, parama []byte) (body []byte, err error) { timeout := time.Duration(10 * time.Second) client := http.Client{ Timeout: timeout, } request, err := http.NewRequest(method, url, bytes.NewBuffer(parama)) request.Header.Set("Content-type", "application/json") if err != nil { logger.Warn("build request fail !") return nil, err } resp, err := client.Do(request) if err != nil { logger.Warn("request error: ", err) return nil, err } defer resp.Body.Close() body, err = ioutil.ReadAll(resp.Body) if err != nil { logger.Warn(err) } return body, nil }