You've already forked openaccounting-server
mirror of
https://github.com/openaccounting/oa-server.git
synced 2025-12-09 09:00:42 +13:00
initial commit
This commit is contained in:
26
vendor/github.com/ant0ine/go-json-rest/rest/timer.go
generated
vendored
Normal file
26
vendor/github.com/ant0ine/go-json-rest/rest/timer.go
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// TimerMiddleware computes the elapsed time spent during the execution of the wrapped handler.
|
||||
// The result is available to the wrapping handlers as request.Env["ELAPSED_TIME"].(*time.Duration),
|
||||
// and as request.Env["START_TIME"].(*time.Time)
|
||||
type TimerMiddleware struct{}
|
||||
|
||||
// MiddlewareFunc makes TimerMiddleware implement the Middleware interface.
|
||||
func (mw *TimerMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc {
|
||||
return func(w ResponseWriter, r *Request) {
|
||||
|
||||
start := time.Now()
|
||||
r.Env["START_TIME"] = &start
|
||||
|
||||
// call the handler
|
||||
h(w, r)
|
||||
|
||||
end := time.Now()
|
||||
elapsed := end.Sub(start)
|
||||
r.Env["ELAPSED_TIME"] = &elapsed
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user