mirror of
https://gitee.com/shikong-sk/gofiber-study
synced 2025-02-23 15:22:14 +08:00
38 lines
516 B
Go
38 lines
516 B
Go
package user
|
|
|
|
import (
|
|
"errors"
|
|
"gofiber.study.skcks.cn/global"
|
|
"gofiber.study.skcks.cn/model/generic/models"
|
|
)
|
|
|
|
var (
|
|
NotExists = errors.New("用户不存在")
|
|
)
|
|
|
|
type Service struct {
|
|
}
|
|
|
|
var Services *Service
|
|
|
|
func InitService() {
|
|
Services = &Service{}
|
|
}
|
|
|
|
func (s *Service) GetUserByAccount(account string) (*models.User, error) {
|
|
u := &models.User{
|
|
Account: account,
|
|
}
|
|
|
|
has, err := global.DataSources.Get(u)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if !has {
|
|
return nil, NotExists
|
|
}
|
|
|
|
return u, nil
|
|
}
|