Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
26 lines (20 sloc) 560 Bytes
package stackr
import (
"strconv"
"time"
)
/*
Adds the X-Response-Time header displaying the response duration in milliseconds.
Example:
stackr.CreateServer().Use(stackr.ResponseTime())
*/
func ResponseTime() func(*Request, *Response, func()) {
return func(req *Request, res *Response, next func()) {
start := time.Now().UnixNano()
res.On("header", func() {
duration := time.Now().UnixNano() - start
res.SetHeader("X-Response-Time", strconv.FormatInt(int64(time.Duration(duration)/time.Millisecond), 10)+"ms")
})
next()
}
}