Skip to content

Commit c422dd1

Browse files
committed
Add default connection attribute '_server_host'
1 parent 451e17f commit c422dd1

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

connector.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type connector struct {
2222
encodedAttributes string // Encoded connection attributes.
2323
}
2424

25-
func encodeConnectionAttributes(textAttributes string) string {
25+
func encodeConnectionAttributes(cfg *Config) string {
2626
connAttrsBuf := make([]byte, 0)
2727

2828
// default connection attributes
@@ -34,9 +34,12 @@ func encodeConnectionAttributes(textAttributes string) string {
3434
connAttrsBuf = appendLengthEncodedString(connAttrsBuf, connAttrPlatformValue)
3535
connAttrsBuf = appendLengthEncodedString(connAttrsBuf, connAttrPid)
3636
connAttrsBuf = appendLengthEncodedString(connAttrsBuf, strconv.Itoa(os.Getpid()))
37+
connAttrsBuf = appendLengthEncodedString(connAttrsBuf, connAttrServerHost)
38+
serverHost, _, _ := net.SplitHostPort(cfg.Addr)
39+
connAttrsBuf = appendLengthEncodedString(connAttrsBuf, serverHost)
3740

3841
// user-defined connection attributes
39-
for _, connAttr := range strings.Split(textAttributes, ",") {
42+
for _, connAttr := range strings.Split(cfg.ConnectionAttributes, ",") {
4043
k, v, found := strings.Cut(connAttr, ":")
4144
if !found {
4245
continue
@@ -49,7 +52,7 @@ func encodeConnectionAttributes(textAttributes string) string {
4952
}
5053

5154
func newConnector(cfg *Config) *connector {
52-
encodedAttributes := encodeConnectionAttributes(cfg.ConnectionAttributes)
55+
encodedAttributes := encodeConnectionAttributes(cfg)
5356
return &connector{
5457
cfg: cfg,
5558
encodedAttributes: encodedAttributes,

const.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const (
2626
connAttrPlatform = "_platform"
2727
connAttrPlatformValue = runtime.GOARCH
2828
connAttrPid = "_pid"
29+
connAttrServerHost = "_server_host"
2930
)
3031

3132
// MySQL constants documentation:

0 commit comments

Comments
 (0)