Skip to content

server: Rework NewConn/defaultServer #1021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 2, 2025
26 changes: 2 additions & 24 deletions server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,9 @@ var baseConnID uint32 = 10000
func NewConn(conn net.Conn, user string, password string, h Handler) (*Conn, error) {
p := NewInMemoryProvider()
p.AddUser(user, password)
server := NewDefaultServer()

var packetConn *packet.Conn
if defaultServer.tlsConfig != nil {
packetConn = packet.NewTLSConn(conn)
} else {
packetConn = packet.NewConn(conn)
}

c := &Conn{
Conn: packetConn,
serverConf: defaultServer,
credentialProvider: p,
h: h,
connectionID: atomic.AddUint32(&baseConnID, 1),
stmts: make(map[uint32]*Stmt),
salt: mysql.RandomBuf(20),
}
c.closed.Store(false)

if err := c.handshake(); err != nil {
c.Close()
return nil, err
}

return c, nil
return NewCustomizedConn(conn, server, p, h)
}

// NewCustomizedConn: create connection with customized server settings
Expand Down
2 changes: 0 additions & 2 deletions server/server_conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"github.com/go-mysql-org/go-mysql/mysql"
)

var defaultServer = NewDefaultServer()

// Defines a basic MySQL server with configs.
//
// We do not aim at implementing the whole MySQL connection suite to have the best compatibilities for the clients.
Expand Down
Loading