NewConn creates a new Conn that proxies the messages sent to and from the given net.Conn. New can be used with pgconn.Config.AfterNetConnect to wrap a net.Conn for testing purposes.
(c net.Conn)
| 33 | // NewConn creates a new Conn that proxies the messages sent to and from the given net.Conn. New can be used with |
| 34 | // pgconn.Config.AfterNetConnect to wrap a net.Conn for testing purposes. |
| 35 | func New(c net.Conn) *Conn { |
| 36 | fromFrontendBuf := &bytes.Buffer{} |
| 37 | fromBackendBuf := &bytes.Buffer{} |
| 38 | |
| 39 | return &Conn{ |
| 40 | conn: c, |
| 41 | fromFrontendBuf: fromFrontendBuf, |
| 42 | fromBackendBuf: fromBackendBuf, |
| 43 | backend: pgproto3.NewBackend(fromFrontendBuf, c), |
| 44 | frontend: pgproto3.NewFrontend(fromBackendBuf, c), |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | func (c *Conn) Read(b []byte) (n int, err error) { |
| 49 | return c.conn.Read(b) |