framework1/framework/middleware/cost.go

26 lines
547 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package middleware
import (
"github.com/Superdanda/hade/framework/gin"
"log"
"time"
)
// recovery机制将协程中的函数异常进行捕获
func Cost() gin.HandlerFunc {
// 使用函数回调
return func(c *gin.Context) {
// 记录开始时间
start := time.Now()
log.Printf("api uri start: %v", c.Request.RequestURI)
// 使用next执行具体的业务逻辑
c.Next()
// 记录结束时间
end := time.Now()
cost := end.Sub(start)
log.Printf("api uri end: %v, cost: %v", c.Request.RequestURI, cost.Seconds())
}
}