用户返回信息 ModelToResponse

func ModelToResponse(user model.User) proto.UserInfoResponse {userInfoRsp := proto.UserInfoResponse{Id:       user.ID,PassWord: user.Password,NickName: user.NickName,Gender:   user.Gender,Role:     int32(user.Role),Mobile:   user.Mobile,}if user.Birthday != nil {userInfoRsp.BirthDay = uint64(user.Birthday.Unix())}return userInfoRsp
}

分页方法 Paginate

func Paginate(page, pageSize int) func(db *gorm.DB) *gorm.DB {return func(db *gorm.DB) *gorm.DB {if page == 0 {page = 1}switch {case pageSize > 100:pageSize = 100case pageSize <= 0:pageSize = 10}offset := (page - 1) * pageSizereturn db.Offset(offset).Limit(pageSize) // 从offset+1行开始返回pagesize行}
}