Skip to content
3 changes: 2 additions & 1 deletion cmd/go-mysqlserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"log"
"net"

"github.com/go-mysql-org/go-mysql/server"

Check failure on line 7 in cmd/go-mysqlserver/main.go

View workflow job for this annotation

GitHub Actions / golangci

could not import github.com/go-mysql-org/go-mysql/server (-: # github.com/go-mysql-org/go-mysql/server
)

func main() {
Expand All @@ -26,7 +26,8 @@

// Create a connection with user root and an empty password.
// You can use your own handler to handle command here.
conn, err := server.NewConn(c, "root", "", server.EmptyHandler{})
srv := server.NewDefaultServer()
conn, err := srv.NewConn(c, "root", "", server.EmptyHandler{})
if err != nil {
log.Fatal(err)
}
Expand Down
51 changes: 23 additions & 28 deletions server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,50 +37,45 @@
}

var baseConnID uint32 = 10000

// NewConn: create connection with default server settings
var defaultServer *Server
// NewConn: create connection with default server settings
//
// Deprecated: Use [Server.NewConn] instead.
// Deprecated: Use [Server.NewConn] instead.
func NewConn(conn net.Conn, user string, password string, h Handler) (*Conn, error) {
p := NewInMemoryProvider()
p.AddUser(user, password)

var packetConn *packet.Conn
if defaultServer.tlsConfig != nil {
packetConn = packet.NewTLSConn(conn)
} else {
packetConn = packet.NewConn(conn)
if defaultServer == nil {
defaultServer = NewDefaultServer()
}
// NewCustomizedConn: create connection with customized server settings
//
// Deprecated: Use [Server.NewConn] instead.

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)
// NewCustomizedConn: create connection with customized server settings
// Deprecated: Use Server.NewConn instead.
func NewCustomizedConn(conn net.Conn, serverConf *Server, p CredentialProvider, h Handler) (*Conn, error) {

Check failure on line 55 in server/conn.go

View workflow job for this annotation

GitHub Actions / platforms (amd64, freebsd)

syntax error: unexpected name NewCustomizedConn, expected (

Check failure on line 55 in server/conn.go

View workflow job for this annotation

GitHub Actions / Tests Go 1.23 on ubuntu-24.04

syntax error: unexpected name NewCustomizedConn, expected (

Check failure on line 55 in server/conn.go

View workflow job for this annotation

GitHub Actions / Tests Go 1.22 on ubuntu-24.04

syntax error: unexpected name NewCustomizedConn, expected (

Check failure on line 55 in server/conn.go

View workflow job for this annotation

GitHub Actions / Tests Go 1.22 on ubuntu-22.04

syntax error: unexpected name NewCustomizedConn, expected (

Check failure on line 55 in server/conn.go

View workflow job for this annotation

GitHub Actions / Tests Go 1.24 on ubuntu-22.04

syntax error: unexpected name NewCustomizedConn, expected (

Check failure on line 55 in server/conn.go

View workflow job for this annotation

GitHub Actions / Tests Go 1.23 on ubuntu-22.04

syntax error: unexpected name NewCustomizedConn, expected (

Check failure on line 55 in server/conn.go

View workflow job for this annotation

GitHub Actions / golangci

expected '(', found NewCustomizedConn (typecheck)

Check failure on line 55 in server/conn.go

View workflow job for this annotation

GitHub Actions / golangci

syntax error: unexpected name NewCustomizedConn, expected (

Check failure on line 55 in server/conn.go

View workflow job for this annotation

GitHub Actions / golangci

syntax error: unexpected name NewCustomizedConn, expected (

Check failure on line 55 in server/conn.go

View workflow job for this annotation

GitHub Actions / golangci

syntax error: unexpected name NewCustomizedConn, expected (

Check failure on line 55 in server/conn.go

View workflow job for this annotation

GitHub Actions / Tests with MySQL 8.4.3

syntax error: unexpected name NewCustomizedConn, expected (

Check failure on line 55 in server/conn.go

View workflow job for this annotation

GitHub Actions / Tests with MySQL 8.0.40

syntax error: unexpected name NewCustomizedConn, expected (
return serverConf.NewCustomizedConn(conn, p, h)
}

if err := c.handshake(); err != nil {
c.Close()
return nil, err
}
// NewConn: create connection with default server settings
func (s *Server) NewConn(conn net.Conn, user string, password string, h Handler) (*Conn, error) {

Check failure on line 60 in server/conn.go

View workflow job for this annotation

GitHub Actions / platforms (amd64, freebsd)

syntax error: unexpected name net in argument list; possibly missing comma or )

Check failure on line 60 in server/conn.go

View workflow job for this annotation

GitHub Actions / Tests Go 1.23 on ubuntu-24.04

syntax error: unexpected name net in argument list; possibly missing comma or )

Check failure on line 60 in server/conn.go

View workflow job for this annotation

GitHub Actions / Tests Go 1.22 on ubuntu-24.04

syntax error: unexpected name net in argument list; possibly missing comma or )

Check failure on line 60 in server/conn.go

View workflow job for this annotation

GitHub Actions / Tests Go 1.22 on ubuntu-22.04

syntax error: unexpected name net in argument list; possibly missing comma or )

Check failure on line 60 in server/conn.go

View workflow job for this annotation

GitHub Actions / Tests Go 1.24 on ubuntu-22.04

syntax error: unexpected name net in argument list; possibly missing comma or )

Check failure on line 60 in server/conn.go

View workflow job for this annotation

GitHub Actions / Tests Go 1.23 on ubuntu-22.04

syntax error: unexpected name net in argument list; possibly missing comma or )

Check failure on line 60 in server/conn.go

View workflow job for this annotation

GitHub Actions / golangci

missing ',' in argument list (typecheck)

Check failure on line 60 in server/conn.go

View workflow job for this annotation

GitHub Actions / golangci

syntax error: unexpected name net in argument list; possibly missing comma or ) (typecheck)

Check failure on line 60 in server/conn.go

View workflow job for this annotation

GitHub Actions / golangci

syntax error: unexpected name net in argument list; possibly missing comma or )) (typecheck)

Check failure on line 60 in server/conn.go

View workflow job for this annotation

GitHub Actions / golangci

syntax error: unexpected name net in argument list; possibly missing comma or )) (typecheck)

Check failure on line 60 in server/conn.go

View workflow job for this annotation

GitHub Actions / Tests with MySQL 8.4.3

syntax error: unexpected name net in argument list; possibly missing comma or )

Check failure on line 60 in server/conn.go

View workflow job for this annotation

GitHub Actions / Tests with MySQL 8.0.40

syntax error: unexpected name net in argument list; possibly missing comma or )
p := NewInMemoryProvider()
p.AddUser(user, password)

return c, nil
return s.NewCustomizedConn(conn, p, h)
}

// NewCustomizedConn: create connection with customized server settings
func NewCustomizedConn(conn net.Conn, serverConf *Server, p CredentialProvider, h Handler) (*Conn, error) {
func (s *Server) NewCustomizedConn(conn net.Conn, p CredentialProvider, h Handler) (*Conn, error) {
var packetConn *packet.Conn
if serverConf.tlsConfig != nil {
if s.tlsConfig != nil {
packetConn = packet.NewTLSConn(conn)
} else {
packetConn = packet.NewConn(conn)
}

c := &Conn{
Conn: packetConn,
serverConf: serverConf,
serverConf: s,
credentialProvider: p,
h: h,
connectionID: atomic.AddUint32(&baseConnID, 1),
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