Implemented a simplified message framework#1
Conversation
99afe05 to
d3e3924
Compare
|
The best way to review this:
Taking this approach, you don't actually need to review all 2,000 lines since a lot of it consists of message definitions. |
|
99% of this would be written to verify messages at compile-time if this were C++, but Go doesn't believe in compile-time behavior except for allowing certain files on certain platforms 😭 |
zachmu
left a comment
There was a problem hiding this comment.
Overall this looks pretty clean, comments are pretty minor.
The init() blocks are nasty. Are they strictly necessary?
| } | ||
|
|
||
| // Send sends the given message over the connection. | ||
| func Send(conn net.Conn, message MessageType) error { |
There was a problem hiding this comment.
This seems misplaced. Probably better to have Encode(message) []byte and keep the writing / connection logic out of this package
There was a problem hiding this comment.
I was thinking of making a connection package, so I might just do that instead. Also having the message definitions in there. Since PostgreSQL seems to strictly communicate in messages, there's no reason for the listener to deal with byte slices when it'll just be sending and receiving the messages, so I want the interface to handle that. This also means that any other edge cases, like dynamically making multiple requests as the byte buffer isn't big enough, is hidden behind the call.
|
Merging the feedback from this PR into #2, so closing this one. |
This makes it so that declaring PostgreSQL messages is almost as straightforward as copying them from the document into Go, as the framework takes care of transforming the data into the format that PostgreSQL expects. This will significantly speed up adding new messages, while adding a layer of validation to ensure that some mistakes aren't possible.