Documentation ¶
Overview ¶
@Author: Sangs
@Date: 2023-08-25
@LastEditTime: 2023-09-02
@Description:
Description: 用于执行跟视频有关的数据库操作;定义了视频的数据结构。
Func: 已经实现的函数
InsertVideo() --- 插入视频信息进入mysql
Author: sangs
Date: 2023-08-22
Index ¶
- Variables
- func DeleteComment(user_id int64, comment_id int64, video_id int64) (int64, error)
- func FindUser2Login(ctx context.Context, username string, password string) (int64, error)
- func GetIsFavor(current_id int64, video_id int64) (bool, error)
- func GetUserFanNum(userid int64) (follower_count int64, err error)
- func GetUserFavorite(userid int64) (favorite_count int64, err error)
- func GetUserFollowNum(userid int64) (follow_count int64, err error)
- func GetUserTotalF(userid int64) (total_favorite int64, err error)
- func GetUserVideosNum(userid int64) (work_count int64, err error)
- func GetVideoCommentNum(videoid int64) (comment_count int64, err error)
- func GetVideoFavoriteNum(videoid int64) (favorite_count int64, err error)
- func GiveALike(user_id int64, video_id int64) (int64, error)
- func GiveAUnlike(user_id int64, video_id int64) (int64, error)
- func InsertUser(ctx context.Context, username string, password string) (int64, error)
- func InsertVideo(userid int64, title string, videoURL string, coverURL string, pubtime int64) error
- func IsFollow(current_id int64, find_id int64) (bool, error)
- func PostComment(user_id int64, video_id int64, comment_text string, t int64) (int64, error)
- type Comment
- type Favorite
- type Relationship
- type User
- type Video
Constants ¶
This section is empty.
Variables ¶
View Source
var DB *gorm.DB
Functions ¶
func DeleteComment ¶
func FindUser2Login ¶
- Description: 该函数进行用户查找,输入参数为用户名和密码。
- 由于只是单表简单查找操作,所以不需要使用事务
- 使用idx_username索引,针对用户名进行查找对应的id和密码
- 对密码使用安全比较,避免时序攻击
- Retn: user.ID 自增的用户id,err 用于判定插入过程是否存在错误
- -1 err表示没有处理的错误
- -2 err表示密码错误或用户名有误
- Author: sangs
- Date: 2023-08-19
func GetUserFanNum ¶
func GetUserFavorite ¶
func GetUserFollowNum ¶
func GetUserTotalF ¶
func GetUserVideosNum ¶
- Description: 通过用户id用户发布的视频个数 以后尽量还是使用redis实现,这样的查找在用户个数很多的时候往往会出问题
- Retn: user.ID 自增的用户id,err 用于判定插入过程是否存在错误
- -1 err表示查找过程出问题了
- Author: sangs
- Date: 2023-08-25
func GetVideoCommentNum ¶
func GetVideoFavoriteNum ¶
func InsertUser ¶
- Description: 如果完成了所有的安全性检查,则可以调用该函数进行新用户的创建,输入参数为用户名和密码。
- 通过User结构将其绑定为user变量上。
- 设置了username的唯一索引,所以不需要使用NoUserWithName()判断是否存在当前用户名了
- 直接判断是否是1062号错误,即可判断出是否存在重复用户名。
- 通过返回id为-2,这样在外面就不需要再调用mysql包来判断错误类型
- 由于只是单表简单操作,所以不需要使用事务
- Retn: user.ID 自增的用户id,err 用于判定插入过程是否存在错误
- -1 err表示没有处理的错误
- -2 err表示username出现重复
- Author: sangs
- Date: 2023-08-13
func InsertVideo ¶
* Description: 根据所有相关的信息,将视频数据插入videos库中 * Author: sangs * Date: 2023-08-22
Types ¶
type Comment ¶
func GetCommentAboutVideo ¶
type Favorite ¶
type Relationship ¶
func (Relationship) TableName ¶
func (Relationship) TableName() string
type User ¶
type User struct { ID int64 // 用户id Username string // 用户名 唯一 Password string // 密码 Avatar string `gorm:"default:'-'"` // 默认头像路径 BackgroundImage string `gorm:"default:'-'"` // 默认背景路径 Signature string `gorm:"default:'这个人比较懒,什么都没有写'"` // 默认简介 }
* Description: 定义单个User的结构体(GORM会自动使用字段名的蛇形寻找列名,所以可以跟数据库对应上) * 实际上真正可以修改的只有用户名和密码,头像、背景图、简介貌似都不能修改,只能查看。可以在一开始创建的时候就随机 * Author: sangs * Date: 2023-08-13
func GetUserByID ¶
- Description: 通过用户id查找所有的信息
- 由于只是单表简单查找操作,所以不需要使用事务
- 使用idx_username索引,针对用户名进行查找对应的id和密码
- 对密码使用安全比较,避免时序攻击
- Retn: user.ID 自增的用户id,err 用于判定插入过程是否存在错误
- -1 err表示没有处理的错误
- -2 err表示密码错误或用户名有误
- Author: sangs
- Date: 2023-08-21
type Video ¶
type Video struct { ID int64 // 视频id AuthorID int64 // 作者id 唯一 Title string // 视频标题 VideoURL string // 视频路径 CoverURL string // 封面路径 Pubtime int64 // 发布时间 }
* Description: 定义单个Video的结构体(GORM会自动使用字段名的蛇形寻找列名,所以可以跟数据库对应上) * Author: sangs * Date: 2023-08-22
func GetVideoBeforeTime ¶
func GetVideoByAuthor2Redis ¶
* Description: 根据用户id,将该用户的所有视频信息存入redis,为了后面统计视频数据,以及倒序退出做准备 * Author: sangs * Date: 2023-08-25
func GetVideoByID ¶
Click to show internal directories.
Click to hide internal directories.