Skip to content

Commit

Permalink
增加 replayer 中间件
Browse files Browse the repository at this point in the history
  • Loading branch information
lvan100 committed Aug 16, 2021
1 parent f3c1350 commit 3d9fbde
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions replayer/middleware.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package replayer

import (
"context"
"net/http"
)

func AddHeader(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
const traceIDKey = "Sharingan-Replayer-TraceID"
if s := r.Header.Get(traceIDKey); s != "" {
r = r.WithContext(context.WithValue(r.Context(), traceIDKey, s))
}
next.ServeHTTP(w, r)
})
}

0 comments on commit 3d9fbde

Please sign in to comment.