package auth import ( "cls-server/internal/domain/admin" "cls-server/internal/domain/auth" "cls-server/pkg/xorm_engine" "errors" "xorm.io/builder" ) type AuthRepositoryORM struct { engine *xorm_engine.Engine } var _ auth.AuthRepository = (*AuthRepositoryORM)(nil) func NewAuthRepositoryORM(db *xorm_engine.Engine) auth.AuthRepository { return &AuthRepositoryORM{ engine: db, } } func (a AuthRepositoryORM) GetAdminByUsername(username string) (*admin.Admin, error) { u := &admin.Admin{} has, err := a.engine.Where(builder.Eq{"username": username}).Get(u) if err != nil { return nil, err } if !has { return nil, errors.New("用户不存在") } return u, nil }