Use pgproto3 for startup message
This commit is contained in:
@@ -302,27 +302,30 @@ func (c *Conn) connect(config ConnConfig, network, address string, tlsConfig *tl
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := newStartupMessage()
|
startupMsg := pgproto3.StartupMessage{
|
||||||
|
ProtocolVersion: pgproto3.ProtocolVersionNumber,
|
||||||
|
Parameters: make(map[string]string),
|
||||||
|
}
|
||||||
|
|
||||||
// Default to disabling TLS renegotiation.
|
// Default to disabling TLS renegotiation.
|
||||||
//
|
//
|
||||||
// Go does not support (https://github.com/golang/go/issues/5742)
|
// Go does not support (https://github.com/golang/go/issues/5742)
|
||||||
// PostgreSQL recommends disabling (http://www.postgresql.org/docs/9.4/static/runtime-config-connection.html#GUC-SSL-RENEGOTIATION-LIMIT)
|
// PostgreSQL recommends disabling (http://www.postgresql.org/docs/9.4/static/runtime-config-connection.html#GUC-SSL-RENEGOTIATION-LIMIT)
|
||||||
if tlsConfig != nil {
|
if tlsConfig != nil {
|
||||||
msg.options["ssl_renegotiation_limit"] = "0"
|
startupMsg.Parameters["ssl_renegotiation_limit"] = "0"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy default run-time params
|
// Copy default run-time params
|
||||||
for k, v := range config.RuntimeParams {
|
for k, v := range config.RuntimeParams {
|
||||||
msg.options[k] = v
|
startupMsg.Parameters[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.options["user"] = c.config.User
|
startupMsg.Parameters["user"] = c.config.User
|
||||||
if c.config.Database != "" {
|
if c.config.Database != "" {
|
||||||
msg.options["database"] = c.config.Database
|
startupMsg.Parameters["database"] = c.config.Database
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = c.txStartupMessage(msg); err != nil {
|
if _, err := c.conn.Write(startupMsg.Encode(nil)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1272,11 +1275,6 @@ func (c *Conn) startTLS(tlsConfig *tls.Config) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) txStartupMessage(msg *startupMessage) error {
|
|
||||||
_, err := c.conn.Write(msg.Bytes())
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Conn) txPasswordMessage(password string) (err error) {
|
func (c *Conn) txPasswordMessage(password string) (err error) {
|
||||||
buf := c.wbuf
|
buf := c.wbuf
|
||||||
buf = append(buf, 'p')
|
buf = append(buf, 'p')
|
||||||
|
|||||||
-28
@@ -1,43 +1,15 @@
|
|||||||
package pgx
|
package pgx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
|
||||||
|
|
||||||
"github.com/jackc/pgx/pgtype"
|
"github.com/jackc/pgx/pgtype"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
protocolVersionNumber = 196608 // 3.0
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
copyData = 'd'
|
copyData = 'd'
|
||||||
copyFail = 'f'
|
copyFail = 'f'
|
||||||
copyDone = 'c'
|
copyDone = 'c'
|
||||||
)
|
)
|
||||||
|
|
||||||
type startupMessage struct {
|
|
||||||
options map[string]string
|
|
||||||
}
|
|
||||||
|
|
||||||
func newStartupMessage() *startupMessage {
|
|
||||||
return &startupMessage{map[string]string{}}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *startupMessage) Bytes() (buf []byte) {
|
|
||||||
buf = make([]byte, 8, 128)
|
|
||||||
binary.BigEndian.PutUint32(buf[4:8], uint32(protocolVersionNumber))
|
|
||||||
for key, value := range s.options {
|
|
||||||
buf = append(buf, key...)
|
|
||||||
buf = append(buf, 0)
|
|
||||||
buf = append(buf, value...)
|
|
||||||
buf = append(buf, 0)
|
|
||||||
}
|
|
||||||
buf = append(buf, ("\000")...)
|
|
||||||
binary.BigEndian.PutUint32(buf[0:4], uint32(len(buf)))
|
|
||||||
return buf
|
|
||||||
}
|
|
||||||
|
|
||||||
type FieldDescription struct {
|
type FieldDescription struct {
|
||||||
Name string
|
Name string
|
||||||
Table pgtype.Oid
|
Table pgtype.Oid
|
||||||
|
|||||||
Reference in New Issue
Block a user