123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package api
- import (
- "fmt"
- "github.com/gin-gonic/gin"
- )
- // RegRouters 注册路由
- func RegRouters(svc *Service) {
- crrouter := svc.NewGinRouter("/" + svc.Conf.Name)
- crrouter.group.Use(Logger())
- // 用户登录
- crrouter.POST("/user/login/password", UserLoginPassword)
- // 用户管理
- crrouter.POSTJWT("/admin/user/create", CreateUser)
- crrouter.POSTJWT("/admin/user/delete/:id", DeleteUser)
- crrouter.POSTJWT("/admin/user/delete/batch", BatchDeleteUser)
- crrouter.GETJWT("/admin/user/list", UserList)
- crrouter.GETJWT("/admin/user/detail/:id", UserDetail)
- crrouter.POSTJWT("/admin/user/update", UpdateUser)
- // 获取自己的详情信息
- crrouter.GETJWT("/user/profile", UserProfile)
- // 增加用户学习时长
- crrouter.GETJWT("/user/learn/inc", UserLearnInc)
- // 考核历史
- crrouter.POSTJWT("/exam/history/create", ExamHistoryCreate)
- crrouter.GETJWT("/exam/history/list", ExamHistoryList)
- Upload(crrouter)
- Version(crrouter)
- }
- func Logger() gin.HandlerFunc {
- return func(c *gin.Context) {
- // 开始时间
- // start := time.Now()
- // 处理请求
- c.Next()
- // 结束时间
- // end := time.Now()
- //执行时间
- // latency := end.Sub(start)
- path := c.Request.URL.Path
- clientIP := c.ClientIP()
- // method := c.Request.Method
- // statusCode := c.Writer.Status()
- out := fmt.Sprintf("%15s=> %s", clientIP, path)
- fmt.Println(out)
- }
- }
|