sk-matrix-project/backend/golang/matrix-middle-service/pkg/database/driver/mysql/utils.go

26 lines
596 B
Go
Raw Normal View History

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&paramN=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 ""
}