sk-matrix-project/backend/golang/matrix-middle-service/pkg/database/driver/mysql/utils.go
2023-02-26 21:20:11 +08:00

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