- refactor http.Get

This commit is contained in:
gazebo
2019-04-26 17:46:18 +08:00
parent 7e0dcbc8ec
commit d6ec47ed6c
2 changed files with 12 additions and 8 deletions

View File

@@ -270,9 +270,7 @@ func (s SkuList) Swap(i, j int) {
func DownloadFileByURL(fileURL string) (bodyData []byte, fileMD5 string, err error) {
response, err := http.Get(fileURL)
if err == nil {
defer func() {
response.Body.Close()
}()
defer response.Body.Close()
if response.StatusCode == http.StatusOK {
if bodyData, err = ioutil.ReadAll(response.Body); err == nil {
fileMD5 = fmt.Sprintf("%X", md5.Sum(bodyData))