From 6fb92c12b8546c9446f79aa20ad4dc3af949496b Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 30 Mar 2013 17:13:35 -0500 Subject: [PATCH] Use message names matching PostgreSQL docs --- conn_test.go | 11 +++++++---- messages.go | 10 +++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/conn_test.go b/conn_test.go index c90f0bd3..164fbc17 100644 --- a/conn_test.go +++ b/conn_test.go @@ -1,26 +1,29 @@ package pqx import ( - // "encoding/binary" + "encoding/binary" "net" "testing" ) func TestXxx(t *testing.T) { - conn, err := net.Dial("tcp", "localhost:5432") + conn, err := net.Dial("unix", "/private/tmp/.s.PGSQL.5432") + // conn, err := net.Dial("tcp", "localhost:5432") if err != nil { // handle error } - msg := newStartupMsg() + msg := newStartupMessage() msg.options["user"] = "jack" msg.WriteTo(conn) - buf := make([]byte, 128) + buf := make([]byte, 512) num, _ := conn.Read(buf) println(string(buf[0:1])) + println(binary.BigEndian.Uint32(buf[1:5])) + println(binary.BigEndian.Uint32(buf[5:9])) println(num) } diff --git a/messages.go b/messages.go index ececc772..840dcc93 100644 --- a/messages.go +++ b/messages.go @@ -9,15 +9,15 @@ const ( protocolVersionNumber = 196608 // 3.0 ) -type startupMsg struct { +type startupMessage struct { options map[string] string } -func newStartupMsg() *startupMsg { - return &startupMsg{map[string] string{}} +func newStartupMessage() *startupMessage { + return &startupMessage{map[string] string{}} } -func (self *startupMsg) WriteTo(w io.Writer) (n int64, err error) { +func (self *startupMessage) WriteTo(w io.Writer) (n int64, err error) { buf := make([]byte, 8, 128) binary.BigEndian.PutUint32(buf[4:8], uint32(protocolVersionNumber)) for key, value := range self.options { @@ -32,4 +32,4 @@ func (self *startupMsg) WriteTo(w io.Writer) (n int64, err error) { var n32 int n32, err = w.Write(buf) return int64(n32), err -} \ No newline at end of file +}