router.go 748 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package api
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. )
  6. // RegRouters 注册路由
  7. func RegRouters(svc *Service) {
  8. train := svc.NewGinRouter("/" + svc.Conf.Name)
  9. train.group.Use(Logger())
  10. train.GET("/printr", Printr)
  11. // 用户管理
  12. User(train)
  13. // 题库管理
  14. Bank(train)
  15. // 试题管理
  16. Test(train)
  17. }
  18. func Logger() gin.HandlerFunc {
  19. return func(c *gin.Context) {
  20. // 开始时间
  21. // start := time.Now()
  22. // 处理请求
  23. c.Next()
  24. // 结束时间
  25. // end := time.Now()
  26. //执行时间
  27. // latency := end.Sub(start)
  28. path := c.Request.URL.Path
  29. clientIP := c.ClientIP()
  30. // method := c.Request.Method
  31. // statusCode := c.Writer.Status()
  32. out := fmt.Sprintf("%15s=> %s", clientIP, path)
  33. fmt.Println(out)
  34. }
  35. }