Use message names matching PostgreSQL docs

pgx-vs-pq
Jack Christensen 2013-03-30 17:13:35 -05:00
parent 9c12da11f7
commit 6fb92c12b8
2 changed files with 12 additions and 9 deletions

View File

@ -1,26 +1,29 @@
package pqx package pqx
import ( import (
// "encoding/binary" "encoding/binary"
"net" "net"
"testing" "testing"
) )
func TestXxx(t *testing.T) { 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 { if err != nil {
// handle error // handle error
} }
msg := newStartupMsg() msg := newStartupMessage()
msg.options["user"] = "jack" msg.options["user"] = "jack"
msg.WriteTo(conn) msg.WriteTo(conn)
buf := make([]byte, 128) buf := make([]byte, 512)
num, _ := conn.Read(buf) num, _ := conn.Read(buf)
println(string(buf[0:1])) println(string(buf[0:1]))
println(binary.BigEndian.Uint32(buf[1:5]))
println(binary.BigEndian.Uint32(buf[5:9]))
println(num) println(num)
} }

View File

@ -9,15 +9,15 @@ const (
protocolVersionNumber = 196608 // 3.0 protocolVersionNumber = 196608 // 3.0
) )
type startupMsg struct { type startupMessage struct {
options map[string] string options map[string] string
} }
func newStartupMsg() *startupMsg { func newStartupMessage() *startupMessage {
return &startupMsg{map[string] string{}} 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) buf := make([]byte, 8, 128)
binary.BigEndian.PutUint32(buf[4:8], uint32(protocolVersionNumber)) binary.BigEndian.PutUint32(buf[4:8], uint32(protocolVersionNumber))
for key, value := range self.options { for key, value := range self.options {