|
@ -1,7 +1,6 @@ |
|
|
package util |
|
|
package util |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"bytes" |
|
|
|
|
|
"compress/gzip" |
|
|
"compress/gzip" |
|
|
"encoding/json" |
|
|
"encoding/json" |
|
|
"errors" |
|
|
"errors" |
|
@ -29,22 +28,6 @@ func init() { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func PostBytes(url string, body []byte) ([]byte, error) { |
|
|
|
|
|
r, err := client.Post(url, "", bytes.NewReader(body)) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, fmt.Errorf("Post to %s: %v", url, err) |
|
|
|
|
|
} |
|
|
|
|
|
defer r.Body.Close() |
|
|
|
|
|
b, err := ioutil.ReadAll(r.Body) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, fmt.Errorf("Read response body: %v", err) |
|
|
|
|
|
} |
|
|
|
|
|
if r.StatusCode >= 400 { |
|
|
|
|
|
return nil, fmt.Errorf("%s: %s", url, r.Status) |
|
|
|
|
|
} |
|
|
|
|
|
return b, nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func Post(url string, values url.Values) ([]byte, error) { |
|
|
func Post(url string, values url.Values) ([]byte, error) { |
|
|
r, err := client.PostForm(url, values) |
|
|
r, err := client.PostForm(url, values) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|