Skip to content

Conversation

bgaifullin
Copy link
Contributor

@bgaifullin bgaifullin commented Sep 19, 2017

Description

in case if connection addr does not have port, set default port. (3306)

Checklist

  • Code compiles correctly
  • Created tests which fail without the change (if possible)
  • All tests passing
  • Extended the README / documentation, if necessary

dsn.go Outdated

func ensureHavePort(addr string) string {
s := strings.Split(addr, ":")
if len(s) == 1 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strings.ContainsRune(addr, ':')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or use SplitHostPort to support IPv6

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if _, _, err := net.SplitHostPort(addr); err != nil {
    addr = net.JoinHostPort(addr, "3306")
}
return addr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@methane , thank you, good approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

@arnehormann arnehormann merged commit 7785c74 into go-sql-driver:master Sep 21, 2017
@julienschmidt julienschmidt added this to the v1.4 milestone Sep 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants