latencyMiddleware sets the start time in the [echo.Context] under "startTime". Its value will be used later to calculate request latency. startTime := c.Get("startTime").(time.Time)
()
| 108 | // |
| 109 | // startTime := c.Get("startTime").(time.Time) |
| 110 | func latencyMiddleware() echo.MiddlewareFunc { |
| 111 | return func(next echo.HandlerFunc) echo.HandlerFunc { |
| 112 | return func(c echo.Context) error { |
| 113 | // First piece for calculating the latency. |
| 114 | startTime := time.Now() |
| 115 | c.Set("startTime", startTime) |
| 116 | |
| 117 | // Call the next middleware in the chain. |
| 118 | return next(c) |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | // rootPathMiddleware sets the root path in the [echo.Context] under |
| 124 | // "rootPath". Its value may be used to skip a middleware execution based on a |