added enlapsed time to make the query on document.
This commit is contained in:
1 parent
14ce42475e
commit
abcff05635
3 files changed
+15
No files matched your search
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type errorWrapper struct {
|
||||
@@ -12,9 +13,17 @@ type errorWrapper struct {
|
||||
|
||||
type ApiHandler func(w http.ResponseWriter, request *http.Request) (interface{}, error)
|
||||
|
||||
func (this ApiHandler) addEnlapsedTimeIfPossible(enlapsedTime time.Duration, obj interface{}) {
|
||||
if dict, ok := obj.(map[string]interface{}); ok {
|
||||
dict["enlapsed_time"] = enlapsedTime.Seconds()
|
||||
}
|
||||
|
||||
}
|
||||
func (this ApiHandler) ServeHTTP(w http.ResponseWriter, request *http.Request) {
|
||||
log.Println("request for", request.URL)
|
||||
t := time.Now()
|
||||
ret, err := this(w, request)
|
||||
this.addEnlapsedTimeIfPossible(time.Since(t), ret)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
ret = &errorWrapper{err.Error()}
|
||||
|
||||
Reference in new issue
Block a user