mirror of
https://github.com/pagefaultgames/rogueserver.git
synced 2025-04-05 04:27:13 +08:00
chore: Refactor FetchDiscordIdByUsername and FetchGoogleIdByUsername to handle null values
This commit is contained in:
parent
214f7e6238
commit
b184e754ce
@ -89,23 +89,31 @@ func FetchUsernameByGoogleId(googleId string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func FetchDiscordIdByUsername(username string) (string, error) {
|
func FetchDiscordIdByUsername(username string) (string, error) {
|
||||||
var discordId string
|
var discordId sql.NullString
|
||||||
err := handle.QueryRow("SELECT discordId FROM accounts WHERE username = ?", username).Scan(&discordId)
|
err := handle.QueryRow("SELECT discordId FROM accounts WHERE username = ?", username).Scan(&discordId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return discordId, nil
|
if !discordId.Valid {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return discordId.String, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func FetchGoogleIdByUsername(username string) (string, error) {
|
func FetchGoogleIdByUsername(username string) (string, error) {
|
||||||
var googleId string
|
var googleId sql.NullString
|
||||||
err := handle.QueryRow("SELECT googleId FROM accounts WHERE username = ?", username).Scan(&googleId)
|
err := handle.QueryRow("SELECT googleId FROM accounts WHERE username = ?", username).Scan(&googleId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return googleId, nil
|
if !googleId.Valid {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return googleId.String, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func FetchUsernameBySessionToken(token []byte) (string, error) {
|
func FetchUsernameBySessionToken(token []byte) (string, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user