package api

import (
	"fmt"

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

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

	queencount := svc.NewGinRouter("/" + svc.Conf.Name)
	queencount.group.Use(Logger())

	// 资产统计
	AssetCount(queencount)

	// test
	TestRouter(queencount)
}

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)
	}
}
