router.go 712 B

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