NewConn: create connection with default server settings
(conn net.Conn, user string, password string, h Handler)
| 48 | |
| 49 | // NewConn: create connection with default server settings |
| 50 | func NewConn(conn net.Conn, user string, password string, h Handler) (*Conn, error) { |
| 51 | p := NewInMemoryProvider() |
| 52 | p.AddUser(user, password) |
| 53 | salt, _ := RandomBuf(20) |
| 54 | |
| 55 | var packetConn *packet.Conn |
| 56 | if defaultServer.tlsConfig != nil { |
| 57 | packetConn = packet.NewTLSConn(conn) |
| 58 | } else { |
| 59 | packetConn = packet.NewConn(conn) |
| 60 | } |
| 61 | |
| 62 | c := &Conn{ |
| 63 | Conn: packetConn, |
| 64 | serverConf: defaultServer, |
| 65 | credentialProvider: p, |
| 66 | h: h, |
| 67 | connectionID: atomic.AddUint32(&baseConnID, 1), |
| 68 | stmts: make(map[uint32]*Stmt), |
| 69 | salt: salt, |
| 70 | } |
| 71 | c.closed.Set(false) |
| 72 | |
| 73 | if err := c.handshake(); err != nil { |
| 74 | c.Close() |
| 75 | return nil, err |
| 76 | } |
| 77 | |
| 78 | return c, nil |
| 79 | } |
| 80 | |
| 81 | // NewCustomizedConn: create connection with customized server settings |
| 82 | func NewCustomizedConn(conn net.Conn, serverConf *Server, p CredentialProvider, h Handler) (*Conn, error) { |
nothing calls this directly
no test coverage detected