router.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package api
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. )
  6. // RegRouters 注册路由
  7. func RegRouters(svc *Service) {
  8. boxcost := svc.NewGinRouter("/" + svc.Conf.Name)
  9. boxcost.group.Use(Logger())
  10. //数据存储
  11. boxcost.POST("/save/policy", ServiceObsUploadPolicy)
  12. // 材料管理
  13. Material(boxcost)
  14. // 工艺管理
  15. Craft(boxcost)
  16. // 工序管理
  17. Process(boxcost)
  18. // 供应商管理
  19. Supplier(boxcost)
  20. // 供应商价格管理
  21. SupplierPrice(boxcost)
  22. // 包装管理
  23. Pack(boxcost)
  24. // 生产计划管理
  25. ProductPlan(boxcost)
  26. // 单据管理
  27. Bill(boxcost)
  28. BillProduce(boxcost)
  29. //设置
  30. Setting(boxcost)
  31. }
  32. func Logger() gin.HandlerFunc {
  33. return func(c *gin.Context) {
  34. // 开始时间
  35. // start := time.Now()
  36. // 处理请求
  37. c.Next()
  38. // 结束时间
  39. // end := time.Now()
  40. //执行时间
  41. // latency := end.Sub(start)
  42. path := c.Request.URL.Path
  43. clientIP := c.ClientIP()
  44. // method := c.Request.Method
  45. // statusCode := c.Writer.Status()
  46. out := fmt.Sprintf("%15s=> %s", clientIP, path)
  47. fmt.Println(out)
  48. }
  49. }