router.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package api
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. )
  6. // RegRouters 注册路由
  7. func RegRouters(svc *Service) {
  8. crrouter := svc.NewGinRouter("/" + svc.Conf.Name)
  9. crrouter.group.Use(Logger())
  10. // 用户登录
  11. crrouter.POST("/user/login/password", UserLoginPassword)
  12. // 用户管理
  13. crrouter.POSTJWT("/admin/user/create", CreateUser)
  14. crrouter.POSTJWT("/admin/user/delete/:id", DeleteUser)
  15. crrouter.POSTJWT("/admin/user/delete/batch", BatchDeleteUser)
  16. crrouter.GETJWT("/admin/user/list", UserList)
  17. crrouter.GETJWT("/admin/user/detail/:id", UserDetail)
  18. crrouter.POSTJWT("/admin/user/update", UpdateUser)
  19. // 获取自己的详情信息
  20. crrouter.GETJWT("/user/profile", UserProfile)
  21. // 增加用户学习时长
  22. crrouter.GETJWT("/user/learn/inc", UserLearnInc)
  23. // 考核历史
  24. crrouter.POSTJWT("/exam/history/create", ExamHistoryCreate)
  25. crrouter.GETJWT("/exam/history/list", ExamHistoryList)
  26. Upload(crrouter)
  27. Version(crrouter)
  28. }
  29. func Logger() gin.HandlerFunc {
  30. return func(c *gin.Context) {
  31. // 开始时间
  32. // start := time.Now()
  33. // 处理请求
  34. c.Next()
  35. // 结束时间
  36. // end := time.Now()
  37. //执行时间
  38. // latency := end.Sub(start)
  39. path := c.Request.URL.Path
  40. clientIP := c.ClientIP()
  41. // method := c.Request.Method
  42. // statusCode := c.Writer.Status()
  43. out := fmt.Sprintf("%15s=> %s", clientIP, path)
  44. fmt.Println(out)
  45. }
  46. }