mirror of https://github.com/jackc/pgx.git
Parse ParameterStatus
parent
226142ae1b
commit
aefc85a67b
29
conn.go
29
conn.go
|
@ -1,6 +1,8 @@
|
||||||
package pqx
|
package pqx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -39,6 +41,16 @@ func Connect(options map[string]string) (c *conn, err error) {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
fmt.Println(response)
|
fmt.Println(response)
|
||||||
|
|
||||||
|
for {
|
||||||
|
response, err = c.rxMsg()
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
fmt.Println(response)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(err)
|
||||||
|
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,8 +70,10 @@ func (c *conn) rxMsg() (msg interface{}, err error) {
|
||||||
switch t {
|
switch t {
|
||||||
case 'R':
|
case 'R':
|
||||||
return c.rxAuthenticationX(buf)
|
return c.rxAuthenticationX(buf)
|
||||||
|
case 'S':
|
||||||
|
return c.rxParameterStatus(buf)
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("Received unknown message type")
|
return nil, fmt.Errorf("Received unknown message type: %c", t)
|
||||||
}
|
}
|
||||||
|
|
||||||
panic("Unreachable")
|
panic("Unreachable")
|
||||||
|
@ -98,3 +112,16 @@ func (c *conn) rxAuthenticationX(buf []byte) (msg interface{}, err error) {
|
||||||
|
|
||||||
panic("Unreachable")
|
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
|
||||||
|
}
|
||||||
|
|
10
messages.go
10
messages.go
|
@ -2,6 +2,7 @@ package pqx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -36,3 +37,12 @@ type authenticationOk struct {
|
||||||
func (self *authenticationOk) String() string {
|
func (self *authenticationOk) String() string {
|
||||||
return "AuthenticationOk"
|
return "AuthenticationOk"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type parameterStatus struct {
|
||||||
|
name string
|
||||||
|
value string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *parameterStatus) String() string {
|
||||||
|
return fmt.Sprintf("ParameterStatus %s: %s", self.name, self.value)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue