gofiber-study/services/user/user.go

38 lines
516 B
Go
Raw Normal View History

2022-10-04 14:59:46 +08:00
package user
import (
"errors"
"gofiber.study.skcks.cn/global"
"gofiber.study.skcks.cn/model/generic/models"
2022-10-04 14:59:46 +08:00
)
var (
NotExists = errors.New("用户不存在")
)
type Service struct {
}
var Services *Service
func InitService() {
Services = &Service{}
}
func (s *Service) GetUserByAccount(account string) (*models.User, error) {
2022-10-04 14:59:46 +08:00
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
}