Skip to content

Commit 4c892f9

Browse files
committed
Use sync.OnceValue()
1 parent ab1308e commit 4c892f9

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

server/conn.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package server
33
import (
44
"errors"
55
"net"
6+
"sync"
67
"sync/atomic"
78

89
"github.com./go-mysql-org/go-mysql/mysql"
@@ -38,17 +39,16 @@ type Conn struct {
3839

3940
var (
4041
baseConnID uint32 = 10000
41-
defaultServer *Server
42+
defaultServer = sync.OnceValue(func() *Server {
43+
return NewDefaultServer()
44+
})
4245
)
4346

4447
// NewConn: create connection with default server settings
4548
//
4649
// Deprecated: Use [Server.NewConn] instead.
4750
func NewConn(conn net.Conn, user string, password string, h Handler) (*Conn, error) {
48-
if defaultServer == nil {
49-
defaultServer = NewDefaultServer()
50-
}
51-
return defaultServer.NewConn(conn, user, password, h)
51+
return defaultServer().NewConn(conn, user, password, h)
5252
}
5353

5454
// NewCustomizedConn: create connection with customized server settings

0 commit comments

Comments
 (0)