Files
SNCTF/routers/router.go
2022-07-01 02:08:07 +08:00

83 lines
2.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package routers
import (
"github.com/gin-gonic/gin"
"main.go/api"
"main.go/api/admin"
)
func Initrouter() {
router := gin.Default()
api_v1 := router.Group("/api/v1")
//公共接口(无需登录)
public := api_v1.Group("")
{
//用户登录
public.POST("/login", api.Login)
//用户注册
public.POST("/register", api.Register)
//用户登出
public.GET("/logout", api.Logout)
//获取指定id用户可公开信息
public.GET("/user/:id", api.GetInfoByUserId)
//获取指定id用户分数
public.GET("/score/:id", api.GetScoreByUserId)
//获取所有用户分数,降序排列
public.GET("/score", api.GetAllScore)
//获取全部公告
public.GET("/notice", api.GetAllNotices)
}
// 普通用户api需要用户登陆且Role=0才能访问
personal := api_v1.Group("/user")
personal.Use(api.AuthRequired())
{
// 获取当前用户信息
personal.GET("/session", api.Session)
// 获取题目分类
personal.GET("/category", api.GetCategories)
// 获取所有题目信息
personal.GET("/challenges/all", api.GetAllChallenges)
// 获取指定分类题目信息
personal.GET("/challenges/:category", api.GetChallengesByCategory)
// 提交flag
personal.POST("/submitflag", api.SubmitFlag)
// 获取所有正确的flag提交记录
personal.GET("/solves/all", api.GetAllSolves)
// 获取指定用户正确的flag提交记录
personal.GET("/solves/uid/:uid", api.GetSolvesByUid)
// 获取指定题目正确的flag提交记录
personal.GET("/solves/cid/:cid", api.GetSolvesByCid)
// 获取当前用户正确flag提交记录即解题记录按时间从早到晚排序
personal.GET("/solves/self", api.GetSelfSolves)
// 获取当前用户分数、排名
personal.GET("/score/self", api.GetSelfScoreAndRank)
// 获取所有用户信息
personal.GET("/users", api.GetAllUserInfo)
// 校内排行api暂时留空
}
// 管理员api需要用户登陆且Role=1才能访问
manager := api_v1.Group("/admin")
manager.Use(admin.AuthRequired())
{
// 创建新题目
manager.POST("/challenge", admin.NewChallenge)
// 删除题目 暂未测试
manager.DELETE("/challenge/:id", admin.DelChallenge)
// 更新题目信息 暂未测试
manager.PUT("/challenge/:id", admin.EditChallenge)
//创建新公告
manager.POST("/notice", api.AddNewNotices)
//删除公告 暂未测试
manager.DELETE("/notice/:id", api.DelNotice)
}
err := router.Run(":9000")
if err != nil {
return
}
}