router.go 801 B

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