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

No need for readFully function and 2 packages imported for it. #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 18 additions & 18 deletions Ch04/JSONEchoClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
package main

import (
"bytes"
// "bytes"
"encoding/json"
"fmt"
"io"
// "io"
"net"
"os"
)
Expand Down Expand Up @@ -69,20 +69,20 @@ func checkError(err error) {
}
}

func readFully(conn net.Conn) ([]byte, error) {
defer conn.Close()
// func readFully(conn net.Conn) ([]byte, error) {
// defer conn.Close()

result := bytes.NewBuffer(nil)
var buf [512]byte
for {
n, err := conn.Read(buf[0:])
result.Write(buf[0:n])
if err != nil {
if err == io.EOF {
break
}
return nil, err
}
}
return result.Bytes(), nil
}
// result := bytes.NewBuffer(nil)
// var buf [512]byte
// for {
// n, err := conn.Read(buf[0:])
// result.Write(buf[0:n])
// if err != nil {
// if err == io.EOF {
// break
// }
// return nil, err
// }
// }
// return result.Bytes(), nil
// }