diff --git a/conn.go b/conn.go index f3716451..6ff0ef8b 100644 --- a/conn.go +++ b/conn.go @@ -1,6 +1,8 @@ package pqx import ( + "bufio" + "bytes" "encoding/binary" "errors" "fmt" @@ -39,6 +41,16 @@ func Connect(options map[string]string) (c *conn, err error) { fmt.Println(err) fmt.Println(response) + for { + response, err = c.rxMsg() + if err != nil { + break + } + fmt.Println(response) + } + + fmt.Println(err) + return c, nil } @@ -58,8 +70,10 @@ func (c *conn) rxMsg() (msg interface{}, err error) { switch t { case 'R': return c.rxAuthenticationX(buf) + case 'S': + return c.rxParameterStatus(buf) default: - return nil, errors.New("Received unknown message type") + return nil, fmt.Errorf("Received unknown message type: %c", t) } panic("Unreachable") @@ -98,3 +112,16 @@ func (c *conn) rxAuthenticationX(buf []byte) (msg interface{}, err error) { panic("Unreachable") } + +func (c *conn) rxParameterStatus(buf []byte) (msg *parameterStatus, err error) { + msg = new(parameterStatus) + + r := bufio.NewReader(bytes.NewReader(buf)) + msg.name, err = r.ReadString(0) + if err != nil { + return + } + + msg.value, err = r.ReadString(0) + return +} diff --git a/messages.go b/messages.go index 0ecb9bed..b5428742 100644 --- a/messages.go +++ b/messages.go @@ -2,6 +2,7 @@ package pqx import ( "encoding/binary" + "fmt" ) const ( @@ -36,3 +37,12 @@ type authenticationOk struct { func (self *authenticationOk) String() string { return "AuthenticationOk" } + +type parameterStatus struct { + name string + value string +} + +func (self *parameterStatus) String() string { + return fmt.Sprintf("ParameterStatus %s: %s", self.name, self.value) +}