Skip to content

Commit be9a3ec

Browse files
committed
Move pid to init() and update connattrs handling
1 parent 97d1741 commit be9a3ec

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

driver.go

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"database/sql"
2121
"database/sql/driver"
2222
"net"
23+
"os"
24+
"strconv"
2325
)
2426

2527
// This struct is exported to make the driver directly accessible.
@@ -30,6 +32,8 @@ type MySQLDriver struct{}
3032
// Custom dial functions must be registered with RegisterDial
3133
type DialFunc func(addr string) (net.Conn, error)
3234

35+
var pid string
36+
3337
var dials map[string]DialFunc
3438

3539
// RegisterDial registers a custom dial function. It can then be used by the
@@ -145,5 +149,6 @@ func (d MySQLDriver) Open(dsn string) (driver.Conn, error) {
145149
}
146150

147151
func init() {
152+
pid = strconv.Itoa(os.Getpid())
148153
sql.Register("mysql", &MySQLDriver{})
149154
}

packets.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ import (
1616
"fmt"
1717
"io"
1818
"math"
19-
"os"
19+
"os"
2020
"path"
2121
"runtime"
22-
"strconv"
2322
"time"
2423
)
2524

@@ -238,12 +237,13 @@ func (mc *mysqlConn) writeAuthPacket(cipher []byte) error {
238237
// User Password
239238
scrambleBuff := scramblePassword(cipher, []byte(mc.cfg.passwd))
240239

241-
attrs := make(map[string]string)
242-
attrs["_os"] = runtime.GOOS
243-
attrs["_client_name"] = "Go MySQL Driver"
244-
attrs["_pid"] = strconv.Itoa(os.Getpid())
245-
attrs["_platform"] = runtime.GOARCH
246-
attrs["program_name"] = path.Base(os.Args[0])
240+
attrs := map[string]string {
241+
"_os": runtime.GOOS,
242+
"_client_name": "Go-MySQL-Driver",
243+
"_pid": pid,
244+
"_platform": runtime.GOARCH,
245+
"program_name": path.Base(os.Args[0]),
246+
}
247247

248248
attrlen := 0
249249
for attrname, attrvalue := range attrs {

0 commit comments

Comments
 (0)