/
t3
/
token-server
Обзор
Документация
Войти
/
t3
/
token-server
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
main
internal/requestid/requestid.go
22 строки
834 B
Ivan Shibkikh
auth: phase 3
25 июл 2026, 22:52
25 июл 2026, 22:52
a53c429
Код
Авторство
О чём код?
// Package requestid provides a shared context key and helpers for X-Request-ID // propagation across STS. Use this package to consistently store and retrieve // the request/correlation ID from context. package requestid import "context" // ctxKey is an unexported empty struct — the value is irrelevant, only the // package-level type identity matters. This guarantees no collisions with // any other package's context key, regardless of the string value. type ctxKey struct{} // FromContext returns the request ID stored in ctx, or an empty string. func FromContext(ctx context.Context) string { v, _ := ctx.Value(ctxKey{}).(string) return v } // WithContext returns a child context with the given request ID. func WithContext(ctx context.Context, id string) context.Context { return context.WithValue(ctx, ctxKey{}, id) }