Open Gadrawingz opened 9 months ago
Perhaps you meant this?
startTime := time.Now()
...
endTime := time.Now()
package main
import (
"log"
"time"
)
func main() {
tStart := time.Now()
time.Sleep(123 * time.Millisecond)
execTime := time.Since(tStart)
log.Printf("executed in %s\n, ", execTime)
}
If you want it in gin Middleware
package main
import (
"log"
"time"
"github.com/gin-gonic/gin"
)
func main() {
g := gin.Default()
g.Use(roundTrip())
g.GET("/hello/:name", func(c *gin.Context) {
c.String(200, "Hello %s", c.Param("name"))
})
g.Run(":9000")
}
func roundTrip() gin.HandlerFunc {
return func(c *gin.Context) {
tsReq := time.Now()
c.Next()
execTime := time.Since(tsReq)
log.Printf("%s executed in %s\n, ", c.FullPath(), execTime)
}
}
Anyway, the default logger in Gin already print out the execution time.
I am starting to understand!
As of PHP framework like Codeigniter, Is that possible in Gin
How to reproduce
Expectations
Environment