router.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. boxcost.GET("/printr", Printr)
  11. //数据存储
  12. boxcost.POST("/save/policy", ServiceObsUploadPolicy)
  13. // 材料管理
  14. Material(boxcost)
  15. // 工艺管理
  16. Craft(boxcost)
  17. // 工序管理
  18. Process(boxcost)
  19. // 供应商管理
  20. Supplier(boxcost)
  21. // 供应商价格管理
  22. SupplierPrice(boxcost)
  23. // 包装管理
  24. Pack(boxcost)
  25. // 生产计划管理
  26. ProductPlan(boxcost)
  27. // 单据管理
  28. Bill(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. }