enhance: memory handling

This commit is contained in:
minoplhy 2024-04-14 02:59:55 +07:00
parent f269bfaa9c
commit 22c23cc2ee
Signed by: minoplhy
GPG Key ID: 41D406044E2434BF
3 changed files with 13 additions and 10 deletions

View File

@ -77,7 +77,6 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
tempfilepath := handler.GetTempFilename(fileHeader.Filename)
handler.InfoLogBuilder([]string{r.RemoteAddr, tempfilepath}, "Successfully obtained temporary Filename")
handler.SaveFile(tempfilepath, file)
handler.DiscardFile(file)
PostData := handler.UploadPostMeta{
ContentType: fileHeader.Header.Get("Content-Type"),
@ -152,7 +151,6 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
http.Error(w, handler.ErrorResponseBuild(http.StatusInternalServerError, "Something went wrong!"), http.StatusInternalServerError)
handler.ErrorLogBuilder([]string{}, err.Error())
return
}
handler.InfoLogBuilder([]string{r.RemoteAddr, PostProcessResponse.Name, tempfilepath}, fmt.Sprintf("Successfully Processed Response with UUID: %s", PostProcessResponse.UUID))

View File

@ -53,11 +53,13 @@ func UploadPost(BasePath string, headers map[string]string, PostData UploadPostM
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
BodyRead, err := io.ReadAll(resp.Body)
buffer := bytes.NewBuffer(nil)
_, err := io.Copy(buffer, resp.Body)
defer resp.Body.Close()
if err != nil {
return nil, err
}
return BodyRead, nil
return buffer.Bytes(), nil
} else {
return nil, err
}
@ -96,14 +98,15 @@ func NetworkStoragePut(URL string, ContentType string, filepath string) ([]byte,
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
BodyRead, err := io.ReadAll(resp.Body)
buffer := bytes.NewBuffer(nil)
_, err := io.Copy(buffer, resp.Body)
defer resp.Body.Close()
if err != nil {
return nil, err
}
return BodyRead, nil
return buffer.Bytes(), nil
} else {
return nil, err
}
@ -129,11 +132,13 @@ func UploadProcessPost(BasePath string, headers map[string]string, PostData Uplo
}
if resp.StatusCode == http.StatusOK {
BodyRead, err := io.ReadAll(resp.Body)
buffer := bytes.NewBuffer(nil)
_, err := io.Copy(buffer, resp.Body)
defer resp.Body.Close()
if err != nil {
return nil, err
}
return BodyRead, nil
return buffer.Bytes(), nil
} else {
return nil, err
}

View File

@ -75,5 +75,5 @@ func HTTPClientDo(Request *http.Request) (*http.Response, error) {
if err != nil {
return nil, err
}
return response, err
return response, nil
}