package api import ( "fmt" "github.com/gin-gonic/gin" ) // 注册路由 func RegRouters(svc *Service) { queenmesh := svc.NewGinRouter("/" + svc.Conf.Name) queenmesh.group.Use(Logger()) // 模型库 RegQueenMeshes(queenmesh) CreateDatabaseCategoryRouter(queenmesh) //数据存储 // queenmesh.POST("/save/policy", UploadPolicy) // queenmesh.GETJWT("/obs/list", ServiceObsList) // queenmesh.POSTJWT("/obs/upload", ServiceObsUploadPolicy) // queenmesh.POSTJWT("/obs/delete", ServiceObsRemove) // queenmesh.POSTJWT("/obs/folder", ServiceObsCreateFolder) } 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) } }