Skip to content

Commit

Permalink
packets: replace repeated if/else if by switch (#580)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienschmidt authored May 2, 2017
1 parent 46a8206 commit af474b6
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,23 +486,24 @@ func (mc *mysqlConn) readResultOK() ([]byte, error) {
plugin := string(data[1:pluginEndIndex])
cipher := data[pluginEndIndex+1 : len(data)-1]

if plugin == "mysql_old_password" {
switch plugin {
case "mysql_old_password":
// using old_passwords
return cipher, ErrOldPassword
} else if plugin == "mysql_clear_password" {
case "mysql_clear_password":
// using clear text password
return cipher, ErrCleartextPassword
} else if plugin == "mysql_native_password" {
case "mysql_native_password":
// using mysql default authentication method
return cipher, ErrNativePassword
} else {
default:
return cipher, ErrUnknownPlugin
}
} else {
// https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::OldAuthSwitchRequest
return nil, ErrOldPassword
}

// https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::OldAuthSwitchRequest
return nil, ErrOldPassword

default: // Error otherwise
return nil, mc.handleErrorPacket(data)
}
Expand Down

0 comments on commit af474b6

Please sign in to comment.