Files
goodBaby/handler/db/account.go
T
mei 9b656cebee
Quality check / Web UI (push) Successful in 9m19s
feat(gateway): 优化gateway相关功能
2026-09-12 15:32:27 +08:00

29 lines
709 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package db
import (
"fmt"
"github.com/ssdomei232/goodBaby/model"
)
// GetAccount 读取一个账号,返回数据库里的原始记录。
//
// 规则执行需要的账号凭据由上层(handler/runner)在这里取好再传给 driver,
// driver 自己不碰数据库。accountID 为 0 表示该规则不需要账号,返回 (nil, nil)。
func GetAccount(accountID uint) (*model.Account, error) {
if accountID == 0 {
return nil, nil
}
gormDB, err := GetGormDB()
if err != nil {
return nil, err
}
var account model.Account
if err := gormDB.First(&account, accountID).Error; err != nil {
return nil, fmt.Errorf("获取账号(ID: %d)失败: %w", accountID, err)
}
return &account, nil
}