package pkg import ( "context" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/utils" "google.golang.org/grpc/metadata" "time" ) func TransFiberCtx2NewOutgoingContext(fCtx *fiber.Ctx, time time.Duration) (context.Context, context.CancelFunc) { ctx := fCtx.UserContext() md := metadata.MD{} if value, ok := ctx.Value(fiber.HeaderXRequestID).(string); ok { md = metadata.Pairs(fiber.HeaderXRequestID, value) } else { md = metadata.Pairs(fiber.HeaderXRequestID, utils.UUIDv4()) } //3s 过期超时 return context.WithTimeout(metadata.NewOutgoingContext(ctx, md), time) }