package api

import (
	"fmt"

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

// RegRouters 注册路由
func RegRouters(svc *Service) {
	// afina := svc.NewGinRouter("/" + svc.Conf.Name)
	root := svc.NewGinRouter("/")
	root.group.Use(Logger())

	Category(root)
	Article(root)
	Banner(root)
	Upload(root)
	// 临时展示接口
	Report(root)
	root.GET("/printr", Printr)
	root.GET("/sync", SyncType)
	// 同步上传文件地址
	root.GET("/syncStatic", SyncStaticAddr)

}

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