Skip to content

Commit

Permalink
Add default connection attribute '_server_host'
Browse files Browse the repository at this point in the history
  • Loading branch information
oblitorum committed Oct 31, 2023
1 parent 182f00a commit dc53627
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type connector struct {
encodedAttributes string // Encoded connection attributes.
}

func encodeConnectionAttributes(textAttributes string) string {
func encodeConnectionAttributes(cfg *Config) string {
connAttrsBuf := make([]byte, 0)

// default connection attributes
Expand All @@ -34,9 +34,12 @@ func encodeConnectionAttributes(textAttributes string) string {
connAttrsBuf = appendLengthEncodedString(connAttrsBuf, connAttrPlatformValue)
connAttrsBuf = appendLengthEncodedString(connAttrsBuf, connAttrPid)
connAttrsBuf = appendLengthEncodedString(connAttrsBuf, strconv.Itoa(os.Getpid()))
connAttrsBuf = appendLengthEncodedString(connAttrsBuf, connAttrServerHost)
serverHost, _, _ := net.SplitHostPort(cfg.Addr)
connAttrsBuf = appendLengthEncodedString(connAttrsBuf, serverHost)

// user-defined connection attributes
for _, connAttr := range strings.Split(textAttributes, ",") {
for _, connAttr := range strings.Split(cfg.ConnectionAttributes, ",") {
attr := strings.SplitN(connAttr, ":", 2)
if len(attr) != 2 {
continue
Expand All @@ -50,7 +53,7 @@ func encodeConnectionAttributes(textAttributes string) string {
}

func newConnector(cfg *Config) *connector {
encodedAttributes := encodeConnectionAttributes(cfg.ConnectionAttributes)
encodedAttributes := encodeConnectionAttributes(cfg)
return &connector{
cfg: cfg,
encodedAttributes: encodedAttributes,
Expand Down
1 change: 1 addition & 0 deletions const.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
connAttrPlatform = "_platform"
connAttrPlatformValue = runtime.GOARCH
connAttrPid = "_pid"
connAttrServerHost = "_server_host"
)

// MySQL constants documentation:
Expand Down

0 comments on commit dc53627

Please sign in to comment.