mirror of
https://github.com/openfaas/faas.git
synced 2025-06-21 22:33:23 +00:00
Add call-id via middleware
Signed-off-by: Alex Ellis <alexellis2@gmail.com>
This commit is contained in:
24
gateway/handlers/callid_middleware.go
Normal file
24
gateway/handlers/callid_middleware.go
Normal file
@ -0,0 +1,24 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/docker/distribution/uuid"
|
||||
)
|
||||
|
||||
// MakeCallIDMiddleware middleware tags a request with a uid
|
||||
func MakeCallIDMiddleware(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
start := time.Now()
|
||||
callID := uuid.Generate().String()
|
||||
r.Header.Add("X-Call-Id", callID)
|
||||
w.Header().Add("X-Call-Id", callID)
|
||||
|
||||
r.Header.Add("X-Start-Time", fmt.Sprintf("%d", start.UTC().UnixNano()))
|
||||
w.Header().Add("X-Start-Time", fmt.Sprintf("%d", start.UTC().UnixNano()))
|
||||
|
||||
next(w, r)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user