forked from mtusi2026/mtusi2026lab6
15 lines
562 B
Go
15 lines
562 B
Go
package middleware
|
|
|
|
import "net/http"
|
|
|
|
// InstanceID добавляет X-Instance-Id ко всем ответам API, включая ошибки и health.
|
|
// Значение задаётся один раз при старте процесса и не меняется до его завершения.
|
|
func InstanceID(id string) func(http.Handler) http.Handler {
|
|
return func(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("X-Instance-Id", id)
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|
|
}
|