MCPcopy
hub / github.com/go-sql-driver/mysql / encodeConnectionAttributes

Function encodeConnectionAttributes

connector.go:26–55  ·  view source on GitHub ↗
(cfg *Config)

Source from the content-addressed store, hash-verified

24}
25
26func encodeConnectionAttributes(cfg *Config) string {
27 connAttrsBuf := make([]byte, 0)
28
29 // default connection attributes
30 connAttrsBuf = appendLengthEncodedString(connAttrsBuf, connAttrClientName)
31 connAttrsBuf = appendLengthEncodedString(connAttrsBuf, connAttrClientNameValue)
32 connAttrsBuf = appendLengthEncodedString(connAttrsBuf, connAttrOS)
33 connAttrsBuf = appendLengthEncodedString(connAttrsBuf, connAttrOSValue)
34 connAttrsBuf = appendLengthEncodedString(connAttrsBuf, connAttrPlatform)
35 connAttrsBuf = appendLengthEncodedString(connAttrsBuf, connAttrPlatformValue)
36 connAttrsBuf = appendLengthEncodedString(connAttrsBuf, connAttrPid)
37 connAttrsBuf = appendLengthEncodedString(connAttrsBuf, strconv.Itoa(os.Getpid()))
38 serverHost, _, _ := net.SplitHostPort(cfg.Addr)
39 if serverHost != "" {
40 connAttrsBuf = appendLengthEncodedString(connAttrsBuf, connAttrServerHost)
41 connAttrsBuf = appendLengthEncodedString(connAttrsBuf, serverHost)
42 }
43
44 // user-defined connection attributes
45 for connAttr := range strings.SplitSeq(cfg.ConnectionAttributes, ",") {
46 k, v, found := strings.Cut(connAttr, ":")
47 if !found {
48 continue
49 }
50 connAttrsBuf = appendLengthEncodedString(connAttrsBuf, k)
51 connAttrsBuf = appendLengthEncodedString(connAttrsBuf, v)
52 }
53
54 return string(connAttrsBuf)
55}
56
57func newConnector(cfg *Config) *connector {
58 encodedAttributes := encodeConnectionAttributes(cfg)

Callers 1

newConnectorFunction · 0.85

Calls 1

Tested by

no test coverage detected