Skip to content

Commit 77430c6

Browse files
authored
Merge pull request #788 from dveeden/default_connattrs
Set library specific connection attributes
2 parents df895b5 + 2dec1fe commit 77430c6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

client/conn.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"crypto/tls"
77
"fmt"
88
"net"
9+
"runtime"
910
"strings"
1011
"time"
1112

@@ -78,6 +79,14 @@ type Dialer func(ctx context.Context, network, address string) (net.Conn, error)
7879
func ConnectWithDialer(ctx context.Context, network string, addr string, user string, password string, dbName string, dialer Dialer, options ...func(*Conn)) (*Conn, error) {
7980
c := new(Conn)
8081

82+
c.attributes = map[string]string{
83+
"_client_name": "go-mysql",
84+
// "_client_version": "0.1",
85+
"_os": runtime.GOOS,
86+
"_platform": runtime.GOARCH,
87+
"_runtime_version": runtime.Version(),
88+
}
89+
8190
if network == "" {
8291
network = getNetProto(addr)
8392
}
@@ -317,7 +326,9 @@ func (c *Conn) Rollback() error {
317326
}
318327

319328
func (c *Conn) SetAttributes(attributes map[string]string) {
320-
c.attributes = attributes
329+
for k, v := range attributes {
330+
c.attributes[k] = v
331+
}
321332
}
322333

323334
func (c *Conn) SetCharset(charset string) error {

replication/binlogsyncer.go

+1
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,7 @@ func (b *BinlogSyncer) newConnection(ctx context.Context) (*client.Conn, error)
891891
return client.ConnectWithDialer(timeoutCtx, "", addr, b.cfg.User, b.cfg.Password,
892892
"", b.cfg.Dialer, func(c *client.Conn) {
893893
c.SetTLSConfig(b.cfg.TLSConfig)
894+
c.SetAttributes(map[string]string{"_client_role": "binary_log_listener"})
894895
})
895896
}
896897

0 commit comments

Comments
 (0)