package api

import (
	"fmt"

	"github.com/gin-gonic/gin"
)

// RegRouters 注册路由
func RegRouters(svc *Service) {

	_3dshow := svc.NewGinRouter("/" + svc.Conf.Name)
	_3dshow.group.Use(Logger())
	_3dshow.GET("/printr", Printr)

	// 供应链管理
	Supply(_3dshow)

	// 产品管理
	Product(_3dshow)

	// 地址管理
	Address(_3dshow)

	// 购物车
	ShopCart(_3dshow)

	// 订单管理
	Order(_3dshow)

	// 收藏
	Collect(_3dshow)

}

func Logger() gin.HandlerFunc {

	return func(c *gin.Context) {
		// 开始时间
		// start := time.Now()
		// 处理请求
		c.Next()
		// 结束时间
		// end := time.Now()
		//执行时间
		// latency := end.Sub(start)

		path := c.Request.URL.Path

		clientIP := c.ClientIP()
		// method := c.Request.Method
		// statusCode := c.Writer.Status()

		out := fmt.Sprintf("%15s=> %s", clientIP, path)
		fmt.Println(out)
	}
}