feat: port verified messenger from lab 6

This commit is contained in:
Dmitrii Grishko
2026-11-14 19:16:28 +03:00
parent 20afc2c790
commit e3d7df4e72
142 changed files with 13702 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
package handlers
import (
"net/http"
"os"
"sync/atomic"
"github.com/google/uuid"
)
// Docker's hostname lets the operator map an API response to its container.
var instanceID = func() string {
id, err := os.Hostname()
if err != nil || id == "" {
return uuid.NewString()
}
return id
}()
var draining atomic.Bool
func BeginShutdown() { draining.Store(true) }
func withInstance(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Instance-Id", instanceID)
w.Header().Set("X-Request-Id", newRequestID())
if draining.Load() && r.URL.Path != "/health/live" {
writeError(w, 503, "unavailable", "instance is shutting down", w.Header().Get("X-Request-Id"))
return
}
next.ServeHTTP(w, r)
})
}