Skip to content

Commit 01d48e6

Browse files
author
Shlomi Noach
authored
Merge pull request #143 from EasyPost/issue_142
Thank you
2 parents 20456c8 + b2fee9a commit 01d48e6

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

go/mysql/connection.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package mysql
77

88
import (
99
"fmt"
10+
"net"
1011
)
1112

1213
// ConnectionConfig is the minimal configuration required to connect to a MySQL server
@@ -47,5 +48,11 @@ func (this *ConnectionConfig) Equals(other *ConnectionConfig) bool {
4748
}
4849

4950
func (this *ConnectionConfig) GetDBUri(databaseName string) string {
50-
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", this.User, this.Password, this.Key.Hostname, this.Key.Port, databaseName)
51+
var ip = net.ParseIP(this.Key.Hostname)
52+
if (ip != nil) && (ip.To4() == nil) {
53+
// Wrap IPv6 literals in square brackets
54+
return fmt.Sprintf("%s:%s@tcp([%s]:%d)/%s", this.User, this.Password, this.Key.Hostname, this.Key.Port, databaseName)
55+
} else {
56+
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", this.User, this.Password, this.Key.Hostname, this.Key.Port, databaseName)
57+
}
5158
}

0 commit comments

Comments
 (0)