Skip to content

Commit

Permalink
Merge pull request #5 from HammerCloth/dev
Browse files Browse the repository at this point in the history
TikTok v1.2.2
  • Loading branch information
HammerCloth authored Jun 6, 2022
2 parents bcc397d + cfe711d commit bc04132
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 5 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- [整体的架构图](#整体的架构图)
- [数据库的设计](#数据库的设计)
- [Redis架构的设计](#Redis架构的设计)
- [RabbitMQ架构的设计](#RabbitMQ架构的设计)
- [服务模块的设计](#服务模块的设计)
- [视频模块设计](#视频模块的设计)
- [点赞模块设计](#点赞模块设计)
Expand All @@ -50,6 +51,8 @@
- [部署](#部署)
- [使用到的技术](#使用到的技术)
- [未来展望](#未来展望)
- [分布式服务](#分布式服务)
- [推荐视频展望](#推荐视频展望)
- [如何参与开源项目](#如何参与开源项目)
- [版本控制](#版本控制)
- [贡献者](#贡献者)
Expand Down Expand Up @@ -146,6 +149,13 @@ tiktok
</a>
</p>

#### RabbitMQ架构的设计
<p align="center">
<a href="https://github.com/HammerCloth/tiktok.git/">
<img src="images/rabbitmq.jpg" alt="Logo" width="1000" height="600">
</a>
</p>

#### 服务模块的设计

###### 视频模块的设计
Expand Down Expand Up @@ -202,13 +212,24 @@ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./
- [MySQL](https://dev.mysql.com/doc/)

### 未来展望
#### 分布式服务
利用dubbogo来完成分布式,貔貅作为网关,Nacos作为注册中心,将五个模块分别布置到不同的服务器上,以rpc调用的方式来调用当前模块依赖其他模块的方法,做到分布式处理与解耦。
<p align="center">
<a href="https://github.com/HammerCloth/tiktok.git/">
<img src="images/future.png" alt="Logo" width="1000" height="600">
</a>
</p>

#### 推荐视频展望
队伍创新推荐算法
<p align="center">
<a href="https://github.com/HammerCloth/tiktok.git/">
<img src="images/recommend.jpg" alt="Logo" width="1000" height="600">
</a>
</p>

详情请阅读[视频推荐展望](https://bytedancecampus1.feishu.cn/docx/doxcnVIK62rWgR0iE49UAI2wB0b)

### 如何参与开源项目

贡献使开源社区成为一个学习、激励和创造的绝佳场所。你所作的任何贡献都是**非常感谢**的。
Expand Down
Binary file added images/rabbitmq.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/recommend.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions middleware/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,32 @@ func Auth() gin.HandlerFunc {
}
}

// AuthWithoutLogin 未登录情况下,若携带token,则解析出用户id并放入context;若未携带,则放入用户id默认值0
func AuthWithoutLogin() gin.HandlerFunc {
return func(context *gin.Context) {
auth := context.Query("token")
var userId string
if len(auth) == 0 {
userId = "0"
} else {
auth = strings.Fields(auth)[1]
token, err := parseToken(auth)
if err != nil {
context.Abort()
context.JSON(http.StatusUnauthorized, Response{
StatusCode: -1,
StatusMsg: "Token Error",
})
} else {
userId = token.Id
println("token 正确")
}
}
context.Set("userId", userId)
context.Next()
}
}

// parseToken 解析token
func parseToken(token string) (*jwt.StandardClaims, error) {
jwtToken, err := jwt.ParseWithClaims(token, &jwt.StandardClaims{}, func(token *jwt.Token) (i interface{}, e error) {
Expand Down
4 changes: 2 additions & 2 deletions middleware/authBody.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"strings"
)

// Auth_body 鉴权中间件
// AuthBody 鉴权中间件
// 若用户携带的token正确,解析token,将userId放入上下文context中并放行;否则,返回错误信息
func Auth_body() gin.HandlerFunc {
func AuthBody() gin.HandlerFunc {
return func(context *gin.Context) {
auth := context.Request.PostFormValue("token")
fmt.Printf("%v \n", auth)
Expand Down
5 changes: 2 additions & 3 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
func initRouter(r *gin.Engine) {
apiRouter := r.Group("/douyin")
// basic apis
apiRouter.GET("/feed/", middleware.Auth(), controller.Feed)
apiRouter.POST("/publish/action/", middleware.Auth_body(), controller.Publish)
apiRouter.GET("/feed/", middleware.AuthWithoutLogin(), controller.Feed)
apiRouter.POST("/publish/action/", middleware.AuthBody(), controller.Publish)
apiRouter.GET("/publish/list/", middleware.Auth(), controller.PublishList)
apiRouter.GET("/user/", middleware.Auth(), controller.UserInfo)
apiRouter.POST("/user/register/", controller.Register)
Expand All @@ -24,5 +24,4 @@ func initRouter(r *gin.Engine) {
apiRouter.POST("/relation/action/", middleware.Auth(), controller.RelationAction)
apiRouter.GET("/relation/follow/list/", middleware.Auth(), controller.GetFollowing)
apiRouter.GET("/relation/follower/list", middleware.Auth(), controller.GetFollowers)

}

0 comments on commit bc04132

Please sign in to comment.