Skip to content

Commit

Permalink
Merge pull request #143 from EasyPost/issue_142
Browse files Browse the repository at this point in the history
Thank you
  • Loading branch information
Shlomi Noach authored Aug 15, 2016
2 parents 20456c8 + b2fee9a commit 01d48e6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion go/mysql/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package mysql

import (
"fmt"
"net"
)

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

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

0 comments on commit 01d48e6

Please sign in to comment.