-
Notifications
You must be signed in to change notification settings - Fork 22
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
Add mock server outline and test #19
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PTAL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small comments with one more major suggestion for TODO/future refactoring
} | ||
writeProtocolMessage(rw.Writer, response) | ||
log.Printf("Response sent\n\t%#v\n", response) | ||
rw.Flush() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking for this line :)
In general, I don't see a reason to buffer the writer here. The code seems to be using bufio.ReadWriter
only to bunch together the reader and the writer, but the writer doesn't have to be buffered.
The code can go in as is for now, but please add a TODO/issue to refactor this. I would suggest making server a type with methods, and the writer and bufio.Reader to be struct fields in the type. The methods can then simply access them.
Then you also wouldn't have to pass these readers/writers around to handlers, dispatchers, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #21
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PTAL
@@ -105,3 +106,21 @@ func readContentLengthHeader(r *bufio.Reader) (contentLength int, err error) { | |||
} | |||
return strconv.Atoi(headerAndLength[1]) | |||
} | |||
|
|||
// WriteProtocolMessage encodes message and writes it to w. | |||
func WriteProtocolMessage(w io.Writer, message Message) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: now that these higher level functions are in io.go, add an issue to consider making the other functions unexported. It's unlikely that we'll want clients to use them directly, and for tests it doesn't matter (because they're in the same package). It's always possible to export a new function w/o breaking the API, whereas the reverse is not possible. So "hidden by default" is safer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #22
No description provided.