Skip to content

Commit af474b6

Browse files
packets: replace repeated if/else if by switch (#580)
1 parent 46a8206 commit af474b6

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

packets.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -486,23 +486,24 @@ func (mc *mysqlConn) readResultOK() ([]byte, error) {
486486
plugin := string(data[1:pluginEndIndex])
487487
cipher := data[pluginEndIndex+1 : len(data)-1]
488488

489-
if plugin == "mysql_old_password" {
489+
switch plugin {
490+
case "mysql_old_password":
490491
// using old_passwords
491492
return cipher, ErrOldPassword
492-
} else if plugin == "mysql_clear_password" {
493+
case "mysql_clear_password":
493494
// using clear text password
494495
return cipher, ErrCleartextPassword
495-
} else if plugin == "mysql_native_password" {
496+
case "mysql_native_password":
496497
// using mysql default authentication method
497498
return cipher, ErrNativePassword
498-
} else {
499+
default:
499500
return cipher, ErrUnknownPlugin
500501
}
501-
} else {
502-
// https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::OldAuthSwitchRequest
503-
return nil, ErrOldPassword
504502
}
505503

504+
// https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::OldAuthSwitchRequest
505+
return nil, ErrOldPassword
506+
506507
default: // Error otherwise
507508
return nil, mc.handleErrorPacket(data)
508509
}

0 commit comments

Comments
 (0)