Open odeke-em opened 1 year ago
If we look at this code https://github.com/danielgross/whatsapp-gpt/blob/d12693276e1e88d5d335276aa42bcfd849d56023/main.go#L52-L57
there is unnecessary process with the bytes.Buffer.ReadFrom then buf.String() then string(newMsg) but really it can be trivially done with
newMsg, err := io.ReadAll(resp.Body) if err != nil { ... return } response := &waProto.Message{Conversation: proto.String(string(newMsg))}
and even more, resp.Body is never closed. We need a defer resp.Body.Close() or resp.Body.Close() right after the read.
If we look at this code https://github.com/danielgross/whatsapp-gpt/blob/d12693276e1e88d5d335276aa42bcfd849d56023/main.go#L52-L57
there is unnecessary process with the bytes.Buffer.ReadFrom then buf.String() then string(newMsg) but really it can be trivially done with
and even more, resp.Body is never closed. We need a defer resp.Body.Close() or resp.Body.Close() right after the read.