26 lines
596 B
Go
26 lines
596 B
Go
package mysql
|
|
|
|
import (
|
|
"regexp"
|
|
)
|
|
|
|
func ParseSqlConnDBName(conn string) string {
|
|
pattern := regexp.MustCompile(
|
|
`^(?:(?P<user>.*?)(?::(?P<passwd>.*))?@)?` + // [user[:password]@]
|
|
`(?:(?P<net>[^\(]*)(?:\((?P<addr>[^\)]*)\))?)?` + // [net[(addr)]]
|
|
`\/(?P<dbname>.*?)` + // /dbname
|
|
`(?:\?(?P<params>[^\?]*))?$`) // [?param1=value1¶mN=valueN]
|
|
matches := pattern.FindStringSubmatch(conn)
|
|
// tlsConfigRegister := make(map[string]*tls.Config)
|
|
names := pattern.SubexpNames()
|
|
|
|
for i, match := range matches {
|
|
switch names[i] {
|
|
case "dbname":
|
|
return match
|
|
}
|
|
}
|
|
|
|
return ""
|
|
}
|