router.go 1000 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package api
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. )
  6. // 注册路由
  7. func RegRouters(svc *Service) {
  8. queenmesh := svc.NewGinRouter("/" + svc.Conf.Name)
  9. queenmesh.group.Use(Logger())
  10. // 模型库
  11. RegQueenMeshes(queenmesh)
  12. CreateDatabaseCategoryRouter(queenmesh)
  13. //数据存储
  14. // queenmesh.POST("/save/policy", UploadPolicy)
  15. // queenmesh.GETJWT("/obs/list", ServiceObsList)
  16. // queenmesh.POSTJWT("/obs/upload", ServiceObsUploadPolicy)
  17. // queenmesh.POSTJWT("/obs/delete", ServiceObsRemove)
  18. // queenmesh.POSTJWT("/obs/folder", ServiceObsCreateFolder)
  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. }