router.go 737 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. func Logger() gin.HandlerFunc {
  17. return func(c *gin.Context) {
  18. // 开始时间
  19. // start := time.Now()
  20. // 处理请求
  21. c.Next()
  22. // 结束时间
  23. // end := time.Now()
  24. //执行时间
  25. // latency := end.Sub(start)
  26. path := c.Request.URL.Path
  27. clientIP := c.ClientIP()
  28. // method := c.Request.Method
  29. // statusCode := c.Writer.Status()
  30. out := fmt.Sprintf("%15s=> %s", clientIP, path)
  31. fmt.Println(out)
  32. }
  33. }