rest/status.go
func (mw *StatusMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc {

	mw.start = time.Now()
	mw.pid = os.Getpid()
	mw.responseCounts = map[string]int{}
	mw.totalResponseTime = time.Time{}

	return func(w ResponseWriter, r *Request) {

		// call the handler
		h(w, r)

		if r.Env["STATUS_CODE"] == nil {
			log.Fatal("StatusMiddleware: Env[\"STATUS_CODE\"] is nil, " +
				"RecorderMiddleware may not be in the wrapped Middlewares.")
		}
		statusCode := r.Env["STATUS_CODE"].(int)

		if r.Env["ELAPSED_TIME"] == nil {
			log.Fatal("StatusMiddleware: Env[\"ELAPSED_TIME\"] is nil, " +
				"TimerMiddleware may not be in the wrapped Middlewares.")
		}
		responseTime := r.Env["ELAPSED_TIME"].(*time.Duration)

		mw.lock.Lock()
		mw.responseCounts[fmt.Sprintf("%d", statusCode)]++
		mw.totalResponseTime = mw.totalResponseTime.Add(*responseTime)
		mw.lock.Unlock()
	}
}
func (mw *StatusMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc {

	mw.start = time.Now()
	mw.pid = os.Getpid()
	mw.responseCounts = map[string]int{}
	mw.totalResponseTime = time.Time{}

	return func(w ResponseWriter, r *Request) {

		// call the handler
		h(w, r)

		if r.Env["STATUS_CODE"] == nil {
			log.Fatal("StatusMiddleware: Env[\"STATUS_CODE\"] is nil, " +
				"RecorderMiddleware may not be in the wrapped Middlewares.")
		}
		statusCode := r.Env["STATUS_CODE"].(int)

		if r.Env["ELAPSED_TIME"] == nil {
			log.Fatal("StatusMiddleware: Env[\"ELAPSED_TIME\"] is nil, " +
				"TimerMiddleware may not be in the wrapped Middlewares.")
		}
		responseTime := r.Env["ELAPSED_TIME"].(*time.Duration)

		mw.lock.Lock()
		mw.responseCounts[fmt.Sprintf("%d", statusCode)]++
		mw.totalResponseTime = mw.totalResponseTime.Add(*responseTime)
		mw.lock.Unlock()
	}
}
// MiddlewareFunc makes StatusMiddleware implement the Middleware interface.