backend requirements onthe xustomer app

This commit is contained in:
2026-09-07 10:55:11 +05:30
parent 35675d8a9b
commit 1b2690b21a
56 changed files with 13342 additions and 1071 deletions

33
middlewares/requestid.go Normal file
View File

@@ -0,0 +1,33 @@
package middlewares
import (
"crypto/rand"
"encoding/hex"
"github.com/gofiber/fiber/v2"
)
// RequestID echoes the caller's X-Request-Id on every response, errors
// included, and mints one when the caller did not send it. The customer app
// funnels all failures into a single retryable error state, so a support
// conversation about "it failed" has nothing to correlate on unless the id the
// client already holds comes back on the failing response too.
//
// Also stashed in c.Locals("requestid") so handlers can log it alongside the
// real error they are hiding behind a customer-safe message.
func RequestID() fiber.Handler {
return func(c *fiber.Ctx) error {
id := c.Get("X-Request-Id")
if id == "" {
b := make([]byte, 8)
if _, err := rand.Read(b); err == nil {
id = hex.EncodeToString(b)
}
}
if id != "" {
c.Locals("requestid", id)
c.Set("X-Request-Id", id)
}
return c.Next()
}
}