panic: rpc error: code = Unknown desc = record not found
来源:1-12 测试用户微服务接口
PHPerAndGopher
2021-07-02 13:38:22
func (s *UserServer) CreateUser(c context.Context, req *proto.CreateUserInfo) (*proto.UserInfoResponse, error){
var user model.User
result := DB.Where(&model.User{Mobile: req.Mobile}).First(&user)
if result.Error != nil {
return nil, result.Error
}
if result.RowsAffected != 0 {
return nil, status.Errorf(codes.AlreadyExists,"用户已存在")
}
user.Mobile = req.Mobile
user.NickName = req.NickName
options := &password.Options{16,100,32,sha512.New}
salt, encodePwd := password.Encode(req.Password,options)
user.Password = fmt.Sprintf("$pbkdf2-sha512$%s$%s",salt,encodePwd)
result = DB.Create(&user)
if result.Error != nil {
return nil, status.Errorf(codes.Internal,result.Error.Error())
}
userInfoRsp := ModelToResponse(user)
return &userInfoRsp, nil
}
老师好,我测试添加用户服务时这里报了一个错误:panic: rpc error: code = Unknown desc = record not found。
我执行代码过程中报错了,我尝试了在Server端的代码里打印错误,也没打印出来,我又把打印的代码删掉了
1回答
这个是应该server端的服务,这个报错是orm没有查询到数据导致的,你要在server端打断点看看具体哪一行代码没有查询到
相似问题