20 lines
417 B
Go
20 lines
417 B
Go
package middleware
|
|
|
|
import (
|
|
"base-framework/pkg/router"
|
|
"time"
|
|
)
|
|
|
|
func Logger() router.HandlerFunc {
|
|
return func(c *router.Context) {
|
|
start := time.Now()
|
|
// 执行后续中间件和处理器
|
|
c.Next()
|
|
elapsed := time.Since(start)
|
|
// 即使业务中断,这里也能执行,打印耗时
|
|
path := c.Request.URL.Path
|
|
method := c.Request.Method
|
|
println(method, path, "耗时:", elapsed.String())
|
|
}
|
|
}
|