Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions mysql/mysqlconn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,31 @@ func ParseConnConfig(proxy bool, config map[string]string) (ConnConfig, error) {
Port: "3306",
}

if location, ok := config["location"]; ok && location != "" {
if err := parseURI(location, &cc); err != nil {
return cc, fmt.Errorf("parsing location URI: %w", err)
if proxy {
_, host, ok := strings.Cut(config["location"], "://")
if !ok {
return cc, fmt.Errorf("failed to parse location URI: expected protocol://identifier")
}
cc.Host = host
} else {
if location, ok := config["location"]; ok && location != "" {
if err := parseURI(location, &cc); err != nil {
return cc, fmt.Errorf("parsing location URI: %w", err)
}
}
}

if v := config["host"]; v != "" {
cc.Host = v
}
if v := config["port"]; v != "" {
p, err := strconv.Atoi(v)
if err != nil || p < 1 || p > 65535 {
return cc, fmt.Errorf("invalid port %q: must be an integer between 1 and 65535", v)
if v := config["host"]; v != "" {
cc.Host = v
}
if v := config["port"]; v != "" {
p, err := strconv.Atoi(v)
if err != nil || p < 1 || p > 65535 {
return cc, fmt.Errorf("invalid port %q: must be an integer between 1 and 65535", v)
}
cc.Port = v
}
cc.Port = v
}

if v := config["username"]; v != "" {
cc.Username = v
}
Expand Down