-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
180 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
package repository | ||
|
||
import ( | ||
"message/app/model" | ||
"fmt" | ||
"message/config" | ||
"message/database" | ||
) | ||
|
||
// GetMessageToken 尝试获取一个符合指定条件的MessageToken。 | ||
// | ||
// 它返回找到的MessageToken和可能出现的错误。如果记录不存在,将返回nil和gorm.ErrRecordNotFound。 | ||
func GetMessageToken(authId string, authToken string) (model.MessageToken, error) { | ||
var token model.MessageToken | ||
result := database.DB.Model(model.MessageToken{}). | ||
Where("auth_id = ?", authId). | ||
Where("token = ?", authToken). | ||
First(&token) | ||
func GetMessageToken(messageToken string) (bool, error) { | ||
verify := config.AppConfig.App.Verify | ||
result := database.DB.Table(verify.Table). | ||
Select(verify.Column). | ||
Where(fmt.Sprintf("%s = ?", verify.Column), messageToken). | ||
Limit(1) | ||
|
||
if result.Error != nil { | ||
// 直接返回错误,包括未找到记录的情况 | ||
return token, result.Error | ||
return false, result.Error | ||
} | ||
|
||
// 记录被成功找到,返回token的指针和nil作为错误 | ||
return token, nil | ||
return true, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.